aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/solvers/h48/gendata_h48.h21
-rw-r--r--src/solvers/h48/map.h5
-rw-r--r--src/utils/math.h1
-rw-r--r--tools/001_gendata_h48h0k4/gendata_h48h0k4.c4
-rw-r--r--tools/002_gendata_h48h0k2/gendata_h48h0k2.c62
-rw-r--r--tools/010_stats_tables_h48/stats_tables_h48.c (renamed from tools/002_stats_tables_h48/stats_tables_h48.c)0
-rw-r--r--tools/020_solve_small/solve_small.c (renamed from tools/003_solve_small/solve_small.c)0
7 files changed, 83 insertions, 10 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index c421c27..fbb8b35 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -1,6 +1,7 @@
1#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * _12c4 * _8c4)) 1#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * _12c4 * _8c4))
2#define H48_COORDMAX(h) ((int64_t)(H48_COORDMAX_NOEO << (int64_t)(h))) 2#define H48_COORDMAX(h) ((int64_t)(H48_COORDMAX_NOEO << (int64_t)(h)))
3#define H48_TABLESIZE(h, k) ((size_t)H48_COORDMAX((h)) / ((size_t)8 / (size_t)(k))) 3#define H48_DIV(k) ((size_t)8 / (size_t)(k))
4#define H48_TABLESIZE(h, k) _div_round_up((size_t)H48_COORDMAX((h)), H48_DIV(k))
4 5
5#define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k)) 6#define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k))
6#define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k)) 7#define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k))
@@ -140,7 +141,7 @@ gendata_h48(gendata_h48_arg_t *arg)
140 cocsepsize = gendata_cocsep( 141 cocsepsize = gendata_cocsep(
141 (void *)arg->cocsepdata, arg->selfsim, arg->crep); 142 (void *)arg->cocsepdata, arg->selfsim, arg->crep);
142 arg->h48data = arg->cocsepdata + (cocsepsize / sizeof(uint32_t)); 143 arg->h48data = arg->cocsepdata + (cocsepsize / sizeof(uint32_t));
143 arg->info = arg->h48data + 144 arg->info = arg->h48data + 1 +
144 (H48_TABLESIZE(arg->h, arg->k) / sizeof(uint32_t)); 145 (H48_TABLESIZE(arg->h, arg->k) / sizeof(uint32_t));
145 146
146 if (arg->buf != NULL) 147 if (arg->buf != NULL)
@@ -341,18 +342,27 @@ gendata_h48k2(gendata_h48_arg_t *arg)
341 }; 342 };
342 343
343 i = 0; 344 i = 0;
345int jj = 0;
344 for (kv = h48map_nextkvpair(&shortcubes, &i); 346 for (kv = h48map_nextkvpair(&shortcubes, &i);
345 i != shortcubes.capacity; 347 i != shortcubes.capacity;
346 kv = h48map_nextkvpair(&shortcubes, &i) 348 kv = h48map_nextkvpair(&shortcubes, &i)
347 ) { 349 ) {
348 /* TODO maybe over all sim? */
349 dfsarg.cube = invcoord_h48(kv.key, arg->crep, 11); 350 dfsarg.cube = invcoord_h48(kv.key, arg->crep, 11);
351
352#if 1
350 gendata_h48k2_dfs(&dfsarg); 353 gendata_h48k2_dfs(&dfsarg);
354#else
355 /* It looks like this is not necessary, we get the same result */
356 _foreach_h48sim(
357 dfsarg.cube, arg->cocsepdata, arg->selfsim, arg->h,
358 gendata_h48k2_dfs(&dfsarg);
359 )
360#endif
361if ((++jj) % 1000 == 0) LOG("Done %d distance 8 cubes\n", jj);
351 } 362 }
352 363
353 h48map_destroy(&shortcubes); 364 h48map_destroy(&shortcubes);
354 365
355 /* TODO: move info update to dfs? */
356 memset(arg->info, 0, 5 * sizeof(arg->info[0])); 366 memset(arg->info, 0, 5 * sizeof(arg->info[0]));
357 arg->info[0] = base[arg->k]; 367 arg->info[0] = base[arg->k];
358 for (j = 0; j < H48_COORDMAX(arg->h); j++) { 368 for (j = 0; j < H48_COORDMAX(arg->h); j++) {
@@ -384,8 +394,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg)
384 set_esep_pval(arg->h48data, coord, arg->k, newval); 394 set_esep_pval(arg->h48data, coord, arg->k, newval);
385 } 395 }
386 396
387 if ((val < arg->shortdepth) || 397 if ((arg->depth > arg->shortdepth && val != MAP_UNSET_VAL) ||
388 (arg->depth > arg->shortdepth && val != MAP_UNSET) ||
389 (arg->depth >= arg->maxdepth || arg->depth >= arg->base + 2)) 398 (arg->depth >= arg->maxdepth || arg->depth >= arg->base + 2))
390 return; 399 return;
391 400
diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h
index 82e5a2c..0e9f926 100644
--- a/src/solvers/h48/map.h
+++ b/src/solvers/h48/map.h
@@ -1,6 +1,7 @@
1#define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF) 1#define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF)
2#define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF) 2#define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF)
3#define MAP_KEYSHIFT UINT64_C(40) 3#define MAP_KEYSHIFT UINT64_C(40)
4#define MAP_UNSET_VAL (MAP_UNSET >> MAP_KEYSHIFT)
4 5
5typedef struct { 6typedef struct {
6 uint64_t n; 7 uint64_t n;
@@ -84,8 +85,8 @@ h48map_nextkvpair(h48map_t *map, uint64_t *p)
84 kvpair_t kv; 85 kvpair_t kv;
85 uint64_t pair; 86 uint64_t pair;
86 87
87 kv.key = MAP_UNSET; 88 kv.key = MAP_KEYMASK;
88 kv.val = MAP_UNSET; 89 kv.val = MAP_UNSET_VAL;
89 90
90 DBG_ASSERT(*p < map->capacity, kv, 91 DBG_ASSERT(*p < map->capacity, kv,
91 "Error looping over map: given index %" PRIu64 " is out of " 92 "Error looping over map: given index %" PRIu64 " is out of "
diff --git a/src/utils/math.h b/src/utils/math.h
index 87402e6..a361808 100644
--- a/src/utils/math.h
+++ b/src/utils/math.h
@@ -1,6 +1,7 @@
1#define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) 1#define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0)
2#define _min(x, y) ((x) < (y) ? (x) : (y)) 2#define _min(x, y) ((x) < (y) ? (x) : (y))
3#define _max(x, y) ((x) > (y) ? (x) : (y)) 3#define _max(x, y) ((x) > (y) ? (x) : (y))
4#define _div_round_up(n, d) (((n) + (d) - 1) / (d))
4 5
5_static int64_t factorial(int64_t); 6_static int64_t factorial(int64_t);
6_static bool isperm(uint8_t *, int64_t); 7_static bool isperm(uint8_t *, int64_t);
diff --git a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c
index 0926a34..a2c57ca 100644
--- a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c
+++ b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c
@@ -37,12 +37,12 @@ void run(void) {
37 printf("Error generating table\n"); 37 printf("Error generating table\n");
38 } else { 38 } else {
39 printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); 39 printf("Succesfully generated %" PRId64 " bytes. Table:\n", s);
40 h48info = (uint32_t *)buf + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; 40 h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4;
41 for (i = 0; i < MAXDEPTH+1 && h48info[i+1]; i++) { 41 for (i = 0; i < MAXDEPTH+1 && h48info[i+1]; i++) {
42 x = h48info[i+1]; 42 x = h48info[i+1];
43 printf("%d:\t%" PRIu32, i, x); 43 printf("%d:\t%" PRIu32, i, x);
44 if (x != expected[i]) 44 if (x != expected[i])
45 printf(" <--- Error! Expected: %" PRIu32 "\n", 45 printf(" <--- Error! Expected: %" PRIu32,
46 expected[i]); 46 expected[i]);
47 printf("\n"); 47 printf("\n");
48 } 48 }
diff --git a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c
new file mode 100644
index 0000000..2754f80
--- /dev/null
+++ b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c
@@ -0,0 +1,62 @@
1#include "../tool.h"
2
3#define MAXDEPTH 20
4#define HVALUE 0
5#define OPTIONS "0;2;20"
6#define LONGOPTIONS "h = 0, k = 2, max depth = 20"
7
8#define COCSEPSIZE 1119792
9#define ETABLESIZE(h) (((3393 * 495 * 70) >> 2) << (size_t)(h))
10
11uint32_t expected[21] = {
12 /* Base value is 8 */
13 [0] = 5473562,
14 [1] = 34776317,
15 [2] = 68566704,
16 [3] = 8750867,
17};
18
19char *buf;
20
21void run(void) {
22 uint32_t *h48info, x;
23 int i;
24 int64_t s;
25
26 s = nissy_gendata("h48", OPTIONS, buf);
27
28 if (s == -1) {
29 printf("Error generating table\n");
30 } else {
31 printf("Succesfully generated %" PRId64 " bytes. Table:\n", s);
32 h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4;
33 for (i = 0; i < 4; i++) {
34 x = h48info[i+1];
35 printf("%d:\t%" PRIu32, i, x);
36 if (x != expected[i])
37 printf(" <--- Error! Expected: %" PRIu32,
38 expected[i]);
39 printf("\n");
40 }
41 }
42}
43
44int main(void) {
45 int64_t size;
46
47 nissy_setlogger(log_stderr);
48
49 size = nissy_datasize("h48", OPTIONS);
50 if (size == -1) {
51 printf("gendata_h48 benchmark: error in datasize\n");
52 return 1;
53 }
54
55 buf = malloc(size);
56
57 timerun(run, "benchmark gendata_h48 " LONGOPTIONS);
58
59 free(buf);
60
61 return 0;
62}
diff --git a/tools/002_stats_tables_h48/stats_tables_h48.c b/tools/010_stats_tables_h48/stats_tables_h48.c
index 8b65862..8b65862 100644
--- a/tools/002_stats_tables_h48/stats_tables_h48.c
+++ b/tools/010_stats_tables_h48/stats_tables_h48.c
diff --git a/tools/003_solve_small/solve_small.c b/tools/020_solve_small/solve_small.c
index dee2b55..dee2b55 100644
--- a/tools/003_solve_small/solve_small.c
+++ b/tools/020_solve_small/solve_small.c

Generated with cgit - Back to sebastiano.tronto.net