aboutsummaryrefslogtreecommitdiff
path: root/cube.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-04-20 10:49:27 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-04-20 10:49:27 +0200
commit9ed96a1ea3fc742791a8774267d5c7d5b604ce79 (patch)
tree4d045aff3c65474ad9a89d3d26299ab65a396b66 /cube.c
parent81708be1d1784f41343530e8e01a68094bc50da6 (diff)
downloadnissy-core-9ed96a1ea3fc742791a8774267d5c7d5b604ce79.tar.gz
nissy-core-9ed96a1ea3fc742791a8774267d5c7d5b604ce79.zip
Fixed edge pruning table, but it is slooooow
Diffstat (limited to 'cube.c')
-rw-r--r--cube.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/cube.c b/cube.c
index 2d94482..2f000ce 100644
--- a/cube.c
+++ b/cube.c
@@ -1096,7 +1096,7 @@ _static void writetrans(uint8_t, char *);
1096_static cube_fast_t move(cube_fast_t, uint8_t); 1096_static cube_fast_t move(cube_fast_t, uint8_t);
1097_static cube_fast_t transform(cube_fast_t, uint8_t); 1097_static cube_fast_t transform(cube_fast_t, uint8_t);
1098 1098
1099_static_inline int64_t coord_fast_h48(cube_fast_t, uint32_t *, uint8_t); 1099_static_inline int64_t coord_h48(cube_fast_t, uint32_t *, uint8_t);
1100 1100
1101cube_t 1101cube_t
1102solvedcube(void) 1102solvedcube(void)
@@ -1803,15 +1803,14 @@ transform(cube_fast_t c, uint8_t t)
1803 1803
1804/* h is the number of eo bits used */ 1804/* h is the number of eo bits used */
1805_static_inline int64_t 1805_static_inline int64_t
1806coord_fast_h48(cube_fast_t c, uint32_t *cocsepdata, uint8_t h) 1806coord_h48(cube_fast_t c, uint32_t *cocsepdata, uint8_t h)
1807{ 1807{
1808 cube_fast_t d; 1808 cube_fast_t d;
1809 int64_t cocsep, coclass, esep, eo, esize; 1809 int64_t cocsep, coclass, esep, eo, esize, ret;
1810 uint32_t data; 1810 uint32_t data;
1811 uint8_t ttrep; 1811 uint8_t ttrep;
1812 1812
1813 DBG_ASSERT(h <= 11, -1, 1813 DBG_ASSERT(h <= 11, -1, "coord_h48: h must be between 0 and 11\n");
1814 "coord_fast_h48: h must be between 0 and 11\n");
1815 1814
1816 cocsep = coord_fast_cocsep(c); 1815 cocsep = coord_fast_cocsep(c);
1817 data = cocsepdata[cocsep]; 1816 data = cocsepdata[cocsep];
@@ -1823,7 +1822,9 @@ coord_fast_h48(cube_fast_t c, uint32_t *cocsepdata, uint8_t h)
1823 eo = coord_fast_eo(d); 1822 eo = coord_fast_eo(d);
1824 1823
1825 esize = (_12c4 * _8c4) << h; 1824 esize = (_12c4 * _8c4) << h;
1826 return (coclass * esize) + (esep << h) + (eo >> (11-h)); 1825 ret = (coclass * esize) + (esep << h) + (eo >> (11-h));
1826
1827 return ret;
1827} 1828}
1828 1829
1829/****************************************************************************** 1830/******************************************************************************
@@ -2025,7 +2026,6 @@ gendata_eoesep(uint8_t h, uint8_t k, const void *cocsepdata, void *buf)
2025 2026
2026 buf32 = (uint32_t *)buf; 2027 buf32 = (uint32_t *)buf;
2027 info = buf32 + tablesize; 2028 info = buf32 + tablesize;
2028DBG_LOG("Allocating 4 * %zu bytes\n", tablesize);
2029 memset(buf32, 0xFFU, 4*tablesize); 2029 memset(buf32, 0xFFU, 4*tablesize);
2030 memset(info, 0, 4*infosize); 2030 memset(info, 0, 4*infosize);
2031 2031
@@ -2051,29 +2051,37 @@ DBG_LOG("Allocating 4 * %zu bytes\n", tablesize);
2051_static_inline uint8_t 2051_static_inline uint8_t
2052get_h48_pval(const uint32_t *buf32, int64_t index, uint8_t k) 2052get_h48_pval(const uint32_t *buf32, int64_t index, uint8_t k)
2053{ 2053{
2054 uint8_t mask, shift; 2054 uint32_t mask, shift;
2055 int64_t realindex, subindex;
2055 2056
2056 DBG_ASSERT(k == 1 || k == 2 || k == 4, 0, 2057 DBG_ASSERT(k == 1 || k == 2 || k == 4, 0,
2057 "h48 coordinate invalid k=%" PRIu8 "\n", k); 2058 "h48 coordinate invalid k=%" PRIu8 "\n", k);
2058 2059
2059 shift = (uint8_t)(k * index % (32 / k)); 2060 /* TODO: use more efficient operations, pass k as exponent */
2060 mask = (1U << k) - 1U; 2061 realindex = index / (32 / k);
2062 subindex = index % (32 / k);
2063 shift = (uint8_t)(k * subindex);
2064 mask = ((1U << k) - 1U) << shift;
2061 2065
2062 return (buf32[index] & (mask << shift)) >> shift; 2066 return (buf32[realindex] & mask) >> shift;
2063} 2067}
2064 2068
2065_static_inline void 2069_static_inline void
2066set_h48_pval(uint32_t *buf32, int64_t index, uint8_t k, uint8_t val) 2070set_h48_pval(uint32_t *buf32, int64_t index, uint8_t k, uint8_t val)
2067{ 2071{
2068 uint8_t mask, shift; 2072 uint32_t mask, shift;
2073 int64_t realindex, subindex;
2069 2074
2070 DBG_ASSERT(k == 1 || k == 2 || k == 4, , 2075 DBG_ASSERT(k == 1 || k == 2 || k == 4, ,
2071 "h48 coordinate invalid k=%" PRIu8 "\n", k); 2076 "h48 coordinate invalid k=%" PRIu8 "\n", k);
2072 2077
2073 shift = (uint8_t)(k * index % (32 / k)); 2078 /* TODO: use more efficient operations, pass k as exponent */
2074 mask = (1U << k) - 1U; 2079 realindex = index / (32 / k);
2080 subindex = index % (32 / k);
2081 shift = (uint8_t)(k * subindex);
2082 mask = ((1U << k) - 1U) << shift;
2075 2083
2076 buf32[index] = (buf32[index] & (~mask)) | (val << shift); 2084 buf32[realindex] = (buf32[realindex] & (~mask)) | (val << shift);
2077} 2085}
2078 2086
2079_static uint32_t 2087_static uint32_t
@@ -2090,13 +2098,14 @@ gendata_eoesep_dfs(dfsarg_gendata_t *arg)
2090 if (arg->nmoves > 0) 2098 if (arg->nmoves > 0)
2091 arg->cube = move(arg->cube, arg->moves[arg->nmoves-1]); 2099 arg->cube = move(arg->cube, arg->moves[arg->nmoves-1]);
2092 2100
2093 i = coord_fast_h48(arg->cube, arg->cocsepdata, arg->h); 2101 i = coord_h48(arg->cube, arg->cocsepdata, arg->h);
2094 olddepth = get_h48_pval(arg->buf32, i, arg->k); 2102 olddepth = get_h48_pval(arg->buf32, i, arg->k);
2103
2095 if (olddepth < arg->nmoves) 2104 if (olddepth < arg->nmoves)
2096 return 0; 2105 return 0;
2097 2106
2098 if (arg->nmoves == arg->depth) { 2107 if (arg->nmoves == arg->depth) {
2099 cc = olddepth == 0xFFU; 2108 cc = olddepth > arg->depth;
2100 set_h48_pval(arg->buf32, i, arg->k, arg->depth); 2109 set_h48_pval(arg->buf32, i, arg->k, arg->depth);
2101 return cc; 2110 return cc;
2102 } 2111 }

Generated with cgit - Back to sebastiano.tronto.net