From 1f1568ebe90f6cd052555969c0e3e32dc741afc1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 3 Sep 2024 12:01:15 -0700 Subject: [PATCH] wip mat mul --- fixed_wide_vectors/src/macros/fixed_wide.rs | 84 +++++++++++++++++++-- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/fixed_wide_vectors/src/macros/fixed_wide.rs b/fixed_wide_vectors/src/macros/fixed_wide.rs index b8fbbae..44d5aec 100644 --- a/fixed_wide_vectors/src/macros/fixed_wide.rs +++ b/fixed_wide_vectors/src/macros/fixed_wide.rs @@ -83,6 +83,74 @@ macro_rules! impl_wide_vector_operations { }; } +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_wide_mul_transpose_helper { + ( + $value:ident, + ($struct: ident { $($field: ident), + }), + ($from_struct: ident { $($from_field: ident), + }), + $static_field: ident + ) => { + $struct { + $( + $field: $value.$from_field.$static_field + ), + + } + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_wide_mul_inner { + ( + $lhs:ident, $lhs_field_outer:ident, $wide_dot:ident, $rhs:ident, + //pass this in twice, once for pass through and once to parse + $struct_inner_thru: tt, + ($struct_inner: ident { $($field_inner: ident), + }), + $rhs_outer_thru: tt, + ($rhs_outer: ident { $($rhs_outer_field: ident), + }) + ) => { + $struct_inner { + $( + $field_inner: $lhs.$lhs_field_outer.$wide_dot( + //construct a transposed vector with the same width as $struct_outer + $crate::impl_matrix_wide_mul_transpose_helper!{ + $rhs, + $struct_inner_thru, + $rhs_outer_thru, + $rhs_outer_field + } + ) + ), + + } + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_wide_mul_outer { + ( + $lhs:ident, $wide_dot:ident, $rhs:ident, + + ($struct_outer: ident { $($field_outer: ident), + }), + $rhs_struct_inner: tt, + + $struct_inner: tt, + $rhs_matrix: tt + + ) => { + $struct_outer { + $( + $field_outer: $crate::impl_matrix_wide_mul_inner!{ + $lhs, $field_outer, $wide_dot, $rhs, + $struct_inner,//thru + $struct_inner, + $rhs_matrix,//thru + $rhs_matrix + } + ), + + } + } +} // Notes: // Mat3.dot(Vec2) -> Vec3 @@ -103,13 +171,15 @@ macro_rules! impl_matrix_wide_mul { paste::item!{ #[inline] pub fn [](self,rhs:$matrix_inner<$rhs_struct_inner>>)->$struct_outer<$rhs_struct_inner>>{ - //just made this up, don't trust it - let tr=rhs.transpose(); - //TODO: use a macro expansion instead of transpose and map - self.map(|axis| - tr.map(|trax| - axis.[](trax) - ).to_vector() + $crate::impl_matrix_wide_mul_outer!( + //constituent idents + self,[],rhs, + //result matrix shape + ($struct_outer { $($field_outer), + }), + ($rhs_struct_inner { $($rhs_field_inner), + }), + //inner loop shape + ($struct_inner { $($field_inner), + }), + ($matrix_inner { $($matrix_field_inner), + }) ) } }