aboutsummaryrefslogtreecommitdiff
path: root/src/arch/portable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/portable.h')
-rw-r--r--src/arch/portable.h80
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 12STATIC void
13pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) 13pieces(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 19STATIC_INLINE bool
20equal(cube_t c1, cube_t c2) 20equal(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 34STATIC_INLINE cube_t
35invertco(cube_t c) 35invertco(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 50STATIC_INLINE void
51compose_edges_inplace(cube_t c1, cube_t c2, cube_t *ret) 51compose_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 64STATIC_INLINE void
65compose_corners_inplace(cube_t c1, cube_t c2, cube_t *ret) 65compose_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 80STATIC_INLINE cube_t
81compose_edges(cube_t c1, cube_t c2) 81compose_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 90STATIC_INLINE cube_t
91compose_corners(cube_t c1, cube_t c2) 91compose_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 100STATIC_INLINE cube_t
101compose(cube_t c1, cube_t c2) 101compose(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 132STATIC_INLINE int64_t
133coord_co(cube_t c) 133coord_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
148possible. Encoding this as a number from 0 to C(8,4) would save about 40% 148possible. Encoding this as a number from 0 to C(8,4) would save about 40%
149of space, but we are not going to use this coordinate in large tables. 149of space, but we are not going to use this coordinate in large tables.
150*/ 150*/
151_static_inline int64_t 151STATIC_INLINE int64_t
152coord_csep(cube_t c) 152coord_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 163STATIC_INLINE int64_t
164coord_cocsep(cube_t c) 164coord_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 169STATIC_INLINE int64_t
170coord_eo(cube_t c) 170coord_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)
182We encode the edge separation as a number from 0 to C(12,4)*C(8,4). 182We encode the edge separation as a number from 0 to C(12,4)*C(8,4).
183It can be seen as the composition of two "subset index" coordinates. 183It can be seen as the composition of two "subset index" coordinates.
184*/ 184*/
185_static_inline int64_t 185STATIC_INLINE int64_t
186coord_esep(cube_t c) 186coord_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 217STATIC_INLINE void
218copy_corners(cube_t *dest, cube_t src) 218copy_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 223STATIC_INLINE void
224copy_edges(cube_t *dest, cube_t src) 224copy_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 229STATIC_INLINE void
230set_eo(cube_t *cube, int64_t eo) 230set_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 242STATIC_INLINE cube_t
243invcoord_esep(int64_t esep) 243invcoord_esep(int64_t esep)
244{ 244{
245 cube_t ret; 245 cube_t ret;

Generated with cgit - Back to sebastiano.tronto.net