add normal safety

wrap safety around normal checks, this was done on the scalar math may as well do it here just in case.

Ad the impl.inl files to libraries so they can actually be found.
This commit is contained in:
marauder2k7 2026-03-04 23:49:08 +00:00
parent 5a6467d54a
commit 8c1acbd1da
7 changed files with 61 additions and 14 deletions

View file

@ -216,8 +216,22 @@ namespace
inline f32x4 v_normalize3(f32x4 v)
{
f32x4 inv = v_rsqrt_nr(v_dot3(v, v));
return _mm_mul_ps(v, inv);
const f32x4 zero = _mm_setzero_ps();
const f32x4 fallback = _mm_set_ps(0.0f, 1.0f, 0.0f, 0.0f); // {0,0,1,0}
f32x4 dot = v_dot3(v, v);
f32x4 inv = v_rsqrt_nr(dot);
f32x4 isZero = _mm_cmpeq_ps(dot, zero);
f32x4 norm = _mm_mul_ps(v, inv);
// vbsl equivalent
f32x4 result = _mm_or_ps(
_mm_and_ps(isZero, fallback),
_mm_andnot_ps(isZero, norm)
);
return result;
}
// adds all 4 lanes together.