From 80b065f757240af7920862b3e09f32a6dc06d392 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 4 Oct 2024 12:01:41 +0200 Subject: Table-based transformations (will revert immediately) This commit changes transformations to being based on a lookup table intead of a big switch. This is something I had planned for a long time and the code is nicer with this change. But unfortunately the performance is noticeably worse, so I'll revert all these changes in the next commit. I wanted to push this anyway so we can keep track of this. --- src/arch/portable.h | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'src/arch/portable.h') diff --git a/src/arch/portable.h b/src/arch/portable.h index e9a8dd0..3776c90 100644 --- a/src/arch/portable.h +++ b/src/arch/portable.h @@ -1,14 +1,3 @@ -#define STATIC_CUBE(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ - e_uf, e_ub, e_db, e_df, e_ur, e_ul, e_dl, e_dr, e_fr, e_fl, e_bl, e_br) \ - ((cube_t) { \ - .corner = { c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl }, \ - .edge = { e_uf, e_ub, e_db, e_df, e_ur, e_ul, \ - e_dl, e_dr, e_fr, e_fl, e_bl, e_br } }) -#define ZERO_CUBE STATIC_CUBE( \ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) -#define SOLVED_CUBE STATIC_CUBE( \ - 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) - STATIC void pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) { @@ -16,6 +5,44 @@ pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) memcpy(e, cube->edge, 12); } +STATIC_INLINE cube_t +cubefrompieces( + uint8_t c_ufr, + uint8_t c_ubl, + uint8_t c_dfl, + uint8_t c_dbr, + uint8_t c_ufl, + uint8_t c_ubr, + uint8_t c_dfr, + uint8_t c_dbl, + + uint8_t e_uf, + uint8_t e_ub, + uint8_t e_db, + uint8_t e_df, + uint8_t e_ur, + uint8_t e_ul, + uint8_t e_dl, + uint8_t e_dr, + uint8_t e_fr, + uint8_t e_fl, + uint8_t e_bl, + uint8_t e_br +) { + cube_t ret = { + .corner = { + 0, 0, 0, 0, 0, 0, 0, 0, + c_dbl, c_dfr, c_ubr, c_ufl, c_dbr, c_dfl, c_ubl, c_ufr + }, + .edge = { + 0, 0, 0, 0, e_br, e_bl, e_fl, e_fr, + e_dr, e_dl, e_ul, e_ur, e_df, e_db, e_ub, e_uf + } + }; + + return ret; +} + STATIC_INLINE bool equal(cube_t c1, cube_t c2) { -- cgit v1.3