diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-25 18:35:47 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-25 18:35:47 +0100 |
| commit | 56048d13b73ec6e6a9c59d62e82f41e69a3994bd (patch) | |
| tree | 49fc5d50e739a399897425756c08a73ba5924ddb /src/solvers/h48/gendata_h48.h | |
| parent | 0f4931c8de298b0f97aba1757c9538f48adb30c6 (diff) | |
| download | nissy-core-56048d13b73ec6e6a9c59d62e82f41e69a3994bd.tar.gz nissy-core-56048d13b73ec6e6a9c59d62e82f41e69a3994bd.zip | |
More safety with pointers using VLA function parameters
Diffstat (limited to 'src/solvers/h48/gendata_h48.h')
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 2d9a9f7..959264d 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -1,17 +1,17 @@ | |||
| 1 | STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); | 1 | STATIC uint64_t genddfggta_h48short(gendata_h48short_arg_t [static 1]); |
| 2 | STATIC int64_t gendata_h48(gendata_h48_arg_t *); | 2 | STATIC int64_t gendata_h48(gendata_h48_arg_t [static 1]); |
| 3 | STATIC void gendata_h48h0k4(gendata_h48_arg_t *); | 3 | STATIC void gendata_h48h0k4(gendata_h48_arg_t [static 1]); |
| 4 | STATIC void gendata_h48k2(gendata_h48_arg_t *); | 4 | STATIC void gendata_h48k2(gendata_h48_arg_t [static 1]); |
| 5 | STATIC void gendata_h48k2_realcoord(gendata_h48_arg_t *); | ||
| 6 | 5 | ||
| 7 | STATIC void * gendata_h48h0k4_runthread(void *); | 6 | STATIC void * gendata_h48h0k4_runthread(void *); |
| 8 | STATIC void * gendata_h48k2_runthread(void *); | 7 | STATIC void * gendata_h48k2_runthread(void *); |
| 9 | 8 | ||
| 10 | STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t *); | 9 | STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t [static 1]); |
| 11 | STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t *); | 10 | STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t [static 1]); |
| 12 | STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); | 11 | STATIC_INLINE bool gendata_h48k2_dfs_stop( |
| 13 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); | 12 | cube_t, int8_t, h48k2_dfs_arg_t [static 1]); |
| 14 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); | 13 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]); |
| 14 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); | ||
| 15 | STATIC void getdistribution_h48(const uint8_t *, | 15 | STATIC void getdistribution_h48(const uint8_t *, |
| 16 | uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); | 16 | uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); |
| 17 | 17 | ||
| @@ -28,7 +28,7 @@ STATIC_INLINE void set_h48_pval_atomic( | |||
| 28 | size_t gendata_h48_derive(uint8_t, const void *, void *); | 28 | size_t gendata_h48_derive(uint8_t, const void *, void *); |
| 29 | 29 | ||
| 30 | STATIC uint64_t | 30 | STATIC uint64_t |
| 31 | gendata_h48short(gendata_h48short_arg_t *arg) | 31 | gendata_h48short(gendata_h48short_arg_t arg[static 1]) |
| 32 | { | 32 | { |
| 33 | uint8_t i, m; | 33 | uint8_t i, m; |
| 34 | int64_t coord; | 34 | int64_t coord; |
| @@ -62,7 +62,7 @@ gendata_h48short(gendata_h48short_arg_t *arg) | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | STATIC int64_t | 64 | STATIC int64_t |
| 65 | gendata_h48(gendata_h48_arg_t *arg) | 65 | gendata_h48(gendata_h48_arg_t arg[static 1]) |
| 66 | { | 66 | { |
| 67 | uint64_t size, cocsepsize, h48size, fallbacksize, fallback2size, of; | 67 | uint64_t size, cocsepsize, h48size, fallbacksize, fallback2size, of; |
| 68 | long long r; | 68 | long long r; |
| @@ -70,11 +70,6 @@ gendata_h48(gendata_h48_arg_t *arg) | |||
| 70 | tableinfo_t cocsepinfo, h48info, fallbackinfo; | 70 | tableinfo_t cocsepinfo, h48info, fallbackinfo; |
| 71 | gendata_h48_arg_t arg_h0k4; | 71 | gendata_h48_arg_t arg_h0k4; |
| 72 | 72 | ||
| 73 | if (arg == NULL) { | ||
| 74 | LOG("Error computing H48 data: arg is NULL.\n"); | ||
| 75 | return NISSY_ERROR_UNKNOWN; | ||
| 76 | } | ||
| 77 | |||
| 78 | cocsepsize = COCSEP_FULLSIZE; | 73 | cocsepsize = COCSEP_FULLSIZE; |
| 79 | h48size = INFOSIZE + H48_TABLESIZE(arg->h, arg->k); | 74 | h48size = INFOSIZE + H48_TABLESIZE(arg->h, arg->k); |
| 80 | fallbacksize = arg->k == 2 ? INFOSIZE + H48_TABLESIZE(0, 4) : 0; | 75 | fallbacksize = arg->k == 2 ? INFOSIZE + H48_TABLESIZE(0, 4) : 0; |
| @@ -107,8 +102,6 @@ gendata_h48(gendata_h48_arg_t *arg) | |||
| 107 | 102 | ||
| 108 | if (arg->h == 0 && arg->k == 4) { | 103 | if (arg->h == 0 && arg->k == 4) { |
| 109 | gendata_h48h0k4(arg); | 104 | gendata_h48h0k4(arg); |
| 110 | } else if ((arg->h == 0 || arg->h == 11) && arg->k == 2) { | ||
| 111 | gendata_h48k2_realcoord(arg); | ||
| 112 | } else if (arg->k == 2) { | 105 | } else if (arg->k == 2) { |
| 113 | gendata_h48k2(arg); | 106 | gendata_h48k2(arg); |
| 114 | } else { | 107 | } else { |
| @@ -189,7 +182,7 @@ gendata_h48(gendata_h48_arg_t *arg) | |||
| 189 | } | 182 | } |
| 190 | 183 | ||
| 191 | STATIC void | 184 | STATIC void |
| 192 | gendata_h48h0k4(gendata_h48_arg_t *arg) | 185 | gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) |
| 193 | { | 186 | { |
| 194 | _Atomic uint8_t *table; | 187 | _Atomic uint8_t *table; |
| 195 | uint8_t val; | 188 | uint8_t val; |
| @@ -325,7 +318,7 @@ gendata_h48h0k4_runthread(void *arg) | |||
| 325 | } | 318 | } |
| 326 | 319 | ||
| 327 | STATIC void | 320 | STATIC void |
| 328 | gendata_h48k2(gendata_h48_arg_t *arg) | 321 | gendata_h48k2(gendata_h48_arg_t arg[static 1]) |
| 329 | { | 322 | { |
| 330 | static const uint8_t shortdepth = 8; | 323 | static const uint8_t shortdepth = 8; |
| 331 | static const uint64_t capacity = 10000019; | 324 | static const uint64_t capacity = 10000019; |
| @@ -483,7 +476,7 @@ gendata_h48k2_runthread(void *arg) | |||
| 483 | } | 476 | } |
| 484 | 477 | ||
| 485 | STATIC void | 478 | STATIC void |
| 486 | gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | 479 | gendata_h48k2_dfs(h48k2_dfs_arg_t arg[static 1]) |
| 487 | { | 480 | { |
| 488 | int8_t d; | 481 | int8_t d; |
| 489 | uint8_t m[4]; | 482 | uint8_t m[4]; |
| @@ -562,7 +555,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | |||
| 562 | } | 555 | } |
| 563 | 556 | ||
| 564 | STATIC_INLINE void | 557 | STATIC_INLINE void |
| 565 | gendata_h48_mark_atomic(gendata_h48_mark_t *arg) | 558 | gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) |
| 566 | { | 559 | { |
| 567 | uint8_t oldval, newval; | 560 | uint8_t oldval, newval; |
| 568 | int64_t coord, mutex; | 561 | int64_t coord, mutex; |
| @@ -582,7 +575,7 @@ gendata_h48_mark_atomic(gendata_h48_mark_t *arg) | |||
| 582 | } | 575 | } |
| 583 | 576 | ||
| 584 | STATIC_INLINE void | 577 | STATIC_INLINE void |
| 585 | gendata_h48_mark(gendata_h48_mark_t *arg) | 578 | gendata_h48_mark(gendata_h48_mark_t arg[static 1]) |
| 586 | { | 579 | { |
| 587 | uint8_t oldval, newval; | 580 | uint8_t oldval, newval; |
| 588 | int64_t coord, mutex; | 581 | int64_t coord, mutex; |
| @@ -599,7 +592,7 @@ gendata_h48_mark(gendata_h48_mark_t *arg) | |||
| 599 | } | 592 | } |
| 600 | 593 | ||
| 601 | STATIC_INLINE bool | 594 | STATIC_INLINE bool |
| 602 | gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) | 595 | gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) |
| 603 | { | 596 | { |
| 604 | uint64_t val; | 597 | uint64_t val; |
| 605 | int64_t coord, mutex; | 598 | int64_t coord, mutex; |
| @@ -613,7 +606,7 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) | |||
| 613 | pthread_mutex_lock(arg->table_mutex[mutex]); | 606 | pthread_mutex_lock(arg->table_mutex[mutex]); |
| 614 | oldval = get_h48_pval(arg->table, coord, arg->k); | 607 | oldval = get_h48_pval(arg->table, coord, arg->k); |
| 615 | pthread_mutex_unlock(arg->table_mutex[mutex]); | 608 | pthread_mutex_unlock(arg->table_mutex[mutex]); |
| 616 | return oldval <= depth; | 609 | return oldval <= d; |
| 617 | } else { | 610 | } else { |
| 618 | /* With 0 < k < 11 we do not have a "real coordinate". | 611 | /* With 0 < k < 11 we do not have a "real coordinate". |
| 619 | The best we can do is checking if we backtracked to | 612 | The best we can do is checking if we backtracked to |
| @@ -624,22 +617,8 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) | |||
| 624 | } | 617 | } |
| 625 | } | 618 | } |
| 626 | 619 | ||
| 627 | STATIC void | ||
| 628 | gendata_h48k2_realcoord(gendata_h48_arg_t *arg) | ||
| 629 | { | ||
| 630 | /* TODO */ | ||
| 631 | gendata_h48k2(arg); | ||
| 632 | } | ||
| 633 | |||
| 634 | STATIC void * | ||
| 635 | gendata_h48k2_realcoord_runthread(void *arg) | ||
| 636 | { | ||
| 637 | /* TODO */ | ||
| 638 | return NULL; | ||
| 639 | } | ||
| 640 | |||
| 641 | STATIC tableinfo_t | 620 | STATIC tableinfo_t |
| 642 | makeinfo_h48k2(gendata_h48_arg_t *arg) | 621 | makeinfo_h48k2(gendata_h48_arg_t arg[static 1]) |
| 643 | { | 622 | { |
| 644 | tableinfo_t info; | 623 | tableinfo_t info; |
| 645 | 624 | ||
