use crate::Bits;
const LANE_2D_X: u32 = 0x5555_5555;
const LANE_2D_Y: u32 = 0xAAAA_AAAA;
const LANE_2D_X_U64: u64 = 0x5555_5555_5555_5555;
const LANE_2D_Y_U64: u64 = 0xAAAA_AAAA_AAAA_AAAA;
const LANE_3D_X: u32 = 0x0924_9249; const LANE_3D_Y: u32 = 0x1249_2492; const LANE_3D_Z: u32 = 0x2492_4924;
#[inline]
pub fn encode_2d(x: u16, y: u16) -> u32 {
(Bits::<u32>::new(x as u32).scatter(Bits::new(LANE_2D_X))
| Bits::<u32>::new(y as u32).scatter(Bits::new(LANE_2D_Y))).get()
}
#[inline]
pub fn decode_2d(z: u32) -> (u16, u16) {
let zb = Bits::<u32>::new(z);
(
zb.gather(Bits::new(LANE_2D_X)).get() as u16,
zb.gather(Bits::new(LANE_2D_Y)).get() as u16,
)
}
#[inline]
pub fn encode_2d_u64(x: u32, y: u32) -> u64 {
(Bits::<u64>::new(x as u64).scatter(Bits::new(LANE_2D_X_U64))
| Bits::<u64>::new(y as u64).scatter(Bits::new(LANE_2D_Y_U64))).get()
}
#[inline]
pub fn decode_2d_u64(z: u64) -> (u32, u32) {
let zb = Bits::<u64>::new(z);
(
zb.gather(Bits::new(LANE_2D_X_U64)).get() as u32,
zb.gather(Bits::new(LANE_2D_Y_U64)).get() as u32,
)
}
#[inline]
pub fn encode_3d(x: u16, y: u16, z: u16) -> u32 {
let m10 = Bits::<u32>::new(0x3FF); let xb = Bits::<u32>::new(x as u32) & m10;
let yb = Bits::<u32>::new(y as u32) & m10;
let zb = Bits::<u32>::new(z as u32) & m10;
(xb.scatter(Bits::new(LANE_3D_X))
| yb.scatter(Bits::new(LANE_3D_Y))
| zb.scatter(Bits::new(LANE_3D_Z))).get()
}
#[inline]
pub fn decode_3d(w: u32) -> (u16, u16, u16) {
let wb = Bits::<u32>::new(w);
(
wb.gather(Bits::new(LANE_3D_X)).get() as u16,
wb.gather(Bits::new(LANE_3D_Y)).get() as u16,
wb.gather(Bits::new(LANE_3D_Z)).get() as u16,
)
}