Skip to content

Instantly share code, notes, and snippets.

@yongqli
Created June 15, 2015 10:07
extern crate test;
#[derive(Debug)]
struct Mat4 {
dat: [[f64; 4]; 4]
}
macro_rules! dot{
($A:expr, $B:expr, $I:expr, $J:expr) => {
$A.dat[0][$I] * $B.dat[$J][0] +
$A.dat[1][$I] * $B.dat[$J][1] +
$A.dat[2][$I] * $B.dat[$J][2] +
$A.dat[3][$I] * $B.dat[$J][3]
};
}
impl Mat4 {
pub fn mult_m(a: Mat4, b: &Mat4) -> Mat4
{
Mat4 {
dat: [[dot!(a, b, 0, 0), dot!(a, b, 1, 0), dot!(a, b, 2, 0), dot!(a, b, 3, 0)],
[dot!(a, b, 0, 1), dot!(a, b, 1, 1), dot!(a, b, 2, 1), dot!(a, b, 3, 1)],
[dot!(a, b, 0, 2), dot!(a, b, 1, 2), dot!(a, b, 2, 2), dot!(a, b, 3, 2)],
[dot!(a, b, 0, 3), dot!(a, b, 1, 3), dot!(a, b, 2, 3), dot!(a, b, 3, 3)]]
}
}
}
pub fn main()
{
let mut a = test::black_box(Mat4 {
dat: [[1., 1., 1., 1.],
[1., 2., 1., 1.],
[1., 1., 4., 1.],
[1., 1., 1., 1.]]
});
let b = test::black_box(Mat4 {
dat: [[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]
});
for _ in 0..1_000_000_000 {
a = Mat4::mult_m(a, &b);
}
println!("a = {:?}", a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment