diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-05 08:53:38 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-05 08:55:25 +0200 |
| commit | fd5ddb3db9f50411ca579d84f225f265ca35b56a (patch) | |
| tree | b659112cc0e2abd6c7edb08b0938c0d2de4ca066 /src/arch/portable.h | |
| parent | c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (diff) | |
| download | nissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.tar.gz nissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.zip | |
Rename constants from _underscore to CAPS
Diffstat (limited to '')
| -rw-r--r-- | src/arch/portable.h | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/src/arch/portable.h b/src/arch/portable.h index f6e5301..fdadb02 100644 --- a/src/arch/portable.h +++ b/src/arch/portable.h | |||
| @@ -9,14 +9,14 @@ | |||
| 9 | #define solved static_cube( \ | 9 | #define solved static_cube( \ |
| 10 | 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) | 10 | 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) |
| 11 | 11 | ||
| 12 | _static void | 12 | STATIC void |
| 13 | pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) | 13 | pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) |
| 14 | { | 14 | { |
| 15 | memcpy(c, cube->corner, 8); | 15 | memcpy(c, cube->corner, 8); |
| 16 | memcpy(e, cube->edge, 12); | 16 | memcpy(e, cube->edge, 12); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | _static_inline bool | 19 | STATIC_INLINE bool |
| 20 | equal(cube_t c1, cube_t c2) | 20 | equal(cube_t c1, cube_t c2) |
| 21 | { | 21 | { |
| 22 | uint8_t i; | 22 | uint8_t i; |
| @@ -31,7 +31,7 @@ equal(cube_t c1, cube_t c2) | |||
| 31 | return ret; | 31 | return ret; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | _static_inline cube_t | 34 | STATIC_INLINE cube_t |
| 35 | invertco(cube_t c) | 35 | invertco(cube_t c) |
| 36 | { | 36 | { |
| 37 | uint8_t i, piece, orien; | 37 | uint8_t i, piece, orien; |
| @@ -40,44 +40,44 @@ invertco(cube_t c) | |||
| 40 | ret = c; | 40 | ret = c; |
| 41 | for (i = 0; i < 8; i++) { | 41 | for (i = 0; i < 8; i++) { |
| 42 | piece = c.corner[i]; | 42 | piece = c.corner[i]; |
| 43 | orien = ((piece << 1) | (piece >> 1)) & _cobits2; | 43 | orien = ((piece << 1) | (piece >> 1)) & COBITS_2; |
| 44 | ret.corner[i] = (piece & _pbits) | orien; | 44 | ret.corner[i] = (piece & PBITS) | orien; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | return ret; | 47 | return ret; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | _static_inline void | 50 | STATIC_INLINE void |
| 51 | compose_edges_inplace(cube_t c1, cube_t c2, cube_t *ret) | 51 | compose_edges_inplace(cube_t c1, cube_t c2, cube_t *ret) |
| 52 | { | 52 | { |
| 53 | uint8_t i, piece1, piece2, p, orien; | 53 | uint8_t i, piece1, piece2, p, orien; |
| 54 | 54 | ||
| 55 | for (i = 0; i < 12; i++) { | 55 | for (i = 0; i < 12; i++) { |
| 56 | piece2 = c2.edge[i]; | 56 | piece2 = c2.edge[i]; |
| 57 | p = piece2 & _pbits; | 57 | p = piece2 & PBITS; |
| 58 | piece1 = c1.edge[p]; | 58 | piece1 = c1.edge[p]; |
| 59 | orien = (piece2 ^ piece1) & _eobit; | 59 | orien = (piece2 ^ piece1) & EOBIT; |
| 60 | ret->edge[i] = (piece1 & _pbits) | orien; | 60 | ret->edge[i] = (piece1 & PBITS) | orien; |
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | _static_inline void | 64 | STATIC_INLINE void |
| 65 | compose_corners_inplace(cube_t c1, cube_t c2, cube_t *ret) | 65 | compose_corners_inplace(cube_t c1, cube_t c2, cube_t *ret) |
| 66 | { | 66 | { |
| 67 | uint8_t i, piece1, piece2, p, orien, aux, auy; | 67 | uint8_t i, piece1, piece2, p, orien, aux, auy; |
| 68 | 68 | ||
| 69 | for (i = 0; i < 8; i++) { | 69 | for (i = 0; i < 8; i++) { |
| 70 | piece2 = c2.corner[i]; | 70 | piece2 = c2.corner[i]; |
| 71 | p = piece2 & _pbits; | 71 | p = piece2 & PBITS; |
| 72 | piece1 = c1.corner[p]; | 72 | piece1 = c1.corner[p]; |
| 73 | aux = (piece2 & _cobits) + (piece1 & _cobits); | 73 | aux = (piece2 & COBITS) + (piece1 & COBITS); |
| 74 | auy = (aux + _ctwist_cw) >> 2; | 74 | auy = (aux + CTWIST_CW) >> 2; |
| 75 | orien = (aux + auy) & _cobits2; | 75 | orien = (aux + auy) & COBITS_2; |
| 76 | ret->corner[i] = (piece1 & _pbits) | orien; | 76 | ret->corner[i] = (piece1 & PBITS) | orien; |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | _static_inline cube_t | 80 | STATIC_INLINE cube_t |
| 81 | compose_edges(cube_t c1, cube_t c2) | 81 | compose_edges(cube_t c1, cube_t c2) |
| 82 | { | 82 | { |
| 83 | cube_t ret = zero; | 83 | cube_t ret = zero; |
| @@ -87,7 +87,7 @@ compose_edges(cube_t c1, cube_t c2) | |||
| 87 | return ret; | 87 | return ret; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | _static_inline cube_t | 90 | STATIC_INLINE cube_t |
| 91 | compose_corners(cube_t c1, cube_t c2) | 91 | compose_corners(cube_t c1, cube_t c2) |
| 92 | { | 92 | { |
| 93 | cube_t ret = zero; | 93 | cube_t ret = zero; |
| @@ -97,7 +97,7 @@ compose_corners(cube_t c1, cube_t c2) | |||
| 97 | return ret; | 97 | return ret; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | _static_inline cube_t | 100 | STATIC_INLINE cube_t |
| 101 | compose(cube_t c1, cube_t c2) | 101 | compose(cube_t c1, cube_t c2) |
| 102 | { | 102 | { |
| 103 | cube_t ret = zero; | 103 | cube_t ret = zero; |
| @@ -116,27 +116,27 @@ inverse(cube_t cube) | |||
| 116 | 116 | ||
| 117 | for (i = 0; i < 12; i++) { | 117 | for (i = 0; i < 12; i++) { |
| 118 | piece = cube.edge[i]; | 118 | piece = cube.edge[i]; |
| 119 | orien = piece & _eobit; | 119 | orien = piece & EOBIT; |
| 120 | ret.edge[piece & _pbits] = i | orien; | 120 | ret.edge[piece & PBITS] = i | orien; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | for (i = 0; i < 8; i++) { | 123 | for (i = 0; i < 8; i++) { |
| 124 | piece = cube.corner[i]; | 124 | piece = cube.corner[i]; |
| 125 | orien = ((piece << 1) | (piece >> 1)) & _cobits2; | 125 | orien = ((piece << 1) | (piece >> 1)) & COBITS_2; |
| 126 | ret.corner[piece & _pbits] = i | orien; | 126 | ret.corner[piece & PBITS] = i | orien; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | return ret; | 129 | return ret; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | _static_inline int64_t | 132 | STATIC_INLINE int64_t |
| 133 | coord_co(cube_t c) | 133 | coord_co(cube_t c) |
| 134 | { | 134 | { |
| 135 | int i, p; | 135 | int i, p; |
| 136 | int64_t ret; | 136 | int64_t ret; |
| 137 | 137 | ||
| 138 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) | 138 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) |
| 139 | ret += p * (c.corner[i] >> _coshift); | 139 | ret += p * (c.corner[i] >> COSHIFT); |
| 140 | 140 | ||
| 141 | return ret; | 141 | return ret; |
| 142 | } | 142 | } |
| @@ -148,32 +148,32 @@ Ignoring the last bit, we have a value up to 2^7, but not all values are | |||
| 148 | possible. Encoding this as a number from 0 to C(8,4) would save about 40% | 148 | possible. Encoding this as a number from 0 to C(8,4) would save about 40% |
| 149 | of space, but we are not going to use this coordinate in large tables. | 149 | of space, but we are not going to use this coordinate in large tables. |
| 150 | */ | 150 | */ |
| 151 | _static_inline int64_t | 151 | STATIC_INLINE int64_t |
| 152 | coord_csep(cube_t c) | 152 | coord_csep(cube_t c) |
| 153 | { | 153 | { |
| 154 | int i, p; | 154 | int i, p; |
| 155 | int64_t ret; | 155 | int64_t ret; |
| 156 | 156 | ||
| 157 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 2) | 157 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 2) |
| 158 | ret += p * ((c.corner[i] & _csepbit) >> 2); | 158 | ret += p * ((c.corner[i] & CSEPBIT) >> 2); |
| 159 | 159 | ||
| 160 | return ret; | 160 | return ret; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | _static_inline int64_t | 163 | STATIC_INLINE int64_t |
| 164 | coord_cocsep(cube_t c) | 164 | coord_cocsep(cube_t c) |
| 165 | { | 165 | { |
| 166 | return (coord_co(c) << 7) + coord_csep(c); | 166 | return (coord_co(c) << 7) + coord_csep(c); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | _static_inline int64_t | 169 | STATIC_INLINE int64_t |
| 170 | coord_eo(cube_t c) | 170 | coord_eo(cube_t c) |
| 171 | { | 171 | { |
| 172 | int i, p; | 172 | int i, p; |
| 173 | int64_t ret; | 173 | int64_t ret; |
| 174 | 174 | ||
| 175 | for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) | 175 | for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) |
| 176 | ret += p * (c.edge[i] >> _eoshift); | 176 | ret += p * (c.edge[i] >> EOSHIFT); |
| 177 | 177 | ||
| 178 | return ret; | 178 | return ret; |
| 179 | } | 179 | } |
| @@ -182,24 +182,24 @@ coord_eo(cube_t c) | |||
| 182 | We encode the edge separation as a number from 0 to C(12,4)*C(8,4). | 182 | We encode the edge separation as a number from 0 to C(12,4)*C(8,4). |
| 183 | It can be seen as the composition of two "subset index" coordinates. | 183 | It can be seen as the composition of two "subset index" coordinates. |
| 184 | */ | 184 | */ |
| 185 | _static_inline int64_t | 185 | STATIC_INLINE int64_t |
| 186 | coord_esep(cube_t c) | 186 | coord_esep(cube_t c) |
| 187 | { | 187 | { |
| 188 | int64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; | 188 | int64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; |
| 189 | 189 | ||
| 190 | for (i = 0, j = 0, k = 4, l = 4, ret1 = 0, ret2 = 0; i < 12; i++) { | 190 | for (i = 0, j = 0, k = 4, l = 4, ret1 = 0, ret2 = 0; i < 12; i++) { |
| 191 | /* Simple version: | 191 | /* Simple version: |
| 192 | if (c.edge[i] & _esepbit2) { | 192 | if (c.edge[i] & ESEPBIT_2) { |
| 193 | ret1 += binomial[11-i][k--]; | 193 | ret1 += binomial[11-i][k--]; |
| 194 | } else { | 194 | } else { |
| 195 | if (c.edge[i] & _esepbit1) | 195 | if (c.edge[i] & ESEPBIT_1) |
| 196 | ret2 += binomial[7-j][l--]; | 196 | ret2 += binomial[7-j][l--]; |
| 197 | j++; | 197 | j++; |
| 198 | } | 198 | } |
| 199 | */ | 199 | */ |
| 200 | 200 | ||
| 201 | bit1 = (c.edge[i] & _esepbit1) >> 2; | 201 | bit1 = (c.edge[i] & ESEPBIT_1) >> 2; |
| 202 | bit2 = (c.edge[i] & _esepbit2) >> 3; | 202 | bit2 = (c.edge[i] & ESEPBIT_2) >> 3; |
| 203 | is1 = (1 - bit2) * bit1; | 203 | is1 = (1 - bit2) * bit1; |
| 204 | 204 | ||
| 205 | ret1 += bit2 * binomial[11-i][k]; | 205 | ret1 += bit2 * binomial[11-i][k]; |
| @@ -214,19 +214,19 @@ coord_esep(cube_t c) | |||
| 214 | return ret1 * 70 + ret2; | 214 | return ret1 * 70 + ret2; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | _static_inline void | 217 | STATIC_INLINE void |
| 218 | copy_corners(cube_t *dest, cube_t src) | 218 | copy_corners(cube_t *dest, cube_t src) |
| 219 | { | 219 | { |
| 220 | memcpy(&dest->corner, src.corner, sizeof(src.corner)); | 220 | memcpy(&dest->corner, src.corner, sizeof(src.corner)); |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | _static_inline void | 223 | STATIC_INLINE void |
| 224 | copy_edges(cube_t *dest, cube_t src) | 224 | copy_edges(cube_t *dest, cube_t src) |
| 225 | { | 225 | { |
| 226 | memcpy(&dest->edge, src.edge, sizeof(src.edge)); | 226 | memcpy(&dest->edge, src.edge, sizeof(src.edge)); |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | _static_inline void | 229 | STATIC_INLINE void |
| 230 | set_eo(cube_t *cube, int64_t eo) | 230 | set_eo(cube_t *cube, int64_t eo) |
| 231 | { | 231 | { |
| 232 | uint8_t i, sum, flip; | 232 | uint8_t i, sum, flip; |
| @@ -234,12 +234,12 @@ set_eo(cube_t *cube, int64_t eo) | |||
| 234 | for (sum = 0, i = 1; i < 12; i++, eo >>= 1) { | 234 | for (sum = 0, i = 1; i < 12; i++, eo >>= 1) { |
| 235 | flip = eo % 2; | 235 | flip = eo % 2; |
| 236 | sum += flip; | 236 | sum += flip; |
| 237 | cube->edge[i] = (cube->edge[i] & ~_eobit) | (_eobit * flip); | 237 | cube->edge[i] = (cube->edge[i] & ~EOBIT) | (EOBIT * flip); |
| 238 | } | 238 | } |
| 239 | cube->edge[0] = (cube->edge[0] & ~_eobit) | (_eobit * (sum % 2)); | 239 | cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | _static_inline cube_t | 242 | STATIC_INLINE cube_t |
| 243 | invcoord_esep(int64_t esep) | 243 | invcoord_esep(int64_t esep) |
| 244 | { | 244 | { |
| 245 | cube_t ret; | 245 | cube_t ret; |
