I have he following structs in my math library
pub const F32x4 = @Vector(4, f32);
pub const Quat = extern struct {
xyzw: F32x4 = .{ 0.0, 0.0, 0.0, 1.0 },
};
pub fn matRotation_1(q: Quat) Mat4 // q is passed via stack
pub fn matRotation_2(q: F32x4) Mat4 // q is passed via xmm0 as it should
pub fn matTRS_1(pos: F32x4, rot: Quat, s: F32x4) Mat4; // crashes on access violation
pub fn matTRS_2(pos: F32x4, rot: F32x4, s: F32x4) Mat4; // works fine
the issue is when using matTRS_1 I get an access violation exception, no error occurs if inline the function (by copy/paste or tag with inline keyword) looking at the assembly I notice that Quat is passed via stack while F32x4 is passed via xmm register not sure if this is a causing the bug or not.
In the past zig had produce invalid code with long an complex functions; I’m calling matTRS_1 from main that is about 1K line function
About Quat been passed in the stack rather than xmm is that working as intended?
Edit 1:
I found another thing: calling Quat.mat(rot) produces a different result that rot.mat() whut
pub fn trs(pos: F32x4, rot: Quat, s: F32x4) Mat4 {
var m = Quat.mat(rot); // works fine
var m = rot.mat(); // access violation
inline for (0..3) |i| m.rows[i] *= @splat(s[i]);
m.rows[3] = @shuffle(f32, pos, m.rows[3], [4]i32{ 0, 1, 2, -4 });
return m;
}