nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

common.h (2114B)


      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 
     17 STATIC void pieces(cube_t [static 1], uint8_t [static 8], uint8_t [static 12]);
     18 STATIC_INLINE bool equal(cube_t, cube_t);
     19 STATIC_INLINE cube_t invertco(cube_t);
     20 STATIC_INLINE cube_t compose_edges(cube_t, cube_t);
     21 STATIC_INLINE cube_t compose_corners(cube_t, cube_t);
     22 STATIC_INLINE cube_t compose(cube_t, cube_t);
     23 STATIC_INLINE cube_t inverse(cube_t);
     24 
     25 STATIC_INLINE int64_t coord_co(cube_t);
     26 STATIC_INLINE cube_t invcoord_co(int64_t);
     27 STATIC_INLINE int64_t coord_csep(cube_t);
     28 STATIC_INLINE int64_t coord_cocsep(cube_t);
     29 STATIC_INLINE int64_t coord_eo(cube_t);
     30 STATIC_INLINE int64_t coord_esep(cube_t);
     31 STATIC_INLINE cube_t invcoord_esep(int64_t);
     32 
     33 STATIC_INLINE void copy_corners(cube_t [static 1], cube_t);
     34 STATIC_INLINE void copy_edges(cube_t [static 1], cube_t);
     35 STATIC_INLINE void set_eo(cube_t [static 1], int64_t);
     36 
     37 STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]);
     38 STATIC_INLINE cube_t invcoord_eoesep(int64_t);
     39 
     40 STATIC_INLINE void
     41 invcoord_esep_array(int64_t set1, int64_t set2, uint8_t mem[static 12])
     42 {
     43 	int64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1;
     44 	uint8_t slice[3] = {0};
     45 
     46 	for (i = 0, j = 0, k = 4, l = 4; i < 12; i++)
     47 	{
     48 		v = binomial[11 - i][k];
     49 		jj = j < 8;
     50 		w = jj * binomial[7 - (j * jj)][l];
     51 		bit2 = set2 >= v;
     52 		bit1 = set1 >= w;
     53 		is1 = (1 - bit2) * bit1;
     54 
     55 		set2 -= bit2 * v;
     56 		k -= bit2;
     57 		set1 -= is1 * w;
     58 		l -= is1;
     59 		j += (1 - bit2);
     60 		s = 2 * bit2 + (1 - bit2) * bit1;
     61 
     62 		mem[i] = (slice[s]++) | (uint8_t)(s << 2);
     63 	}
     64 }
     65 
     66 STATIC_INLINE cube_t
     67 invcoord_eoesep(int64_t i)
     68 {
     69 	cube_t c;
     70 	int64_t esep, eo;
     71 
     72 	esep = i >> INT64_C(11);
     73 	eo = i % POW_2_11;
     74 	c = invcoord_esep(esep);
     75 	set_eo(&c, eo);
     76 
     77 	return c;
     78 }