|
|
|
@ -83,6 +83,185 @@ macro_rules! impl_wide_vector_operations {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul_transpose_helper {
|
|
|
|
|
(
|
|
|
|
|
$lhs_axis:expr, $wide_mul:ident, $rhs:ident,
|
|
|
|
|
($struct: ident { $($field: ident), + }),
|
|
|
|
|
($from_struct: ident { $($from_field: ident), + }),
|
|
|
|
|
$static_field: ident
|
|
|
|
|
) => {
|
|
|
|
|
$crate::sum_repeating!(
|
|
|
|
|
$( + $lhs_axis.$field.$wide_mul($rhs.$from_field.$static_field) ) +
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul_inner {
|
|
|
|
|
(
|
|
|
|
|
// MatY<VecX>.MatX<VecZ> = MatY<VecZ>
|
|
|
|
|
$lhs:ident, $lhs_field_outer:ident, $wide_mul:ident, $rhs:ident,
|
|
|
|
|
$struct_inner_thru: tt, //VecX
|
|
|
|
|
($struct_inner: ident { $($field_inner: ident), + }), //VecX
|
|
|
|
|
($rhs_struct_inner: ident { $($rhs_field_inner: ident), + }), //VecZ
|
|
|
|
|
$rhs_outer: tt //MatX
|
|
|
|
|
) => {
|
|
|
|
|
$rhs_struct_inner {
|
|
|
|
|
$(
|
|
|
|
|
//directly dot product to avoid a copy
|
|
|
|
|
$rhs_field_inner: $crate::impl_matrix_wide_mul_transpose_helper!{
|
|
|
|
|
//lhs_axis
|
|
|
|
|
$lhs.$lhs_field_outer,$wide_mul,$rhs,
|
|
|
|
|
$struct_inner_thru, //VecZ
|
|
|
|
|
$rhs_outer, //MatX
|
|
|
|
|
$rhs_field_inner
|
|
|
|
|
}
|
|
|
|
|
), +
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul_outer {
|
|
|
|
|
(
|
|
|
|
|
// MatY<VecX>.MatX<VecZ> = MatY<VecZ>
|
|
|
|
|
$lhs:ident, $wide_mul:ident, $rhs:ident,
|
|
|
|
|
//result matrix shape
|
|
|
|
|
($struct_outer: ident { $($field_outer: ident), + }),//MatY
|
|
|
|
|
$rhs_struct_inner: tt,//VecZ
|
|
|
|
|
//inner loop shape
|
|
|
|
|
$struct_inner: tt,//VecX
|
|
|
|
|
$rhs_matrix: tt//MatX
|
|
|
|
|
|
|
|
|
|
) => {
|
|
|
|
|
$struct_outer {
|
|
|
|
|
$(
|
|
|
|
|
$field_outer: $crate::impl_matrix_wide_mul_inner!{
|
|
|
|
|
$lhs, $field_outer, $wide_mul, $rhs,
|
|
|
|
|
$struct_inner, //VecX
|
|
|
|
|
$struct_inner, //VecX
|
|
|
|
|
$rhs_struct_inner, //VecZ
|
|
|
|
|
$rhs_matrix //MatX
|
|
|
|
|
}
|
|
|
|
|
), +
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Notes:
|
|
|
|
|
// Mat3<Vec2>.dot(Vec2) -> Vec3
|
|
|
|
|
// lhs.dot(rhs) -> out
|
|
|
|
|
// lhs = Mat3<Vec4>
|
|
|
|
|
// rhs = Mat4<Vec2>
|
|
|
|
|
// out = Mat3<Vec2>
|
|
|
|
|
// Mat3<Vec4>.dot(Mat4<Vec2>) -> Mat3<Vec2>
|
|
|
|
|
// how to matrix multiply:
|
|
|
|
|
// RHS TRANSPOSE
|
|
|
|
|
// Mat4<Vec2> -> Mat2<Vec4>
|
|
|
|
|
// rhs_t = Mat2<Vec4>
|
|
|
|
|
// inner loop:
|
|
|
|
|
// out[y][x] = lhs[y].dot(rhs_t[x])
|
|
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul {
|
|
|
|
|
(
|
|
|
|
|
($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr),
|
|
|
|
|
($struct_inner: ident { $($field_inner: ident), + }, $matrix_inner: ident { $($matrix_field_inner: ident), + }, $size_inner: expr),
|
|
|
|
|
($rhs_struct_inner: ident { $($rhs_field_inner: ident), + }, $rhs_matrix_inner: ident { $($rhs_matrix_field_inner: ident), + }, $rhs_size_inner: expr),
|
|
|
|
|
($lhs: expr, $rhs: expr)
|
|
|
|
|
) => {
|
|
|
|
|
impl $struct_outer<$struct_inner<fixed_wide::fixed::Fixed<{$lhs},{$lhs*32}>>>{
|
|
|
|
|
paste::item!{
|
|
|
|
|
#[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}>>>{
|
|
|
|
|
$crate::impl_matrix_wide_mul_outer!(
|
|
|
|
|
//constituent idents
|
|
|
|
|
self,[<wide_mul_ $lhs _ $rhs>],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), + })
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul_shim {
|
|
|
|
|
(
|
|
|
|
|
($outer_info:tt,$inner_info:tt,$rhs_info:tt),
|
|
|
|
|
($lhs: expr, $rhs: expr)
|
|
|
|
|
) => {
|
|
|
|
|
$crate::impl_matrix_wide_mul!($outer_info,$inner_info,$rhs_info,($lhs,$rhs));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul_8x8 {
|
|
|
|
|
(
|
|
|
|
|
($outer_info:tt,$inner_info:tt),
|
|
|
|
|
$rhs_info:tt
|
|
|
|
|
) => {
|
|
|
|
|
$crate::do_macro_8x8!(impl_matrix_wide_mul_shim,($outer_info,$inner_info,$rhs_info));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_matrix_wide_mul_repeat_rhs {
|
|
|
|
|
(
|
|
|
|
|
($outer_info:tt,($($rhs_info:tt),+)),
|
|
|
|
|
$inner_info:tt
|
|
|
|
|
) => {
|
|
|
|
|
$crate::macro_repeated!(impl_matrix_wide_mul_8x8,($outer_info,$inner_info),$($rhs_info),+);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_wide_matrix_operations_2arg_not_const_generic {
|
|
|
|
|
(
|
|
|
|
|
$lhs: expr, $rhs: expr,
|
|
|
|
|
($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr),
|
|
|
|
|
($struct_inner: ident { $($field_inner: ident), + }, $matrix_inner: ident { $($matrix_field_inner: ident), + }, $size_inner: expr)
|
|
|
|
|
) => {
|
|
|
|
|
/* TODO: nasty determinant macro
|
|
|
|
|
impl<U:std::ops::Add<Output=U>,T:Copy+fixed_wide_traits::wide::WideMul<Output=U>> $struct<T> {
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn wide_dot(&self) -> U {
|
|
|
|
|
$crate::sum_repeating!(
|
|
|
|
|
$( + self.$field.wide_mul(self.$field) ) +
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
#[macro_export(local_inner_macros)]
|
|
|
|
|
macro_rules! impl_wide_matrix_operations_1arg_not_const_generic {
|
|
|
|
|
(
|
|
|
|
|
$n: expr,
|
|
|
|
|
($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr),
|
|
|
|
|
) => {
|
|
|
|
|
/* TODO: nasty determinant macro
|
|
|
|
|
impl<U:std::ops::Add<Output=U>,T:Copy+fixed_wide_traits::wide::WideMul<Output=U>> $struct<T> {
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn wide_det(&self) -> U {
|
|
|
|
|
$crate::sum_repeating!(
|
|
|
|
|
$( + self.$field.wide_mul(self.$field) ) +
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HACK: Allows us to sum repeating tokens in macros.
|
|
|
|
|
// See: https://stackoverflow.com/a/60187870/17452730
|
|
|
|
|