macro_rules! impl_packed_field_pow_2 {
(
$type:ty
$(, ($type_param:ty, $param_name:ty))?
; [ $( ($block_len:expr, $func:ident) ),* $(,)? ],
$width:expr
) => { ... };
}Expand description
A macro to implement the PackedFieldPow2 trait for PackedFields. The macro assumes that the PackedFields
have a to_vector and from_vector method, which convert between the PackedField and a packed vector.
§Arguments:
$type: The type of the PackedField.($type_param, $param_name): Optional type parameter if one is needed and a name for it.; [ ($block_len, $func), ... ]: A list of block lengths and their corresponding interleaving functions.$width: The width of the PackedField, corresponding to the largest possible block length.
For example, calling this macro with:
ⓘ
impl_packed_field_pow_2!(
PackedMontyField31Neon, (FieldParameters, FP);
[
(1, interleave_u32),
(2, interleave_u64),
],
4
);crates the code:
ⓘ
impl<FP: FieldParameters> PackedFieldPow2 for PackedMontyField31Neon<FP> {
#[inline]
fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) {
let (v0, v1) = (self.to_vector(), other.to_vector());
let (res0, res1) = match block_len {
1 => interleave_u32(v0, v1),
2 => interleave_u64(v0, v1),
4 => (v0, v1),
_ => panic!("unsupported block_len"),
};
unsafe {
// Safety: We haven't changed any values, just moved data around
// so all entries still represent valid field elements.
(Self::from_vector(res0), Self::from_vector(res1))
}
}
}