pub trait BlockDim: Clone {
const SHIFT: usize;
const WIDTH: usize = 1 << Self::SHIFT;
const AREA: usize = Self::WIDTH * Self::WIDTH;
const MASK: usize = Self::WIDTH - 1;
fn round_up_to_valid(rows: usize, cols: usize) -> (usize, usize) {
let round_up = |i: usize| {
let mut i = i.max(1);
let rem = i % Self::WIDTH;
if rem != 0 {
i += Self::WIDTH - rem;
}
i
};
(round_up(rows), round_up(cols))
}
}
macro_rules! make_block_width [
($($name: ident, $shift: literal);*) => {
$(
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct $name;
impl BlockDim for $name {
const SHIFT: usize = $shift;
}
)*
}
];
make_block_width![
U1, 0;
U2, 1;
U4, 2;
U8, 3;
U16, 4;
U32, 5;
U64, 6;
U128, 7;
U256, 8;
U512, 9
];