coordinate.h (1850B)
1 #define H48_ESIZE(h) ((COMB_12_4 * COMB_8_4) << (int64_t)(h)) 2 3 #define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) 4 #define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) 5 #define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) 6 #define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) 7 8 STATIC_INLINE int64_t coord_h48(cube_t, const uint32_t *, uint8_t); 9 STATIC_INLINE int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); 10 STATIC_INLINE cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); 11 12 STATIC_INLINE int64_t 13 coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) 14 { 15 int64_t cocsep, coclass; 16 uint32_t data; 17 uint8_t ttrep; 18 19 DBG_ASSERT(h <= 11, -1, "coord_h48: h must be between 0 and 11\n"); 20 21 cocsep = coord_cocsep(c); 22 data = cocsepdata[cocsep]; 23 coclass = (int64_t)COCLASS(data); 24 ttrep = (int64_t)TTREP(data); 25 26 return coord_h48_edges(c, coclass, ttrep, h); 27 } 28 29 STATIC_INLINE int64_t 30 coord_h48_edges(cube_t c, int64_t coclass, uint8_t ttrep, uint8_t h) 31 { 32 cube_t d; 33 int64_t esep, eo, edges; 34 35 d = transform_edges(c, ttrep); 36 esep = coord_esep(d); 37 eo = coord_eo(d); 38 edges = (esep << 11) + eo; 39 40 return (coclass * H48_ESIZE(11) + edges) >> (11 - (int64_t)h); 41 } 42 43 /* 44 This function does not necessarily return a cube whose coordinate is 45 the given value, because it works up to symmetry. This means that the 46 returned cube is a transformed cube of one that gives the correct value. 47 */ 48 STATIC_INLINE cube_t 49 invcoord_h48(int64_t i, const cube_t *crep, uint8_t h) 50 { 51 cube_t ret; 52 int64_t hh, coclass, ee, esep, eo; 53 54 DBG_ASSERT(h <= 11, ZERO_CUBE, 55 "invcoord_h48: h must be between 0 and 11\n"); 56 57 hh = (int64_t)h; 58 coclass = i / H48_ESIZE(h); 59 ee = i % H48_ESIZE(h); 60 esep = ee >> hh; 61 eo = (ee & ((1 << hh) - 1)) << (11 - hh); 62 63 ret = invcoord_esep(esep); 64 copy_corners(&ret, crep[coclass]); 65 set_eo(&ret, eo); 66 67 return ret; 68 }