checkdata.h (3509B)
1 STATIC long long checkdata_h48( 2 const char *, unsigned long long, const unsigned char *); 3 4 uint64_t expected_cocsep[21] = { 5 [0] = 1, 6 [1] = 6, 7 [2] = 63, 8 [3] = 468, 9 [4] = 3068, 10 [5] = 15438, 11 [6] = 53814, 12 [7] = 71352, 13 [8] = 8784, 14 [9] = 96 15 }; 16 17 struct { 18 uint8_t max; 19 uint64_t table[21]; 20 } expected_h48[12] = { 21 [0] = { 22 .max = 3, 23 .table = { 24 [0] = 5473562, 25 [1] = 34776317, 26 [2] = 68566704, 27 [3] = 8750867, 28 }, 29 }, 30 [1] = { 31 .max = 3, 32 .table = { 33 [0] = 6012079, 34 [1] = 45822302, 35 [2] = 142018732, 36 [3] = 41281787, 37 }, 38 }, 39 [2] = { 40 .max = 3, 41 .table = { 42 [0] = 6391286, 43 [1] = 55494785, 44 [2] = 252389935, 45 [3] = 155993794, 46 }, 47 }, 48 [3] = { 49 .max = 3, 50 .table = { 51 [0] = 6686828, 52 [1] = 63867852, 53 [2] = 392789689, 54 [3] = 477195231, 55 }, 56 }, 57 [4] = { 58 .max = 3, 59 .table = { 60 [0] = 77147213, 61 [1] = 543379415, 62 [2] = 1139570251, 63 [3] = 120982321, 64 }, 65 }, 66 [5] = { 67 .max = 3, 68 .table = { 69 [0] = 82471284, 70 [1] = 687850732, 71 [2] = 2345840746, 72 [3] = 645995638, 73 }, 74 }, 75 [6] = { 76 .max = 3, 77 .table = { 78 [0] = 85941099, 79 [1] = 804752968, 80 [2] = 4077248182, 81 [3] = 2556374551, 82 }, 83 }, 84 [7] = { 85 .max = 3, 86 .table = { 87 [0] = 88529761, 88 [1] = 897323475, 89 [2] = 6126260791, 90 [3] = 7936519573, 91 }, 92 }, 93 [8] = { 94 .max = 3, 95 .table = { 96 [0] = 1051579940, 97 [1] = 8136021316, 98 [2] = 19024479822, 99 [3] = 1885186122, 100 }, 101 }, 102 [9] = { 103 .max = 3, 104 .table = { 105 [0] = 1102038189, 106 [1] = 9888265242, 107 [2] = 38299375805, 108 [3] = 10904855164, 109 }, 110 }, 111 [10] = { 112 .max = 3, 113 .table = { 114 [0] = 1133240039, 115 [1] = 11196285614, 116 [2] = 64164702961, 117 [3] = 43894840186, 118 }, 119 }, 120 [11] = { 121 .max = 3, 122 .table = { 123 [0] = 1150763161, 124 [1] = 12045845660, 125 [2] = 91163433330, 126 [3] = 136418095449, 127 }, 128 }, 129 }; 130 131 /* 132 TODO: add check for cocsep table. 133 134 TODO: add check for fallback values at the end of each line. 135 136 TODO: this function can be simplified, now we support only one h48 table + 137 eoesep. The loop can be just two checks. 138 */ 139 STATIC long long 140 checkdata_h48( 141 const char *solver, 142 unsigned long long data_size, 143 const unsigned char *data 144 ) 145 { 146 const unsigned char *table; 147 tableinfo_t info; 148 int64_t err; 149 uint64_t actual_distribution[INFO_DISTRIBUTION_LEN]; 150 uint8_t em; 151 uint64_t *ed; 152 153 if ((size_t)data % 8 != 0) { 154 LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); 155 return NISSY_ERROR_DATA; 156 } 157 158 do { 159 err = readtableinfo(data_size, data, &info); 160 if (err != NISSY_OK) { 161 LOG("[checkdata] Data is corrupt\n"); 162 return NISSY_ERROR_DATA; 163 } 164 165 table = data + INFOSIZE; 166 data += info.next; 167 data_size -= info.next; 168 169 if (info.type != TABLETYPE_PRUNING) { 170 LOG("[checkdata] Skipping '%s'\n", info.solver); 171 continue; 172 } 173 174 ed = expected_h48[info.h48h].table; 175 em = expected_h48[info.h48h].max; 176 177 LOG("[checkdata] Checking distribution for '%s' from " 178 "table preamble\n", info.solver); 179 if (!distribution_equal(ed, info.distribution, em)) { 180 LOG("[checkdata] Distribution from the table preamble " 181 "does not match the expected one\n"); 182 return NISSY_ERROR_DATA; 183 } 184 185 LOG("[checkdata] Checking distribution for '%s' from " 186 "actual table\n", info.solver); 187 getdistribution_h48(table, actual_distribution, &info); 188 if (!distribution_equal(ed, actual_distribution, em)) { 189 LOG("[checkdata] Distribution from the actual table " 190 "does not match the expected one\n"); 191 return NISSY_ERROR_DATA; 192 } 193 } while (info.next != 0); 194 195 return NISSY_OK; 196 }