Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
solver_heap.h
1/* Copyright (c) 2020 tevador <tevador@gmail.com> */
2/* See LICENSE for licensing information */
3
4#ifndef SOLVER_HEAP_H
5#define SOLVER_HEAP_H
6
7#include <stdint.h>
8#include <equix.h>
9
10#define INDEX_SPACE (UINT32_C(1) << 16)
11#define NUM_COARSE_BUCKETS 256
12#define NUM_FINE_BUCKETS 128
13#define COARSE_BUCKET_ITEMS 336
14#define FINE_BUCKET_ITEMS 12
15
16typedef uint16_t fine_item;
17
18typedef struct fine_bucket {
19 fine_item items[FINE_BUCKET_ITEMS];
21
22typedef struct fine_hashtab {
23 uint8_t counts[NUM_FINE_BUCKETS];
24 fine_bucket buckets[NUM_FINE_BUCKETS];
26
27typedef equix_idx stage1_idx_item; /* 16 bits */
28
29typedef uint64_t stage1_data_item; /* 52 bits */
30
31typedef struct stage1_idx_bucket {
32 stage1_idx_item items[COARSE_BUCKET_ITEMS];
34
35typedef struct stage1_data_bucket {
36 stage1_data_item items[COARSE_BUCKET_ITEMS];
38
39typedef struct stage1_idx_hashtab {
40 uint16_t counts[NUM_COARSE_BUCKETS];
41 stage1_idx_bucket buckets[NUM_COARSE_BUCKETS];
43
44typedef struct stage1_data_hashtab {
45 stage1_data_bucket buckets[NUM_COARSE_BUCKETS];
47
48typedef uint32_t stage2_idx_item; /* 26 bits: 8 bits = left bucket index
49 9 bits = left item index
50 9 bits = right item index */
51
52typedef struct stage2_idx_bucket {
53 stage2_idx_item items[COARSE_BUCKET_ITEMS];
55
56typedef struct stage2_idx_hashtab {
57 uint16_t counts[NUM_COARSE_BUCKETS];
58 stage2_idx_bucket buckets[NUM_COARSE_BUCKETS];
60
61#ifdef SOLVER_PACKED_STAGE2
62#pragma pack(push, 1)
63typedef struct stage2_data_item {
64 uint32_t upper; /* 22 bits */
65 uint8_t middle; /* 8 bits */
66 uint8_t lower; /* 7 bits */
67} stage2_data_item;
68#pragma pack(pop)
69#else
70typedef uint64_t stage2_data_item; /* 37 bits */
71#endif
72
73typedef struct stage2_data_bucket {
74 stage2_data_item items[COARSE_BUCKET_ITEMS];
76
77typedef struct stage2_data_hashtab {
78 stage2_data_bucket buckets[NUM_COARSE_BUCKETS];
80
81typedef uint32_t stage3_data_item; /* 22 bits */
82
83typedef struct stage3_data_bucket {
84 stage3_data_item items[COARSE_BUCKET_ITEMS];
86
87typedef struct stage3_data_hashtab {
88 stage3_data_bucket buckets[NUM_COARSE_BUCKETS];
90
92typedef stage2_idx_item stage3_idx_item;
93
94typedef struct solver_heap {
95 stage1_idx_hashtab stage1_indices; /* 172 544 bytes */
96 stage2_idx_hashtab stage2_indices; /* 344 576 bytes */
97 stage2_data_hashtab stage2_data; /* 688 128 bytes */
98 union {
99 stage1_data_hashtab stage1_data; /* 688 128 bytes */
100 struct {
101 stage3_idx_hashtab stage3_indices; /* 344 576 bytes */
102 stage3_data_hashtab stage3_data; /* 344 064 bytes */
103 };
104 };
105 fine_hashtab scratch_ht; /* 3 200 bytes */
106} solver_heap; /* TOTAL: 1 897 088 bytes */
107
108#endif