#[macro_export]
macro_rules! mask {
([..$end: tt], $ty: ty) => {
{
let max_bits = $crate::max_bits!(type = $ty);
!(0 as $ty) >> (max_bits - $end)
}
};
([$start: tt..], $ty: ty) => {
{
!(0 as $ty) << $start
}
};
([..], $ty: ty) => {
{
!(0 as $ty)
}
};
([$start: tt..$end: tt], $ty: ty) => {
{
let max_bits = $crate::max_bits!(type = $ty);
(!(0 as $ty) << $start) & (!(0 as $ty) >> (max_bits - $end))
}
};
(rev [$start: tt..], $ty: ty) => {
{
!(0 as $ty) >> $start
}
};
(rev [..$end: tt], $ty: ty) => {
{
let max_bits = $crate::max_bits!(type = $ty);
!(0 as $ty) << (max_bits - $end)
}
};
(rev [..], $ty: ty) => {
{
!(0 as $ty)
}
};
(rev [$start: tt..$end: tt], $ty: ty) => {
{
let max_bits = $crate::max_bits!(type = $ty);
(!(0 as $ty) << (max_bits - $end)) & (!(0 as $ty) >> $start)
}
};
([start = $start: tt, count = $count: tt], $ty: ty) => {
{
$crate::mask!([$start..($start + $count)], ($ty))
}
};
(rev [start = $start: tt, count = $count: tt], $ty: ty) => {
{
$crate::mask!(rev [$start..($start + $count)], ($ty))
}
};
}