common.h (3277B)
1 #define EOSHIFT UINT8_C(4) 2 #define COSHIFT UINT8_C(5) 3 4 #define PBITS UINT8_C(0xF) 5 #define ESEPBIT_1 UINT8_C(0x4) 6 #define ESEPBIT_2 UINT8_C(0x8) 7 #define CSEPBIT UINT8_C(0x4) 8 #define EOBIT UINT8_C(0x10) 9 #define COBITS UINT8_C(0xF0) 10 #define COBITS_2 UINT8_C(0x60) 11 #define CTWIST_CW UINT8_C(0x20) 12 #define CTWIST_CCW UINT8_C(0x40) 13 #define EFLIP UINT8_C(0x10) 14 15 STATIC_INLINE int popcount_u32(uint32_t); 16 STATIC_INLINE int popcount_u64(uint64_t); 17 18 STATIC void pieces(cube_t [NON_NULL], uint8_t [SIZE(8)], uint8_t [SIZE(12)]); 19 STATIC_INLINE bool equal(cube_t, cube_t); 20 STATIC_INLINE cube_t invertco(cube_t); 21 STATIC_INLINE cube_t compose_edges(cube_t, cube_t); 22 STATIC_INLINE cube_t compose_corners(cube_t, cube_t); 23 STATIC_INLINE cube_t compose(cube_t, cube_t); 24 STATIC_INLINE cube_t inverse(cube_t); 25 26 STATIC_INLINE uint64_t coord_co(cube_t); 27 STATIC_INLINE cube_t invcoord_co(uint64_t); 28 STATIC_INLINE uint64_t coord_csep(cube_t); 29 STATIC_INLINE uint64_t coord_cocsep(cube_t); 30 STATIC_INLINE uint64_t coord_eo(cube_t); 31 STATIC_INLINE uint64_t coord_esep(cube_t); 32 STATIC_INLINE cube_t invcoord_esep(uint64_t); 33 STATIC_INLINE uint64_t coord_epudsep(cube_t); 34 STATIC_INLINE cube_t invcoord_epudsep(uint64_t); 35 36 STATIC_INLINE bool is_eo_even(cube_t); 37 38 STATIC_INLINE void copy_corners(cube_t [NON_NULL], cube_t); 39 STATIC_INLINE void copy_co(cube_t [NON_NULL], cube_t); 40 STATIC_INLINE void copy_edges(cube_t [NON_NULL], cube_t); 41 STATIC_INLINE void set_eo(cube_t [NON_NULL], uint64_t); 42 43 STATIC_INLINE void invcoord_esep_array(uint64_t, uint64_t, uint8_t[SIZE(12)]); 44 STATIC_INLINE cube_t invcoord_eoesep(uint64_t); 45 STATIC_INLINE uint64_t coord_epudsep_array(const uint8_t [8]); 46 STATIC_INLINE void invcoord_epudsep_array(uint64_t, uint8_t [8]); 47 48 STATIC_INLINE uint64_t coord_cp(cube_t); 49 STATIC_INLINE cube_t invcoord_cp(uint64_t); 50 STATIC_INLINE uint64_t coord_epud(cube_t); 51 STATIC_INLINE cube_t invcoord_epud(uint64_t); 52 STATIC_INLINE uint64_t coord_epe(cube_t); 53 STATIC_INLINE cube_t invcoord_epe(uint64_t); 54 55 STATIC_INLINE void 56 invcoord_esep_array(uint64_t set1, uint64_t set2, uint8_t mem[SIZE(12)]) 57 { 58 uint64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1; 59 uint8_t slice[3] = {0}; 60 61 for (i = 0, j = 0, k = 4, l = 4; i < 12; i++) 62 { 63 v = binomial[11 - i][k]; 64 jj = j < 8; 65 w = jj * binomial[7 - (j * jj)][l]; 66 bit2 = set2 >= v; 67 bit1 = set1 >= w; 68 is1 = (1 - bit2) * bit1; 69 70 set2 -= bit2 * v; 71 k -= bit2; 72 set1 -= is1 * w; 73 l -= is1; 74 j += (1 - bit2); 75 s = 2 * bit2 + (1 - bit2) * bit1; 76 77 mem[i] = (slice[s]++) | (uint8_t)(s << 2); 78 } 79 } 80 81 STATIC_INLINE cube_t 82 invcoord_eoesep(uint64_t i) 83 { 84 cube_t c; 85 uint64_t esep, eo; 86 87 esep = i >> INT64_C(11); 88 eo = i % POW_2_11; 89 c = invcoord_esep(esep); 90 set_eo(&c, eo); 91 92 return c; 93 } 94 95 STATIC_INLINE uint64_t 96 coord_epudsep_array(const uint8_t e[8]) 97 { 98 uint8_t i, k, is; 99 uint64_t ret; 100 101 ret = 0; 102 k = 4; 103 for (i = 0; i < 8; i++) { 104 is = (e[i] & UINT8_C(4)) >> UINT8_C(2); 105 ret += is * binomial[7-i][k]; 106 k -= is; 107 } 108 109 return ret; 110 } 111 112 STATIC_INLINE void 113 invcoord_epudsep_array(uint64_t c, uint8_t ret[8]) 114 { 115 uint8_t i, k, is, x, y; 116 117 k = 4; 118 x = 0; 119 y = 4; 120 for (i = 0; i < 8; i++) { 121 is = c >= binomial[7-i][k]; 122 ret[i] = is*y + (1-is)*x; 123 y += is; 124 x += 1-is; 125 c -= is * binomial[7-i][k]; 126 k -= is; 127 } 128 }