From 70d3a3de3a2fdef7e47b2bd510261d69390a3a9c Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 10 Sep 2024 19:43:05 +0200 Subject: New tableinfo for gendata_h48, still work to do --- test/090_tables_readwrite/00_table.in | 1 + test/090_tables_readwrite/00_table.out | 1 + test/090_tables_readwrite/tables_readwrite_tests.c | 5 +- test/100_gendata_cocsep/00_all.out | 2 +- test/100_gendata_cocsep/gendata_cocsep_tests.c | 35 +++++++-- .../cocsep_transform_invariant.c | 9 ++- test/102_cocsep_selfsim/cocsep_selfsim_tests.c | 7 +- .../cocsep_selfsim_distribution_tests.c | 2 +- test/104_cocsep_ttrep/cocsep_ttrep_tests.c | 10 ++- .../coord_invcoord_h48_tests.c | 7 +- test/112_gen_h48short/gen_h48short.c | 87 --------------------- test/112_gen_h48short/gen_h48short_tests.c | 88 ++++++++++++++++++++++ test/120_gendata_h48h0k4/00_h_0.out | 2 +- test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c | 60 ++++++++++++--- 14 files changed, 198 insertions(+), 118 deletions(-) delete mode 100644 test/112_gen_h48short/gen_h48short.c create mode 100644 test/112_gen_h48short/gen_h48short_tests.c (limited to 'test') diff --git a/test/090_tables_readwrite/00_table.in b/test/090_tables_readwrite/00_table.in index f286968..579736a 100644 --- a/test/090_tables_readwrite/00_table.in +++ b/test/090_tables_readwrite/00_table.in @@ -5,6 +5,7 @@ Test solver 100000000000 12345678912345 399999999998 +3393 2 0 20 diff --git a/test/090_tables_readwrite/00_table.out b/test/090_tables_readwrite/00_table.out index f286968..579736a 100644 --- a/test/090_tables_readwrite/00_table.out +++ b/test/090_tables_readwrite/00_table.out @@ -5,6 +5,7 @@ Test solver 100000000000 12345678912345 399999999998 +3393 2 0 20 diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c index f3162ea..32d171a 100644 --- a/test/090_tables_readwrite/tables_readwrite_tests.c +++ b/test/090_tables_readwrite/tables_readwrite_tests.c @@ -1,7 +1,7 @@ #include "../test.h" #define INFOSIZE 512 -#define INFO_SOLVER_STRLEN 20 +#define INFO_SOLVER_STRLEN 100 #define INFO_DISTRIBUTION_LEN 21 typedef struct { @@ -11,6 +11,7 @@ typedef struct { uint64_t fullsize; uint64_t hash; uint64_t entries; + uint64_t classes; uint8_t bits; uint8_t base; uint8_t maxvalue; @@ -45,6 +46,7 @@ tableinfo_t test_readinfo(void) { ret.fullsize = readn(); ret.hash = readn(); ret.entries = readn(); + ret.classes = readn(); ret.bits = (uint8_t)readn(); ret.base = (uint8_t)readn(); ret.maxvalue = (uint8_t)readn(); @@ -69,6 +71,7 @@ void test_writeinfo(tableinfo_t info) { printf("%" PRIu64 "\n", info.fullsize); printf("%" PRIu64 "\n", info.hash); printf("%" PRIu64 "\n", info.entries); + printf("%" PRIu64 "\n", info.classes); printf("%" PRIu8 "\n", info.bits); printf("%" PRIu8 "\n", info.base); printf("%" PRIu8 "\n", info.maxvalue); diff --git a/test/100_gendata_cocsep/00_all.out b/test/100_gendata_cocsep/00_all.out index e14b938..82eb6c2 100644 --- a/test/100_gendata_cocsep/00_all.out +++ b/test/100_gendata_cocsep/00_all.out @@ -1,4 +1,4 @@ -1119792 +1120256 Classes: 3393 Max value: 9 0: 1 diff --git a/test/100_gendata_cocsep/gendata_cocsep_tests.c b/test/100_gendata_cocsep/gendata_cocsep_tests.c index 4a29ebb..ee26de9 100644 --- a/test/100_gendata_cocsep/gendata_cocsep_tests.c +++ b/test/100_gendata_cocsep/gendata_cocsep_tests.c @@ -1,20 +1,45 @@ #include "../test.h" -#define COCSEP_CLASSES 3393 +#define INFOSIZE 512 +#define INFO_SOLVER_STRLEN 100 +#define INFO_DISTRIBUTION_LEN 21 +#define COCSEP_CLASSES 3393 + +typedef struct { + char solver[INFO_SOLVER_STRLEN]; + uint64_t type; + uint64_t infosize; + uint64_t fullsize; + uint64_t hash; + uint64_t entries; + uint64_t classes; /* Used only by cocsepdata, for now */ + uint8_t bits; + uint8_t base; + uint8_t maxvalue; + uint64_t next; + uint64_t distribution[INFO_DISTRIBUTION_LEN]; +} tableinfo_t; size_t gendata_cocsep(void *, uint64_t *, cube_t *); +bool readtableinfo(const void *, tableinfo_t *); void run(void) { - uint32_t buf[300000], i; + char buf[2000000]; + uint32_t i; uint64_t selfsim[COCSEP_CLASSES]; cube_t rep[COCSEP_CLASSES]; size_t result; + tableinfo_t info; result = gendata_cocsep(buf, selfsim, rep); + if (!readtableinfo(buf, &info)) { + printf("Error reading info from table\n"); + return; + } printf("%zu\n", result); - printf("Classes: %" PRIu32 "\n", buf[result/4-12]); - printf("Max value: %" PRIu32 "\n", buf[result/4-11]); + printf("Classes: %" PRIu64 "\n", info.classes); + printf("Max value: %" PRIu8 "\n", info.maxvalue); for (i = 0; i < 10; i++) - printf("%" PRIu32 ": %" PRIu32 "\n", i, buf[result/4-10+i]); + printf("%" PRIu32 ": %" PRIu64 "\n", i, info.distribution[i]); } diff --git a/test/101_cocsep_transform_invariant/cocsep_transform_invariant.c b/test/101_cocsep_transform_invariant/cocsep_transform_invariant.c index b0286e5..67f70a5 100644 --- a/test/101_cocsep_transform_invariant/cocsep_transform_invariant.c +++ b/test/101_cocsep_transform_invariant/cocsep_transform_invariant.c @@ -3,6 +3,7 @@ #define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) #define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) +#define INFOSIZE 512 #define COCSEP_CLASSES 3393 size_t gendata_cocsep(void *, uint64_t *, cube_t *); @@ -11,7 +12,8 @@ int64_t coord_cocsep(cube_t); void run(void) { uint8_t t; - uint32_t buf[300000]; + char buf[2000000]; + uint32_t *cocsepdata; uint64_t selfsim[COCSEP_CLASSES]; int64_t coord, tcoord; char str[STRLENMAX]; @@ -21,11 +23,12 @@ void run(void) { cube = readcube("H48", str); gendata_cocsep(buf, selfsim, rep); + cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); - coord = (int64_t)COCLASS(buf[coord_cocsep(cube)]); + coord = (int64_t)COCLASS(cocsepdata[coord_cocsep(cube)]); for (t = 0; t < 48; t++) { transd = transform(cube, t); - tcoord = (int64_t)COCLASS(buf[coord_cocsep(transd)]); + tcoord = (int64_t)COCLASS(cocsepdata[coord_cocsep(transd)]); if (coord != tcoord) printf("Error: expected %" PRId64 " but got %" PRId64 "\n", coord, tcoord); diff --git a/test/102_cocsep_selfsim/cocsep_selfsim_tests.c b/test/102_cocsep_selfsim/cocsep_selfsim_tests.c index 7211e2e..490952a 100644 --- a/test/102_cocsep_selfsim/cocsep_selfsim_tests.c +++ b/test/102_cocsep_selfsim/cocsep_selfsim_tests.c @@ -8,25 +8,28 @@ #include "../test.h" #define COCSEP_CLASSES 3393 +#define INFOSIZE 512 size_t gendata_cocsep(void *, uint64_t *, cube_t *); int64_t coord_cocsep(cube_t); void run(void) { char str[STRLENMAX]; - uint32_t buf[300000], data; + char buf[2000000]; + uint32_t *cocsepdata, data; int64_t coord, coclass; uint64_t selfsim[COCSEP_CLASSES], sim, t; cube_t cube, rep[COCSEP_CLASSES]; gendata_cocsep(buf, selfsim, rep); + cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); /* All cases in the same test so we do not generate data many times */ while (fgets(str, STRLENMAX, stdin) != NULL) { cube = readcube("H48", str); coord = coord_cocsep(cube); - data = buf[coord]; + data = cocsepdata[coord]; coclass = (data & (0xFFFU << 16)) >> 16; sim = selfsim[coclass]; for (t = 0; t < 48 && sim; t++, sim >>= 1) { diff --git a/test/103_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c b/test/103_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c index fb1338e..84e3fd8 100644 --- a/test/103_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c +++ b/test/103_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c @@ -17,7 +17,7 @@ int bcount(uint64_t x) { } void run(void) { - uint32_t buf[300000]; + char buf[2000000]; int size[65], tot, j; int64_t i; uint64_t selfsim[COCSEP_CLASSES], sim; diff --git a/test/104_cocsep_ttrep/cocsep_ttrep_tests.c b/test/104_cocsep_ttrep/cocsep_ttrep_tests.c index f692ca8..efe5a26 100644 --- a/test/104_cocsep_ttrep/cocsep_ttrep_tests.c +++ b/test/104_cocsep_ttrep/cocsep_ttrep_tests.c @@ -1,9 +1,11 @@ #include "../test.h" -#define COCSEP_CLASSES 3393 #define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) #define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) +#define COCSEP_CLASSES 3393 +#define INFOSIZE 512 + uint8_t inverse_trans(uint8_t); cube_t transform_corners(cube_t, uint8_t); int64_t coord_cocsep(cube_t); @@ -11,19 +13,21 @@ size_t gendata_cocsep(void *, uint64_t *, cube_t *); void run(void) { uint8_t t; - uint32_t buf[300000], tt; + char buf[2000000]; + uint32_t *cocsepdata, tt; uint64_t selfsim[COCSEP_CLASSES]; int64_t i, j, k, l; cube_t rep[COCSEP_CLASSES], c, d; gendata_cocsep(buf, selfsim, rep); + cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); for (i = 0; i < COCSEP_CLASSES; i++) { c = rep[i]; for (t = 0; t < 48; t++) { d = transform_corners(c, t); j = coord_cocsep(d); - tt = TTREP(buf[j]); + tt = TTREP(cocsepdata[j]); d = transform_corners(d, tt); k = coord_cocsep(d); l = coord_cocsep(c); diff --git a/test/110_coord_invcoord_h48/coord_invcoord_h48_tests.c b/test/110_coord_invcoord_h48/coord_invcoord_h48_tests.c index 77dea81..1fcbabd 100644 --- a/test/110_coord_invcoord_h48/coord_invcoord_h48_tests.c +++ b/test/110_coord_invcoord_h48/coord_invcoord_h48_tests.c @@ -1,6 +1,7 @@ #include "../test.h" #define COCSEP_CLASSES 3393 +#define INFOSIZE 512 size_t gendata_cocsep(void *, uint64_t *, cube_t *); int64_t coord_h48(cube_t, const uint32_t *, uint8_t); @@ -12,12 +13,14 @@ void run(void) { int i; bool found; uint8_t h, t; - uint32_t cocsepdata[300000]; + char buf[2000000]; + uint32_t *cocsepdata; uint64_t selfsim[COCSEP_CLASSES]; int64_t c, cc; cube_t cube, invc, rep[COCSEP_CLASSES]; - gendata_cocsep(cocsepdata, selfsim, rep); + gendata_cocsep(buf, selfsim, rep); + cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); i = 1; h = 11; diff --git a/test/112_gen_h48short/gen_h48short.c b/test/112_gen_h48short/gen_h48short.c deleted file mode 100644 index 335821a..0000000 --- a/test/112_gen_h48short/gen_h48short.c +++ /dev/null @@ -1,87 +0,0 @@ -#include "../test.h" - -#define COCSEP_CLASSES 3393 -#define MAXPOS 200 - -typedef struct { - uint64_t n; - uint64_t capacity; - uint64_t randomizer; - uint64_t *table; - uint32_t *info; - uint32_t *cocsepdata; - uint32_t *h48data; - uint64_t selfsim[COCSEP_CLASSES]; - cube_t crep[COCSEP_CLASSES]; -} h48map_t; - -typedef struct { - uint64_t key; - uint64_t val; -} kvpair_t; - -typedef struct { - uint8_t maxdepth; - const uint32_t *cocsepdata; - const cube_t *crep; - const uint64_t *selfsim; - h48map_t *map; -} gendata_h48short_arg_t; - -void h48map_create(h48map_t *, uint64_t, uint64_t); -void h48map_destroy(h48map_t *); -kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); -size_t gendata_cocsep(void *, uint64_t *, cube_t *); -uint64_t gen_h48short(gendata_h48short_arg_t *); - -char str[STRLENMAX]; - -int compare(const void *x, const void *y) { - uint64_t a = ((kvpair_t *)x)->key; - uint64_t b = ((kvpair_t *)y)->key; - - if (a > b) return 1; - if (a == b) return 0; - return -1; -} - -uint64_t readl(void) { - fgets(str, STRLENMAX, stdin); - return atoll(str); -} - -void run(void) { - uint32_t cocsepdata[300000]; - h48map_t map; - uint64_t i, j, capacity, randomizer, selfsim[COCSEP_CLASSES]; - kvpair_t kv, b[MAXPOS]; - gendata_h48short_arg_t arg; - cube_t crep[COCSEP_CLASSES]; - - capacity = readl(); - randomizer = readl(); - arg.maxdepth = readl(); - arg.cocsepdata = cocsepdata; - arg.crep = crep; - arg.selfsim = selfsim; - arg.map = ↦ - - h48map_create(&map, capacity, randomizer); - gendata_cocsep(cocsepdata, selfsim, crep); - gen_h48short(&arg); - - i = 0; - for (kv = h48map_nextkvpair(&map, &i), j = 0; - i != map.capacity && j < MAXPOS; - kv = h48map_nextkvpair(&map, &i) - ) { - b[j++] = kv; - } - qsort(b, j, sizeof(kvpair_t), compare); - - printf("%" PRIu64 "\n", map.n); - for (i = 0; i < j; i++) - printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val); - - h48map_destroy(&map); -} diff --git a/test/112_gen_h48short/gen_h48short_tests.c b/test/112_gen_h48short/gen_h48short_tests.c new file mode 100644 index 0000000..a706dff --- /dev/null +++ b/test/112_gen_h48short/gen_h48short_tests.c @@ -0,0 +1,88 @@ +#include "../test.h" + +#define COCSEP_CLASSES 3393 +#define INFOSIZE 512 +#define MAXPOS 200 + +typedef struct { + uint64_t n; + uint64_t capacity; + uint64_t randomizer; + uint64_t *table; + uint32_t *info; + uint32_t *cocsepdata; + uint32_t *h48data; + uint64_t selfsim[COCSEP_CLASSES]; + cube_t crep[COCSEP_CLASSES]; +} h48map_t; + +typedef struct { + uint64_t key; + uint64_t val; +} kvpair_t; + +typedef struct { + uint8_t maxdepth; + const uint32_t *cocsepdata; + const cube_t *crep; + const uint64_t *selfsim; + h48map_t *map; +} gendata_h48short_arg_t; + +void h48map_create(h48map_t *, uint64_t, uint64_t); +void h48map_destroy(h48map_t *); +kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); +size_t gendata_cocsep(void *, uint64_t *, cube_t *); +uint64_t gen_h48short(gendata_h48short_arg_t *); + +char str[STRLENMAX]; + +int compare(const void *x, const void *y) { + uint64_t a = ((kvpair_t *)x)->key; + uint64_t b = ((kvpair_t *)y)->key; + + if (a > b) return 1; + if (a == b) return 0; + return -1; +} + +uint64_t readl(void) { + fgets(str, STRLENMAX, stdin); + return atoll(str); +} + +void run(void) { + char buf[2000000]; + h48map_t map; + uint64_t i, j, capacity, randomizer, selfsim[COCSEP_CLASSES]; + kvpair_t kv, b[MAXPOS]; + gendata_h48short_arg_t arg; + cube_t crep[COCSEP_CLASSES]; + + capacity = readl(); + randomizer = readl(); + arg.maxdepth = readl(); + arg.crep = crep; + arg.selfsim = selfsim; + arg.map = ↦ + + h48map_create(&map, capacity, randomizer); + gendata_cocsep(buf, selfsim, crep); + arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); + gen_h48short(&arg); + + i = 0; + for (kv = h48map_nextkvpair(&map, &i), j = 0; + i != map.capacity && j < MAXPOS; + kv = h48map_nextkvpair(&map, &i) + ) { + b[j++] = kv; + } + qsort(b, j, sizeof(kvpair_t), compare); + + printf("%" PRIu64 "\n", map.n); + for (i = 0; i < j; i++) + printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val); + + h48map_destroy(&map); +} diff --git a/test/120_gendata_h48h0k4/00_h_0.out b/test/120_gendata_h48h0k4/00_h_0.out index 04e8bf6..7d70463 100644 --- a/test/120_gendata_h48h0k4/00_h_0.out +++ b/test/120_gendata_h48h0k4/00_h_0.out @@ -1,4 +1,4 @@ -59903605 +59904493 cocsepdata: Classes: 3393 diff --git a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c index d6c6cb2..bc3488c 100644 --- a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c +++ b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c @@ -1,27 +1,47 @@ #include "../test.h" -#define COCSEP_CLASSES 3393 -#define COCSEPSIZE 1119792 +#define COCSEP_CLASSES 3393 +#define INFOSIZE 512 +#define INFO_SOLVER_STRLEN 100 +#define INFO_DISTRIBUTION_LEN 21 + +typedef struct { + char solver[INFO_SOLVER_STRLEN]; + uint64_t type; + uint64_t infosize; + uint64_t fullsize; + uint64_t hash; + uint64_t entries; + uint64_t classes; /* Used only by cocsepdata, for now */ + uint8_t bits; + uint8_t base; + uint8_t maxvalue; + uint64_t next; + uint64_t distribution[INFO_DISTRIBUTION_LEN]; +} tableinfo_t; typedef struct { uint8_t h; uint8_t k; uint8_t maxdepth; + tableinfo_t info; void *buf; - uint32_t *info; + void *h48buf; uint32_t *cocsepdata; - uint32_t *h48data; uint64_t selfsim[COCSEP_CLASSES]; cube_t crep[COCSEP_CLASSES]; } gendata_h48_arg_t; int64_t gendata_h48(gendata_h48_arg_t *); +bool readtableinfo(const void *, tableinfo_t *); void run(void) { char str[STRLENMAX]; uint8_t i; gendata_h48_arg_t arg; size_t result, sz; + tableinfo_t cinfo, hinfo; + void *h48buf; fgets(str, STRLENMAX, stdin); arg.maxdepth = atoi(str); @@ -30,21 +50,37 @@ void run(void) { arg.k = 4; sz = gendata_h48(&arg); /* With buf = NULL returns data size */ - arg.buf = malloc(sz); + arg.buf = malloc(sz+23); +/* +TODO: the +23 is a workaround for a bug that I don't understand and seems +to happen only with gcc. Hopefully this gets fixed when switching to 8-bit. +*/ + result = gendata_h48(&arg); + if (!readtableinfo(arg.buf, &cinfo)) { + printf("Error reading cocsep info\n"); + goto end; + } + + h48buf = (char *)arg.buf + cinfo.next; + if (!readtableinfo(h48buf, &hinfo)) { + printf("Error reading h48 info\n"); + goto end; + } + printf("%zu\n\n", result); printf("cocsepdata:\n"); - printf("Classes: %" PRIu32 "\n", arg.cocsepdata[COCSEPSIZE/4-12]); - printf("Max value: %" PRIu32 "\n", arg.cocsepdata[COCSEPSIZE/4-11]); - for (i = 0; i < 10; i++) - printf("%" PRIu32 ": %" PRIu32 "\n", - i, arg.cocsepdata[COCSEPSIZE/4-10+i]); + printf("Classes: %" PRIu64 "\n", cinfo.classes); + printf("Max value: %" PRIu8 "\n", cinfo.maxvalue); + for (i = 0; i <= cinfo.maxvalue; i++) + printf("%" PRIu32 ": %" PRIu64 "\n", i, cinfo.distribution[i]); printf("\nh48:\n"); - for (i = 0; i < arg.maxdepth+1; i++) - printf("%" PRIu32 ": %" PRIu32 "\n", i, arg.info[i+1]); + for (i = 0; i <= hinfo.maxvalue; i++) + printf("%" PRIu32 ": %" PRIu64 "\n", i, hinfo.distribution[i]); +end: free(arg.buf); } -- cgit v1.3