diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-04-20 10:49:27 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-04-20 10:49:27 +0200 |
| commit | 9ed96a1ea3fc742791a8774267d5c7d5b604ce79 (patch) | |
| tree | 4d045aff3c65474ad9a89d3d26299ab65a396b66 /cube.c | |
| parent | 81708be1d1784f41343530e8e01a68094bc50da6 (diff) | |
| download | nissy-core-9ed96a1ea3fc742791a8774267d5c7d5b604ce79.tar.gz nissy-core-9ed96a1ea3fc742791a8774267d5c7d5b604ce79.zip | |
Fixed edge pruning table, but it is slooooow
Diffstat (limited to '')
| -rw-r--r-- | cube.c | 43 |
1 files changed, 26 insertions, 17 deletions
| @@ -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 | ||
| 1101 | cube_t | 1101 | cube_t |
| 1102 | solvedcube(void) | 1102 | solvedcube(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 |
| 1806 | coord_fast_h48(cube_fast_t c, uint32_t *cocsepdata, uint8_t h) | 1806 | coord_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; |
| 2028 | DBG_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 |
| 2052 | get_h48_pval(const uint32_t *buf32, int64_t index, uint8_t k) | 2052 | get_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 |
| 2066 | set_h48_pval(uint32_t *buf32, int64_t index, uint8_t k, uint8_t val) | 2070 | set_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 | } |
