From a6dc0c37ba6b1a643cc742c6a3b4fea0193b6f94 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 2 Sep 2024 18:35:37 -0700 Subject: [PATCH] MACRO MACRO MACRO --- fixed_wide_vectors/src/macros/fixed_wide.rs | 38 +++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/fixed_wide_vectors/src/macros/fixed_wide.rs b/fixed_wide_vectors/src/macros/fixed_wide.rs index 7679939..ff4e075 100644 --- a/fixed_wide_vectors/src/macros/fixed_wide.rs +++ b/fixed_wide_vectors/src/macros/fixed_wide.rs @@ -1,7 +1,7 @@ #[doc(hidden)] #[macro_export(local_inner_macros)] -macro_rules! impl_wide_vector_operations_const { - ( $lhs:expr, $rhs:expr, ($struct: ident { $($field: ident), + }, $size: expr) ) => { +macro_rules! impl_wide_vector_operations_2arg_not_const_generic { + ( ($lhs:expr, $rhs:expr), ($struct: ident { $($field: ident), + }, $size: expr) ) => { impl $struct>{ paste::item!{ #[inline] @@ -18,16 +18,22 @@ macro_rules! impl_wide_vector_operations_const { } } } - /* - impl,T:Copy+fixed_wide_traits::wide::WideMul> $struct { + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_wide_vector_operations_1arg_not_const_generic { + ( $n:expr, ($struct: ident { $($field: ident), + }, $size: expr) ) => { + impl $struct>{ + paste::item!{ #[inline] - pub fn wide_length_squared(&self) -> U { + pub fn wide_length_squared(&self)->fixed_wide::fixed::Fixed<{$n*2},{$n*2*32}>{ $crate::sum_repeating!( - $( + self.$field.wide_mul(self.$field) ) + + $( + self.$field.[](self.$field) ) + ) } + } } - */ }; } #[doc(hidden)] @@ -36,10 +42,10 @@ macro_rules! do_macro_repeated{ ( $macro:ident, $any:tt, - $(($x:expr, $y:expr)),* + $($repeated:tt),* )=>{ $( - $crate::$macro!($x, $y, $any); + $crate::$macro!($repeated, $any); )* }; } @@ -64,11 +70,23 @@ macro_rules! do_macro_8x8{ }; } +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! do_macro_8{ + ( + $macro:ident, + $any:tt + )=>{ + $crate::do_macro_repeated!($macro, $any, 1,2,3,4,5,6,7,8); + }; +} + #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_wide_vector_operations { ( $struct: ident { $($field: ident), + }, $size: expr ) => { - $crate::do_macro_8x8!(impl_wide_vector_operations_const,($struct { $($field), + }, $size)); + $crate::do_macro_8!(impl_wide_vector_operations_1arg_not_const_generic,($struct { $($field), + }, $size)); + $crate::do_macro_8x8!(impl_wide_vector_operations_2arg_not_const_generic,($struct { $($field), + }, $size)); }; }