diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-26 19:22:50 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-26 19:22:50 +0100 |
| commit | 83338a2f753ebbb7ba7b154cc60b2f427b6121b0 (patch) | |
| tree | 149efb6a0b835fd6b3d89f7fd7808f8eed8e0288 /src/arch | |
| parent | 56048d13b73ec6e6a9c59d62e82f41e69a3994bd (diff) | |
| download | nissy-core-83338a2f753ebbb7ba7b154cc60b2f427b6121b0.tar.gz nissy-core-83338a2f753ebbb7ba7b154cc60b2f427b6121b0.zip | |
Added inverse coordinate for CO
this is necessary for DR coordinate
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/avx2.h | 49 | ||||
| -rw-r--r-- | src/arch/common.h | 3 | ||||
| -rw-r--r-- | src/arch/neon.h | 19 | ||||
| -rw-r--r-- | src/arch/portable.h | 42 |
4 files changed, 84 insertions, 29 deletions
diff --git a/src/arch/avx2.h b/src/arch/avx2.h index ebcf84f..4682e33 100644 --- a/src/arch/avx2.h +++ b/src/arch/avx2.h | |||
| @@ -188,6 +188,25 @@ coord_co(cube_t c) | |||
| 188 | return ret; | 188 | return ret; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | STATIC_INLINE cube_t | ||
| 192 | invcoord_co(int64_t coord) | ||
| 193 | { | ||
| 194 | int64_t i, c, p, co, mem[4] = {0}; | ||
| 195 | cube_t cube, cc; | ||
| 196 | |||
| 197 | for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { | ||
| 198 | co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); | ||
| 199 | p += co; | ||
| 200 | mem[0] |= (int64_t)(i + (co << COSHIFT)) << (int64_t)(8 * i); | ||
| 201 | } | ||
| 202 | |||
| 203 | cc = _mm256_loadu_si256((const __m256i *)mem); | ||
| 204 | cube = SOLVED_CUBE; | ||
| 205 | copy_corners(&cube, cc); | ||
| 206 | |||
| 207 | return cube; | ||
| 208 | } | ||
| 209 | |||
| 191 | STATIC_INLINE int64_t | 210 | STATIC_INLINE int64_t |
| 192 | coord_csep(cube_t c) | 211 | coord_csep(cube_t c) |
| 193 | { | 212 | { |
| @@ -251,6 +270,21 @@ coord_esep(cube_t c) | |||
| 251 | return ret1 * 70 + ret2; | 270 | return ret1 * 70 + ret2; |
| 252 | } | 271 | } |
| 253 | 272 | ||
| 273 | STATIC_INLINE cube_t | ||
| 274 | invcoord_esep(int64_t esep) | ||
| 275 | { | ||
| 276 | cube_t eee, ret; | ||
| 277 | uint8_t mem[32] = {0}; | ||
| 278 | |||
| 279 | invcoord_esep_array(esep % 70, esep / 70, mem+16); | ||
| 280 | |||
| 281 | ret = SOLVED_CUBE; | ||
| 282 | eee = _mm256_loadu_si256((__m256i_u *)&mem); | ||
| 283 | copy_edges(&ret, eee); | ||
| 284 | |||
| 285 | return ret; | ||
| 286 | } | ||
| 287 | |||
| 254 | STATIC_INLINE void | 288 | STATIC_INLINE void |
| 255 | copy_corners(cube_t dest[static 1], cube_t src) | 289 | copy_corners(cube_t dest[static 1], cube_t src) |
| 256 | { | 290 | { |
| @@ -287,18 +321,3 @@ set_eo(cube_t cube[static 1], int64_t eo) | |||
| 287 | *cube = _mm256_andnot_si256(EO_AVX2, *cube); | 321 | *cube = _mm256_andnot_si256(EO_AVX2, *cube); |
| 288 | *cube = _mm256_or_si256(*cube, veo); | 322 | *cube = _mm256_or_si256(*cube, veo); |
| 289 | } | 323 | } |
| 290 | |||
| 291 | STATIC_INLINE cube_t | ||
| 292 | invcoord_esep(int64_t esep) | ||
| 293 | { | ||
| 294 | cube_t eee, ret; | ||
| 295 | uint8_t mem[32] = {0}; | ||
| 296 | |||
| 297 | invcoord_esep_array(esep % 70, esep / 70, mem+16); | ||
| 298 | |||
| 299 | ret = SOLVED_CUBE; | ||
| 300 | eee = _mm256_loadu_si256((__m256i_u *)&mem); | ||
| 301 | copy_edges(&ret, eee); | ||
| 302 | |||
| 303 | return ret; | ||
| 304 | } | ||
diff --git a/src/arch/common.h b/src/arch/common.h index 5c1efde..e57fba9 100644 --- a/src/arch/common.h +++ b/src/arch/common.h | |||
| @@ -9,15 +9,16 @@ STATIC_INLINE cube_t compose(cube_t, cube_t); | |||
| 9 | STATIC_INLINE cube_t inverse(cube_t); | 9 | STATIC_INLINE cube_t inverse(cube_t); |
| 10 | 10 | ||
| 11 | STATIC_INLINE int64_t coord_co(cube_t); | 11 | STATIC_INLINE int64_t coord_co(cube_t); |
| 12 | STATIC_INLINE cube_t invcoord_co(int64_t); | ||
| 12 | STATIC_INLINE int64_t coord_csep(cube_t); | 13 | STATIC_INLINE int64_t coord_csep(cube_t); |
| 13 | STATIC_INLINE int64_t coord_cocsep(cube_t); | 14 | STATIC_INLINE int64_t coord_cocsep(cube_t); |
| 14 | STATIC_INLINE int64_t coord_eo(cube_t); | 15 | STATIC_INLINE int64_t coord_eo(cube_t); |
| 15 | STATIC_INLINE int64_t coord_esep(cube_t); | 16 | STATIC_INLINE int64_t coord_esep(cube_t); |
| 17 | STATIC_INLINE cube_t invcoord_esep(int64_t); | ||
| 16 | 18 | ||
| 17 | STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); | 19 | STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); |
| 18 | STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); | 20 | STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); |
| 19 | STATIC_INLINE void set_eo(cube_t [static 1], int64_t); | 21 | STATIC_INLINE void set_eo(cube_t [static 1], int64_t); |
| 20 | STATIC_INLINE cube_t invcoord_esep(int64_t); | ||
| 21 | 22 | ||
| 22 | STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); | 23 | STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); |
| 23 | STATIC_INLINE cube_t invcoord_eoesep(int64_t); | 24 | STATIC_INLINE cube_t invcoord_eoesep(int64_t); |
diff --git a/src/arch/neon.h b/src/arch/neon.h index d5f5f8b..fc0e612 100644 --- a/src/arch/neon.h +++ b/src/arch/neon.h | |||
| @@ -219,6 +219,25 @@ coord_co(cube_t c) | |||
| 219 | return ret; | 219 | return ret; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | STATIC_INLINE cube_t | ||
| 223 | invcoord_co(int64_t coord) | ||
| 224 | { | ||
| 225 | int64_t co, c, i, p; | ||
| 226 | uint8_t mem[8]; | ||
| 227 | cube_t cube; | ||
| 228 | |||
| 229 | for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { | ||
| 230 | co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); | ||
| 231 | p += co; | ||
| 232 | mem[i] = i + (co << COSHIFT); | ||
| 233 | } | ||
| 234 | |||
| 235 | cube.corner = vld1_u8(mem); | ||
| 236 | cube.edge = SOLVED_CUBE.edge; | ||
| 237 | |||
| 238 | return cube; | ||
| 239 | } | ||
| 240 | |||
| 222 | STATIC_INLINE int64_t | 241 | STATIC_INLINE int64_t |
| 223 | coord_csep(cube_t c) | 242 | coord_csep(cube_t c) |
| 224 | { | 243 | { |
diff --git a/src/arch/portable.h b/src/arch/portable.h index 4ac5fe7..56d3074 100644 --- a/src/arch/portable.h +++ b/src/arch/portable.h | |||
| @@ -144,8 +144,7 @@ inverse(cube_t cube) | |||
| 144 | STATIC_INLINE int64_t | 144 | STATIC_INLINE int64_t |
| 145 | coord_co(cube_t c) | 145 | coord_co(cube_t c) |
| 146 | { | 146 | { |
| 147 | int i, p; | 147 | int i, p, ret; |
| 148 | int64_t ret; | ||
| 149 | 148 | ||
| 150 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) | 149 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) |
| 151 | ret += p * (c.corner[i] >> COSHIFT); | 150 | ret += p * (c.corner[i] >> COSHIFT); |
| @@ -153,6 +152,23 @@ coord_co(cube_t c) | |||
| 153 | return ret; | 152 | return ret; |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 155 | STATIC_INLINE cube_t | ||
| 156 | invcoord_co(int64_t coord) | ||
| 157 | { | ||
| 158 | int64_t i, c, p; | ||
| 159 | cube_t cube; | ||
| 160 | |||
| 161 | cube = SOLVED_CUBE; | ||
| 162 | for (i = 0, p = 0, c = coord; i < 7; i++, c /= 3) { | ||
| 163 | p += c % 3; | ||
| 164 | cube.corner[i] |= (c % 3) << COSHIFT; | ||
| 165 | } | ||
| 166 | |||
| 167 | cube.corner[7] |= ((3 - (p % 3)) % 3) << COSHIFT; | ||
| 168 | |||
| 169 | return cube; | ||
| 170 | } | ||
| 171 | |||
| 156 | /* | 172 | /* |
| 157 | For corner separation, we consider the axis (a.k.a. tetrad) each | 173 | For corner separation, we consider the axis (a.k.a. tetrad) each |
| 158 | corner belongs to as 0 or 1 and we translate this sequence into binary. | 174 | corner belongs to as 0 or 1 and we translate this sequence into binary. |
| @@ -226,6 +242,17 @@ coord_esep(cube_t c) | |||
| 226 | return ret1 * 70 + ret2; | 242 | return ret1 * 70 + ret2; |
| 227 | } | 243 | } |
| 228 | 244 | ||
| 245 | STATIC_INLINE cube_t | ||
| 246 | invcoord_esep(int64_t esep) | ||
| 247 | { | ||
| 248 | cube_t ret; | ||
| 249 | |||
| 250 | ret = SOLVED_CUBE; | ||
| 251 | invcoord_esep_array(esep % 70, esep / 70, ret.edge); | ||
| 252 | |||
| 253 | return ret; | ||
| 254 | } | ||
| 255 | |||
| 229 | STATIC_INLINE void | 256 | STATIC_INLINE void |
| 230 | copy_corners(cube_t dest[static 1], cube_t src) | 257 | copy_corners(cube_t dest[static 1], cube_t src) |
| 231 | { | 258 | { |
| @@ -250,14 +277,3 @@ set_eo(cube_t cube[static 1], int64_t eo) | |||
| 250 | } | 277 | } |
| 251 | cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); | 278 | cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); |
| 252 | } | 279 | } |
| 253 | |||
| 254 | STATIC_INLINE cube_t | ||
| 255 | invcoord_esep(int64_t esep) | ||
| 256 | { | ||
| 257 | cube_t ret; | ||
| 258 | |||
| 259 | ret = SOLVED_CUBE; | ||
| 260 | invcoord_esep_array(esep % 70, esep / 70, ret.edge); | ||
| 261 | |||
| 262 | return ret; | ||
| 263 | } | ||
