aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-19 23:07:18 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-19 23:07:18 +0200
commit37899ca61e17543c4bd5131ef76f655684d1faa7 (patch)
tree05ea000ff70ecff50b59312e7412432ccc00807d /src/solvers/h48
parenta1acf445ff4b5cc506622b7c5f89c63e53307fe9 (diff)
parent24f24e01380bd1fd0afeac284686512fa98f1e3b (diff)
downloadnissy-core-37899ca61e17543c4bd5131ef76f655684d1faa7.tar.gz
nissy-core-37899ca61e17543c4bd5131ef76f655684d1faa7.zip
Merge branch 'master' of github.com:sebastianotronto/h48
Diffstat (limited to 'src/solvers/h48')
-rw-r--r--src/solvers/h48/gendata_h48.h338
1 files changed, 232 insertions, 106 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 62dab8c..0a6f130 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -33,6 +33,7 @@ _t by _ttrep).
33typedef struct { 33typedef struct {
34 uint8_t h; 34 uint8_t h;
35 uint8_t k; 35 uint8_t k;
36 uint8_t base;
36 uint8_t maxdepth; 37 uint8_t maxdepth;
37 tableinfo_t info; 38 tableinfo_t info;
38 void *buf; 39 void *buf;
@@ -56,6 +57,12 @@ typedef struct {
56 uint8_t *table; 57 uint8_t *table;
57 uint64_t *selfsim; 58 uint64_t *selfsim;
58 cube_t *crep; 59 cube_t *crep;
60 uint64_t start;
61 uint64_t end;
62 uint64_t count;
63 uint64_t *distribution;
64 pthread_mutex_t *distribution_mutex;
65 pthread_mutex_t *table_mutex[CHUNKS];
59} h48h0k4_bfs_arg_t; 66} h48h0k4_bfs_arg_t;
60 67
61typedef struct { 68typedef struct {
@@ -75,17 +82,30 @@ typedef struct {
75 uint64_t *count; 82 uint64_t *count;
76} h48k2_dfs_arg_t; 83} h48k2_dfs_arg_t;
77 84
85typedef struct {
86 cube_t cube;
87 int8_t depth;
88 uint8_t h;
89 uint8_t k;
90 uint32_t *cocsepdata;
91 uint64_t *selfsim;
92 uint8_t *table;
93 pthread_mutex_t **table_mutex;
94} gendata_h48_mark_t;
95
78STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); 96STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *);
79STATIC size_t gendata_h48(gendata_h48_arg_t *); 97STATIC size_t gendata_h48(gendata_h48_arg_t *);
80STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); 98STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *);
81STATIC int64_t gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *); 99STATIC void gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *);
82STATIC int64_t gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *); 100STATIC void gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *);
83STATIC int64_t gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *);
84STATIC size_t gendata_h48k2(gendata_h48_arg_t *); 101STATIC size_t gendata_h48k2(gendata_h48_arg_t *);
85STATIC void * gendata_h48k2_runthread(void *); 102STATIC void * gendata_h48h0k4_runthread(void *);
86STATIC_INLINE void gendata_h48k2_mark(cube_t, int8_t, h48k2_dfs_arg_t *); 103STATIC_INLINE uint64_t gendata_h48_mark(gendata_h48_mark_t *);
87STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); 104STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *);
105STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *);
88STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); 106STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg);
107STATIC void * gendata_h48k2_runthread(void *);
108STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t);
89 109
90STATIC uint32_t *get_cocsepdata_ptr(const void *); 110STATIC uint32_t *get_cocsepdata_ptr(const void *);
91STATIC uint8_t *get_h48data_ptr(const void *); 111STATIC uint8_t *get_h48data_ptr(const void *);
@@ -147,8 +167,12 @@ gendata_h48(gendata_h48_arg_t *arg)
147 arg->cocsepdata = (uint32_t *)cocsepdata_offset; 167 arg->cocsepdata = (uint32_t *)cocsepdata_offset;
148 arg->h48buf = (char *)arg->buf + cocsepsize; 168 arg->h48buf = (char *)arg->buf + cocsepsize;
149 169
170 arg->base = 99; // TODO: set this somewhere else
171
150 if (arg->h == 0 && arg->k == 4) { 172 if (arg->h == 0 && arg->k == 4) {
151 h48size = gendata_h48h0k4(arg); 173 h48size = gendata_h48h0k4(arg);
174 } else if ((arg->h == 0 || arg->h == 11) && arg->k == 2) {
175 h48size = gendata_h48k2_realcoord(arg);
152 } else if (arg->k == 2) { 176 } else if (arg->k == 2) {
153 h48size = gendata_h48k2(arg); 177 h48size = gendata_h48k2(arg);
154 } else { 178 } else {
@@ -179,17 +203,15 @@ gendata_h48_error:
179 return 0; 203 return 0;
180} 204}
181 205
182/*
183TODO description
184generating fixed table with h=0, k=4
185*/
186STATIC size_t 206STATIC size_t
187gendata_h48h0k4(gendata_h48_arg_t *arg) 207gendata_h48h0k4(gendata_h48_arg_t *arg)
188{ 208{
189 uint32_t j;
190 uint8_t *table; 209 uint8_t *table;
191 h48h0k4_bfs_arg_t bfsarg; 210 int64_t sc, done, d, h48max;
192 int64_t sc, cc, done, h48max; 211 uint64_t t, tt, isize, cc;
212 h48h0k4_bfs_arg_t bfsarg[THREADS];
213 pthread_t thread[THREADS];
214 pthread_mutex_t distribution_mutex, table_mutex[CHUNKS];
193 215
194 if (arg->buf == NULL) 216 if (arg->buf == NULL)
195 goto gendata_h48h0k4_return_size; 217 goto gendata_h48h0k4_return_size;
@@ -216,109 +238,164 @@ gendata_h48h0k4(gendata_h48_arg_t *arg)
216 sc = coord_h48(SOLVED_CUBE, arg->cocsepdata, 0); 238 sc = coord_h48(SOLVED_CUBE, arg->cocsepdata, 0);
217 set_h48_pval(table, sc, 4, 0); 239 set_h48_pval(table, sc, 4, 0);
218 arg->info.distribution[0] = 1; 240 arg->info.distribution[0] = 1;
219 bfsarg = (h48h0k4_bfs_arg_t) { 241
220 .cocsepdata = arg->cocsepdata, 242 isize = h48max / THREADS;
221 .table = table, 243 isize = (isize / H48_COEFF(arg->k)) * H48_COEFF(arg->k);
222 .selfsim = arg->selfsim, 244 pthread_mutex_init(&distribution_mutex, NULL);
223 .crep = arg->crep 245 for (t = 0; t < CHUNKS; t++)
224 }; 246 pthread_mutex_init(&table_mutex[t], NULL);
225 for ( 247 for (t = 0; t < THREADS; t++) {
226 done = 1, bfsarg.depth = 1, cc = 0; 248 bfsarg[t] = (h48h0k4_bfs_arg_t) {
227 done < h48max && bfsarg.depth <= arg->maxdepth; 249 .cocsepdata = arg->cocsepdata,
228 bfsarg.depth++ 250 .table = table,
229 ) { 251 .selfsim = arg->selfsim,
230 LOG("h48: generating depth %" PRIu8 "\n", bfsarg.depth); 252 .crep = arg->crep,
231 cc = gendata_h48h0k4_bfs(&bfsarg); 253 .start = isize * t,
232 done += cc; 254 .end = t == THREADS-1 ? (uint64_t)h48max : isize * (t+1),
233 arg->info.distribution[bfsarg.depth] = cc; 255 .distribution = arg->info.distribution,
234 LOG("found %" PRId64 "\n", cc); 256 .distribution_mutex = &distribution_mutex,
257 };
258 for (tt = 0; tt < CHUNKS; tt++)
259 bfsarg[t].table_mutex[tt] = &table_mutex[tt];
235 } 260 }
261 for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) {
262 LOG("h48: generating depth %" PRIu8 "\n", d);
263
264 for (t = 0; t < THREADS; t++) {
265 bfsarg[t].depth = d;
266 bfsarg[t].count = 0;
267 pthread_create(&thread[t], NULL,
268 gendata_h48h0k4_runthread, &bfsarg[t]);
269 }
270
271 for (t = 0, cc = 0; t < THREADS; t++) {
272 pthread_join(thread[t], NULL);
273 cc += bfsarg[t].count;
274 }
236 275
237 arg->info.maxvalue = bfsarg.depth-1; 276 done += cc;
277 arg->info.distribution[d] = cc;
238 278
239 LOG("h48 pruning table computed\n"); 279 LOG("found %" PRId64 "\n", cc);
240 LOG("Maximum pruning value: %" PRIu32 "\n", arg->info.maxvalue); 280 }
241 LOG("Pruning value distribution:\n");
242 for (j = 0; j <= arg->info.maxvalue; j++)
243 LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, arg->info.distribution[j]);
244 281
282 arg->info.maxvalue = d - 1;
245 writetableinfo(&arg->info, arg->h48buf); 283 writetableinfo(&arg->info, arg->h48buf);
246 284
247gendata_h48h0k4_return_size: 285gendata_h48h0k4_return_size:
248 return H48_TABLESIZE(0, 4) + INFOSIZE; 286 return H48_TABLESIZE(0, 4) + INFOSIZE;
249} 287}
250 288
251STATIC int64_t 289STATIC void *
252gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *arg) 290gendata_h48h0k4_runthread(void *arg)
253{ 291{
254 const uint8_t breakpoint = 10; /* Hand-picked optimal */ 292 static const uint8_t breakpoint = 10; /* Hand-picked optimal */
293
294 h48h0k4_bfs_arg_t *bfsarg;
255 295
256 if (arg->depth < breakpoint) 296 bfsarg = (h48h0k4_bfs_arg_t *)arg;
257 return gendata_h48h0k4_bfs_fromdone(arg); 297
298 if (bfsarg->depth < breakpoint)
299 gendata_h48h0k4_bfs_fromdone(bfsarg);
258 else 300 else
259 return gendata_h48h0k4_bfs_fromnew(arg); 301 gendata_h48h0k4_bfs_fromnew(bfsarg);
302
303 return NULL;
260} 304}
261 305
262STATIC int64_t 306STATIC void
263gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg) 307gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg)
264{ 308{
265 uint8_t c, m, x; 309 uint8_t c, m;
266 uint32_t cc; 310 uint64_t i, d, mutex;
267 int64_t i, j, k; 311 int64_t j;
268 cube_t cube, moved; 312 cube_t cube, moved;
313 gendata_h48_mark_t markarg;
314
315 markarg = (gendata_h48_mark_t) {
316 .depth = arg->depth,
317 .h = 0,
318 .k = 4,
319 .cocsepdata = arg->cocsepdata,
320 .selfsim = arg->selfsim,
321 .table = arg->table,
322 .table_mutex = arg->table_mutex,
323 };
269 324
270 for (i = 0, cc = 0; i < (int64_t)H48_COORDMAX(0); i++) { 325 for (i = arg->start, d = 0; i < arg->end; i++) {
326 mutex = H48_INDEX(i, 4) % CHUNKS;
327 pthread_mutex_lock(arg->table_mutex[mutex]);
271 c = get_h48_pval(arg->table, i, 4); 328 c = get_h48_pval(arg->table, i, 4);
329 pthread_mutex_unlock(arg->table_mutex[mutex]);
272 if (c != arg->depth - 1) 330 if (c != arg->depth - 1)
273 continue; 331 continue;
274 cube = invcoord_h48(i, arg->crep, 0); 332 cube = invcoord_h48(i, arg->crep, 0);
275 for (m = 0; m < 18; m++) { 333 for (m = 0; m < 18; m++) {
276 moved = move(cube, m); 334 moved = move(cube, m);
277 j = coord_h48(moved, arg->cocsepdata, 0); 335 j = coord_h48(moved, arg->cocsepdata, 0);
278 if (get_h48_pval(arg->table, j, 4) <= arg->depth) 336 mutex = H48_INDEX(j, 4) % CHUNKS;
337 pthread_mutex_lock(arg->table_mutex[mutex]);
338 c = get_h48_pval(arg->table, j, 4);
339 pthread_mutex_unlock(arg->table_mutex[mutex]);
340 if (c <= arg->depth)
279 continue; 341 continue;
280 FOREACH_H48SIM(moved, arg->cocsepdata, arg->selfsim, 342 markarg.cube = moved;
281 k = coord_h48(moved, arg->cocsepdata, 0); 343 d += gendata_h48_mark(&markarg);
282 x = get_h48_pval(arg->table, k, 4);
283 set_h48_pval(arg->table, k, 4, arg->depth);
284 cc += x != arg->depth;
285 )
286 } 344 }
287 } 345 }
288 346
289 return cc; 347 pthread_mutex_lock(arg->distribution_mutex);
348 arg->count += d;
349 arg->distribution[arg->depth] += d;
350 pthread_mutex_unlock(arg->distribution_mutex);
290} 351}
291 352
292STATIC int64_t 353STATIC void
293gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg) 354gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg)
294{ 355{
295 uint8_t c, m, x; 356 uint8_t c, m, x;
296 uint32_t cc; 357 uint64_t i, d, mutex;
297 int64_t i, j; 358 int64_t j;
298 cube_t cube, moved; 359 cube_t cube, moved;
360 gendata_h48_mark_t markarg;
361
362 markarg = (gendata_h48_mark_t) {
363 .depth = arg->depth,
364 .h = 0,
365 .k = 4,
366 .cocsepdata = arg->cocsepdata,
367 .selfsim = arg->selfsim,
368 .table = arg->table,
369 .table_mutex = arg->table_mutex,
370 };
299 371
300 for (i = 0, cc = 0; i < (int64_t)H48_COORDMAX(0); i++) { 372 for (i = arg->start, d = 0; i < arg->end; i++) {
373 mutex = H48_INDEX(i, 4) % CHUNKS;
374 pthread_mutex_lock(arg->table_mutex[mutex]);
301 c = get_h48_pval(arg->table, i, 4); 375 c = get_h48_pval(arg->table, i, 4);
376 pthread_mutex_unlock(arg->table_mutex[mutex]);
302 if (c != 0xF) 377 if (c != 0xF)
303 continue; 378 continue;
304 cube = invcoord_h48(i, arg->crep, 0); 379 cube = invcoord_h48(i, arg->crep, 0);
305 for (m = 0; m < 18; m++) { 380 for (m = 0; m < 18; m++) {
306 moved = move(cube, m); 381 moved = move(cube, m);
307 j = coord_h48(moved, arg->cocsepdata, 0); 382 j = coord_h48(moved, arg->cocsepdata, 0);
383 mutex = H48_INDEX(j, 4) % CHUNKS;
384 pthread_mutex_lock(arg->table_mutex[mutex]);
308 x = get_h48_pval(arg->table, j, 4); 385 x = get_h48_pval(arg->table, j, 4);
386 pthread_mutex_unlock(arg->table_mutex[mutex]);
309 if (x >= arg->depth) 387 if (x >= arg->depth)
310 continue; 388 continue;
311 FOREACH_H48SIM(cube, arg->cocsepdata, arg->selfsim, 389 markarg.cube = cube;
312 j = coord_h48(cube, arg->cocsepdata, 0); 390 d += gendata_h48_mark(&markarg);
313 x = get_h48_pval(arg->table, j, 4);
314 set_h48_pval(arg->table, j, 4, arg->depth);
315 cc += x == 0xF;
316 )
317 break; /* Enough to find one, skip the rest */ 391 break; /* Enough to find one, skip the rest */
318 } 392 }
319 } 393 }
320 394
321 return cc; 395 pthread_mutex_lock(arg->distribution_mutex);
396 arg->count += d;
397 arg->distribution[arg->depth] += d;
398 pthread_mutex_unlock(arg->distribution_mutex);
322} 399}
323 400
324STATIC size_t 401STATIC size_t
@@ -369,24 +446,8 @@ gendata_h48k2(gendata_h48_arg_t *arg)
369 }; 446 };
370 gendata_h48short(&shortarg); 447 gendata_h48short(&shortarg);
371 448
372 selectedbase = base[arg->h]; 449 selectedbase = arg->base < 20 ? arg->base : base[arg->h];
373 arg->info = (tableinfo_t) { 450 arg->info = makeinfo_h48k2(arg, selectedbase);
374 .solver = "h48 solver h = , k = 2",
375 .type = TABLETYPE_PRUNING,
376 .infosize = INFOSIZE,
377 .fullsize = H48_TABLESIZE(arg->h, 2) + INFOSIZE,
378 .hash = 0, /* TODO */
379 .entries = H48_COORDMAX(arg->h),
380 .classes = 0,
381 .h48h = arg->h,
382 .bits = 2,
383 .base = selectedbase,
384 .maxvalue = 3,
385 .next = 0,
386 };
387 arg->info.solver[15] = (arg->h % 10) + '0';
388 if (arg->h >= 10)
389 arg->info.solver[14] = (arg->h / 10) + '0';
390 451
391 inext = count = 0; 452 inext = count = 0;
392 pthread_mutex_init(&shortcubes_mutex, NULL); 453 pthread_mutex_init(&shortcubes_mutex, NULL);
@@ -419,6 +480,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
419 480
420 h48map_destroy(&shortcubes); 481 h48map_destroy(&shortcubes);
421 482
483 /* TODO: inline into mark */
422 for (j = 0; j < H48_COORDMAX(arg->h); j++) { 484 for (j = 0; j < H48_COORDMAX(arg->h); j++) {
423 t = get_h48_pval(table, j, 2); 485 t = get_h48_pval(table, j, 2);
424 arg->info.distribution[t]++; 486 arg->info.distribution[t]++;
@@ -474,21 +536,36 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg)
474 int8_t d; 536 int8_t d;
475 uint8_t m[4]; 537 uint8_t m[4];
476 cube_t cube[4]; 538 cube_t cube[4];
539 gendata_h48_mark_t markarg;
540
541 markarg = (gendata_h48_mark_t) {
542 .h = arg->h,
543 .k = arg->k,
544 .cocsepdata = arg->cocsepdata,
545 .selfsim = arg->selfsim,
546 .table = arg->table,
547 .table_mutex = arg->table_mutex,
548 };
477 549
478 d = (int8_t)arg->shortdepth - (int8_t)arg->base; 550 d = (int8_t)arg->shortdepth - (int8_t)arg->base;
479 551
480 /* Depth d+0 (shortcubes) */ 552 /* Depth d+0 (shortcubes) */
481 gendata_h48k2_mark(arg->cube, d, arg); 553 markarg.depth = d;
554 markarg.cube = arg->cube;
555 gendata_h48_mark(&markarg);
482 556
483 /* Depth d+1 */ 557 /* Depth d+1 */
484 for (m[0] = 0; m[0] < 18; m[0]++) { 558 for (m[0] = 0; m[0] < 18; m[0]++) {
559 markarg.depth = d+1;
485 cube[0] = move(arg->cube, m[0]); 560 cube[0] = move(arg->cube, m[0]);
486 if (gendata_h48k2_dfs_stop(cube[0], d+1, arg)) 561 if (gendata_h48k2_dfs_stop(cube[0], d+1, arg))
487 continue; 562 continue;
488 gendata_h48k2_mark(cube[0], d+1, arg); 563 markarg.cube = cube[0];
564 gendata_h48_mark(&markarg);
489 565
490 /* Depth d+2 */ 566 /* Depth d+2 */
491 for (m[1] = 0; m[1] < 18; m[1]++) { 567 for (m[1] = 0; m[1] < 18; m[1]++) {
568 markarg.depth = d+2;
492 if (m[0] / 3 == m[1] / 3) { 569 if (m[0] / 3 == m[1] / 3) {
493 m[1] += 2; 570 m[1] += 2;
494 continue; 571 continue;
@@ -496,12 +573,14 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg)
496 cube[1] = move(cube[0], m[1]); 573 cube[1] = move(cube[0], m[1]);
497 if (gendata_h48k2_dfs_stop(cube[1], d+2, arg)) 574 if (gendata_h48k2_dfs_stop(cube[1], d+2, arg))
498 continue; 575 continue;
499 gendata_h48k2_mark(cube[1], d+2, arg); 576 markarg.cube = cube[1];
577 gendata_h48_mark(&markarg);
500 if (d >= 0) 578 if (d >= 0)
501 continue; 579 continue;
502 580
503 /* Depth d+3 */ 581 /* Depth d+3 */
504 for (m[2] = 0; m[2] < 18; m[2]++) { 582 for (m[2] = 0; m[2] < 18; m[2]++) {
583 markarg.depth = d+3;
505 if (!allowednextmove(m, 3)) { 584 if (!allowednextmove(m, 3)) {
506 m[2] += 2; 585 m[2] += 2;
507 continue; 586 continue;
@@ -509,40 +588,47 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg)
509 cube[2] = move(cube[1], m[2]); 588 cube[2] = move(cube[1], m[2]);
510 if (gendata_h48k2_dfs_stop(cube[2], d+3, arg)) 589 if (gendata_h48k2_dfs_stop(cube[2], d+3, arg))
511 continue; 590 continue;
512 gendata_h48k2_mark(cube[2], d+3, arg); 591 markarg.cube = cube[2];
592 gendata_h48_mark(&markarg);
513 if (d >= -1) 593 if (d >= -1)
514 continue; 594 continue;
515 595
516 /* Depth d+4 */ 596 /* Depth d+4 */
517 for (m[3] = 0; m[3] < 18; m[3]++) { 597 for (m[3] = 0; m[3] < 18; m[3]++) {
598 markarg.depth = d+4;
518 if (!allowednextmove(m, 4)) { 599 if (!allowednextmove(m, 4)) {
519 m[3] += 2; 600 m[3] += 2;
520 continue; 601 continue;
521 } 602 }
522 cube[3] = move(cube[2], m[3]); 603 cube[3] = move(cube[2], m[3]);
523 gendata_h48k2_mark(cube[3], d+4, arg); 604 markarg.cube = cube[3];
605 gendata_h48_mark(&markarg);
524 } 606 }
525 } 607 }
526 } 608 }
527 } 609 }
528} 610}
529 611
530STATIC_INLINE void 612STATIC_INLINE uint64_t
531gendata_h48k2_mark(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) 613gendata_h48_mark(gendata_h48_mark_t *arg)
532{ 614{
533 uint8_t oldval, newval; 615 uint8_t oldval, newval;
534 int64_t coord, fullcoord, mutex; 616 uint64_t d;
617 int64_t coord, mutex;
535 618
536 FOREACH_H48SIM(cube, arg->cocsepdata, arg->selfsim, 619 d = 0;
537 fullcoord = coord_h48(cube, arg->cocsepdata, 11); 620 FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim,
538 coord = fullcoord >> (int64_t)(11 - arg->h); 621 coord = coord_h48(arg->cube, arg->cocsepdata, arg->h);
539 mutex = H48_INDEX(coord, arg->k) % CHUNKS; 622 mutex = H48_INDEX(coord, arg->k) % CHUNKS;
540 pthread_mutex_lock(arg->table_mutex[mutex]); 623 pthread_mutex_lock(arg->table_mutex[mutex]);
541 oldval = get_h48_pval(arg->table, coord, arg->k); 624 oldval = get_h48_pval(arg->table, coord, arg->k);
542 newval = (uint8_t)MAX(depth, 0); 625 newval = (uint8_t)MAX(arg->depth, 0);
626 d += newval < oldval;
543 set_h48_pval(arg->table, coord, arg->k, MIN(oldval, newval)); 627 set_h48_pval(arg->table, coord, arg->k, MIN(oldval, newval));
544 pthread_mutex_unlock(arg->table_mutex[mutex]); 628 pthread_mutex_unlock(arg->table_mutex[mutex]);
545 ) 629 )
630
631 return d;
546} 632}
547 633
548STATIC_INLINE bool 634STATIC_INLINE bool
@@ -568,26 +654,44 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg)
568 } 654 }
569} 655}
570 656
571STATIC_INLINE uint8_t 657STATIC size_t
572get_h48_pval(const uint8_t *table, int64_t i, uint8_t k) 658gendata_h48k2_realcoord(gendata_h48_arg_t *arg)
573{ 659{
574 return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); 660 /* TODO */
661 return gendata_h48k2(arg);
575} 662}
576 663
577STATIC_INLINE void 664STATIC void *
578set_h48_pval(uint8_t *table, int64_t i, uint8_t k, uint8_t val) 665gendata_h48k2_realcoord_runthread(void *arg)
579{ 666{
580 table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) 667 /* TODO */
581 | (val << H48_SHIFT(i, k)); 668 return NULL;
582} 669}
583 670
584STATIC_INLINE uint8_t 671STATIC tableinfo_t
585get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table) 672makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base)
586{ 673{
587 int64_t coord; 674 tableinfo_t info;
588 675
589 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); 676 info = (tableinfo_t) {
590 return get_h48_pval(table, coord, k); 677 .solver = "h48 solver h = , k = 2",
678 .type = TABLETYPE_PRUNING,
679 .infosize = INFOSIZE,
680 .fullsize = H48_TABLESIZE(arg->h, 2) + INFOSIZE,
681 .hash = 0, /* TODO */
682 .entries = H48_COORDMAX(arg->h),
683 .classes = 0,
684 .h48h = arg->h,
685 .bits = 2,
686 .base = base,
687 .maxvalue = 3,
688 .next = 0,
689 };
690 info.solver[15] = (arg->h % 10) + '0';
691 if (arg->h >= 10)
692 info.solver[14] = (arg->h / 10) + '0';
693
694 return info;
591} 695}
592 696
593STATIC uint32_t * 697STATIC uint32_t *
@@ -601,3 +705,25 @@ get_h48data_ptr(const void *data)
601{ 705{
602 return (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE; 706 return (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE;
603} 707}
708
709STATIC_INLINE uint8_t
710get_h48_pval(const uint8_t *table, int64_t i, uint8_t k)
711{
712 return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k);
713}
714
715STATIC_INLINE void
716set_h48_pval(uint8_t *table, int64_t i, uint8_t k, uint8_t val)
717{
718 table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k)))
719 | (val << H48_SHIFT(i, k));
720}
721
722STATIC_INLINE uint8_t
723get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table)
724{
725 int64_t coord;
726
727 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h);
728 return get_h48_pval(table, coord, k);
729}

Generated with cgit - Back to sebastiano.tronto.net