wip mat mul

This commit is contained in:
Quaternions 2024-09-03 12:01:15 -07:00
parent 176eb762e3
commit 1f1568ebe9

View File

@ -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: // Notes:
// Mat3<Vec2>.dot(Vec2) -> Vec3 // Mat3<Vec2>.dot(Vec2) -> Vec3
@ -103,13 +171,15 @@ macro_rules! impl_matrix_wide_mul {
paste::item!{ paste::item!{
#[inline] #[inline]
pub fn [<wide_dot_ $size_outer x $size_inner _ $size_inner x $rhs_size_inner _ $lhs _ $rhs>](self,rhs:$matrix_inner<$rhs_struct_inner<fixed_wide::fixed::Fixed<{$rhs},{$rhs*32}>>>)->$struct_outer<$rhs_struct_inner<fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>>>{ pub fn [<wide_dot_ $size_outer x $size_inner _ $size_inner x $rhs_size_inner _ $lhs _ $rhs>](self,rhs:$matrix_inner<$rhs_struct_inner<fixed_wide::fixed::Fixed<{$rhs},{$rhs*32}>>>)->$struct_outer<$rhs_struct_inner<fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>>>{
//just made this up, don't trust it $crate::impl_matrix_wide_mul_outer!(
let tr=rhs.transpose(); //constituent idents
//TODO: use a macro expansion instead of transpose and map self,[<wide_dot_ $lhs _ $rhs>],rhs,
self.map(|axis| //result matrix shape
tr.map(|trax| ($struct_outer { $($field_outer), + }),
axis.[<wide_dot_ $lhs _ $rhs>](trax) ($rhs_struct_inner { $($rhs_field_inner), + }),
).to_vector() //inner loop shape
($struct_inner { $($field_inner), + }),
($matrix_inner { $($matrix_field_inner), + })
) )
} }
} }