aboutsummaryrefslogtreecommitdiff
path: root/src/fst.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fst.c')
-rw-r--r--src/fst.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/src/fst.c b/src/fst.c
index aa9e41e..df5b81f 100644
--- a/src/fst.c
+++ b/src/fst.c
@@ -3,7 +3,6 @@
3#include "fst.h" 3#include "fst.h"
4 4
5static FstCube ep_to_fst_epos(int *ep); 5static FstCube ep_to_fst_epos(int *ep);
6static int fst_where_is_edge(int e, FstCube fst);
7static void transform_ep_only(Trans t, int *ep, Cube *dst); 6static void transform_ep_only(Trans t, int *ep, Cube *dst);
8static void init_fst_corner_invtables(); 7static void init_fst_corner_invtables();
9static void init_fst_eo_invtables(); 8static void init_fst_eo_invtables();
@@ -55,7 +54,10 @@ cube_to_fst(Cube *cube)
55static FstCube 54static FstCube
56ep_to_fst_epos(int *ep) 55ep_to_fst_epos(int *ep)
57{ 56{
58 /* TODO: maybe optimize? */ 57 /* TODO: maybe optimize */
58
59/* TODO: this version if faster, but broken
60 probably need to fix transform_ep_only()
59 61
60 FstCube ret; 62 FstCube ret;
61 Cube c; 63 Cube c;
@@ -68,6 +70,24 @@ ep_to_fst_epos(int *ep)
68 70
69 transform_ep_only(rd, ep, &c); 71 transform_ep_only(rd, ep, &c);
70 ret.rd_eposepe = coord_eposepe.i[0]->index(&c); 72 ret.rd_eposepe = coord_eposepe.i[0]->index(&c);
73*/
74
75 FstCube ret;
76 Cube c, d;
77
78 make_solved(&c);
79 memcpy(c.ep, ep, 12 * sizeof(int));
80
81 copy_cube(&c, &d);
82 ret.uf_eposepe = coord_eposepe.i[0]->index(&d);
83
84 copy_cube(&c, &d);
85 apply_trans(fr, &d);
86 ret.fr_eposepe = coord_eposepe.i[0]->index(&d);
87
88 copy_cube(&c, &d);
89 apply_trans(rd, &d);
90 ret.rd_eposepe = coord_eposepe.i[0]->index(&d);
71 91
72 return ret; 92 return ret;
73} 93}
@@ -155,7 +175,7 @@ fst_to_cube(FstCube fst, Cube *cube)
155 cube->xp[i] = i; 175 cube->xp[i] = i;
156} 176}
157 177
158static int 178int
159fst_where_is_edge(int e, FstCube fst) 179fst_where_is_edge(int e, FstCube fst)
160{ 180{
161 switch (edge_slice[e]) { 181 switch (edge_slice[e]) {
@@ -183,6 +203,10 @@ void
183init_fst() 203init_fst()
184{ 204{
185 init_trans(); 205 init_trans();
206 gen_coord(&coord_eofb);
207 gen_coord(&coord_eposepe);
208 gen_coord(&coord_coud);
209 gen_coord(&coord_cp);
186 210
187 init_fst_corner_invtables(); 211 init_fst_corner_invtables();
188 init_fst_eo_invtables(); 212 init_fst_eo_invtables();
@@ -193,32 +217,29 @@ init_fst()
193static void 217static void
194init_fst_corner_invtables() 218init_fst_corner_invtables()
195{ 219{
196/* TODO: this can be optimized by transforming and copying only corners */
197/* A factor of about 4 would be saved in the innermost loop */
198
199 Cube c, d; 220 Cube c, d;
200 uint64_t cp, coud; 221 uint64_t cp, coud;
201 222
202 for (cp = 0; cp < FACTORIAL8; cp++) { 223 for (cp = 0; cp < FACTORIAL8; cp++) {
203 make_solved(&c); 224 make_solved_corners(&c);
204 coord_cp.i[0]->to_cube(cp, &c); 225 coord_cp.i[0]->to_cube(cp, &c);
205 226
206 copy_cube(&c, &d); 227 copy_cube_corners(&c, &d);
207 invert_cube(&d); 228 invert_cube_corners(&d);
208 inv_cp[cp] = coord_coud.i[0]->index(&d); 229 inv_cp[cp] = coord_cp.i[0]->index(&d);
209 230
210 for (coud = 0; coud < POW3TO7; coud++) { 231 for (coud = 0; coud < POW3TO7; coud++) {
211 copy_cube(&c, &d); 232 copy_cube_corners(&c, &d);
212 coord_coud.i[0]->to_cube(coud, &d); 233 coord_coud.i[0]->to_cube(coud, &d);
213 invert_cube(&d); 234 invert_cube_corners(&d);
214 inv_coud[cp][coud] = coord_coud.i[0]->index(&d); 235 inv_coud[cp][coud] = coord_coud.i[0]->index(&d);
215 } 236 }
216 237
217 copy_cube(&c, &d); 238 copy_cube_corners(&c, &d);
218 apply_trans(fr, &d); 239 apply_trans(fr, &d);
219 uf_cp_to_fr_cp[cp] = coord_cp.i[0]->index(&d); 240 uf_cp_to_fr_cp[cp] = coord_cp.i[0]->index(&d);
220 241
221 copy_cube(&c, &d); 242 copy_cube_corners(&c, &d);
222 apply_trans(rd, &d); 243 apply_trans(rd, &d);
223 uf_cp_to_rd_cp[cp] = coord_cp.i[0]->index(&d); 244 uf_cp_to_rd_cp[cp] = coord_cp.i[0]->index(&d);
224 } 245 }
@@ -234,13 +255,17 @@ init_fst_eo_invtables()
234 make_solved(&c); 255 make_solved(&c);
235 coord_eposepe.i[0]->to_cube(ep, &c); 256 coord_eposepe.i[0]->to_cube(ep, &c);
236 for (eo = 0; eo < POW2TO11; eo++) { 257 for (eo = 0; eo < POW2TO11; eo++) {
237 coord_eofb.i[0]->to_cube(eo, &c); 258 copy_cube_edges(&c, &d);
238 copy_cube(&c, &d); 259 coord_eofb.i[0]->to_cube(eo, &d);
239 init_fst_eo_update(eo, ep, 0, &d); 260 init_fst_eo_update(eo, ep, 0, &d);
261
240 apply_trans(inverse_trans(fr), &d); 262 apply_trans(inverse_trans(fr), &d);
263 coord_eofb.i[0]->to_cube(eo, &d);
241 init_fst_eo_update(eo, ep, 1, &d); 264 init_fst_eo_update(eo, ep, 1, &d);
242 copy_cube(&c, &d); 265
266 copy_cube_edges(&c, &d);
243 apply_trans(inverse_trans(rd), &d); 267 apply_trans(inverse_trans(rd), &d);
268 coord_eofb.i[0]->to_cube(eo, &d);
244 init_fst_eo_update(eo, ep, 2, &d); 269 init_fst_eo_update(eo, ep, 2, &d);
245 } 270 }
246 } 271 }
@@ -251,9 +276,11 @@ init_fst_eo_update(uint64_t eo, uint64_t ep, int s, Cube *d)
251{ 276{
252 int i; 277 int i;
253 278
254 for (i = 0; i < 12; i++) 279 for (i = 0; i < 12; i++) {
255 if (d->eo[i]) 280 if (edge_slice[d->ep[i]] == s && d->eo[i] && d->ep[i] != 11)
256 eo_invtable[s][eo][ep] |= ((uint16_t)1) << d->ep[i]; 281 eo_invtable[s][eo][ep] |=
282 ((uint16_t)1) << ((uint16_t)d->ep[i]);
283 }
257} 284}
258 285
259static void 286static void
@@ -270,7 +297,7 @@ init_fst_transalg()
270 apply_alg(alg, &c); 297 apply_alg(alg, &c);
271 for (i = 0; i < 12; i++) 298 for (i = 0; i < 12; i++)
272 trans_ep_alg[t][i] = c.ep[i]; 299 trans_ep_alg[t][i] = c.ep[i];
273 invert_cube(&c); 300 invert_cube_edges(&c);
274 for (i = 0; i < 12; i++) 301 for (i = 0; i < 12; i++)
275 trans_ep_inv[t][i] = c.ep[i]; 302 trans_ep_inv[t][i] = c.ep[i];
276 } 303 }
@@ -286,20 +313,20 @@ init_fst_where_is_edge()
286 for (e = 0; e < BINOM12ON4 * FACTORIAL4; e++) { 313 for (e = 0; e < BINOM12ON4 * FACTORIAL4; e++) {
287 coord_eposepe.i[0]->to_cube(e, &c); 314 coord_eposepe.i[0]->to_cube(e, &c);
288 315
289 copy_cube(&c, &d); 316 copy_cube_edges(&c, &d);
290 fst_where_is_edge_arr[0][FR][e] = where_is_edge(FR, &d); 317 fst_where_is_edge_arr[0][FR][e] = where_is_edge(FR, &d);
291 fst_where_is_edge_arr[0][FL][e] = where_is_edge(FL, &d); 318 fst_where_is_edge_arr[0][FL][e] = where_is_edge(FL, &d);
292 fst_where_is_edge_arr[0][BL][e] = where_is_edge(BL, &d); 319 fst_where_is_edge_arr[0][BL][e] = where_is_edge(BL, &d);
293 fst_where_is_edge_arr[0][BR][e] = where_is_edge(BR, &d); 320 fst_where_is_edge_arr[0][BR][e] = where_is_edge(BR, &d);
294 321
295 copy_cube(&c, &d); 322 copy_cube_edges(&c, &d);
296 apply_trans(inverse_trans(fr), &d); 323 apply_trans(inverse_trans(fr), &d);
297 fst_where_is_edge_arr[1][UL][e] = where_is_edge(UL, &d); 324 fst_where_is_edge_arr[1][UL][e] = where_is_edge(UL, &d);
298 fst_where_is_edge_arr[1][UR][e] = where_is_edge(UR, &d); 325 fst_where_is_edge_arr[1][UR][e] = where_is_edge(UR, &d);
299 fst_where_is_edge_arr[1][DL][e] = where_is_edge(DL, &d); 326 fst_where_is_edge_arr[1][DL][e] = where_is_edge(DL, &d);
300 fst_where_is_edge_arr[1][DR][e] = where_is_edge(DR, &d); 327 fst_where_is_edge_arr[1][DR][e] = where_is_edge(DR, &d);
301 328
302 copy_cube(&c, &d); 329 copy_cube_edges(&c, &d);
303 apply_trans(inverse_trans(rd), &d); 330 apply_trans(inverse_trans(rd), &d);
304 fst_where_is_edge_arr[2][UF][e] = where_is_edge(UF, &d); 331 fst_where_is_edge_arr[2][UF][e] = where_is_edge(UF, &d);
305 fst_where_is_edge_arr[2][UB][e] = where_is_edge(UB, &d); 332 fst_where_is_edge_arr[2][UB][e] = where_is_edge(UB, &d);

Generated with cgit - Back to sebastiano.tronto.net