all float3 and float4 functions and isas

completed all options of float3 and float4 functions in isas and math_c
neon still to be done but that will be on mac.
This commit is contained in:
marauder2k7 2026-02-27 11:28:51 +00:00
parent 18d0aa0418
commit f0a3251cd3
16 changed files with 593 additions and 90 deletions

View file

@ -18,8 +18,16 @@ namespace
// Element-wise multiply
inline f32x4 v_mul(f32x4 a, f32x4 b) { return _mm_mul_ps(a, b); }
// Element-wise divide
inline f32x4 v_div(f32x4 a, f32x4 b) { return _mm_div_ps(a, b); }
// Element-wise divide fast (1/b)
inline f32x4 v_div_fast(f32x4 a, f32x4 b)
{
f32x4 rcp = _mm_rcp_ps(b);
// Optional refinement here
return _mm_mul_ps(a, rcp);
}
// Element-wise divide (to change from fast use _mm_div_ps(a,b)
inline f32x4 v_div(f32x4 a, f32x4 b) { return v_div_fast(a, b); }
// Element-wise add
inline f32x4 v_add(f32x4 a, f32x4 b) { return _mm_add_ps(a, b); }
@ -43,6 +51,19 @@ namespace
__m128 dp = _mm_dp_ps(va, vb, 0xF1); // multiply all 4, sum all 4, lowest lane
return _mm_cvtss_f32(dp);
}
inline f32x4 v_cross(f32x4 a, f32x4 b)
{
f32x4 a_yzx = _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 0, 2, 1));
f32x4 b_yzx = _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 0, 2, 1));
f32x4 c = _mm_sub_ps(
_mm_mul_ps(a, b_yzx),
_mm_mul_ps(a_yzx, b)
);
return _mm_shuffle_ps(c, c, _MM_SHUFFLE(3, 0, 2, 1));
}
}
#include "float4_impl.inl"
@ -64,5 +85,6 @@ namespace math_backend::float4::dispatch
gFloat4.normalize = float4_normalize_impl;
gFloat4.normalize_mag = float4_normalize_mag_impl;
gFloat4.lerp = float4_lerp_impl;
gFloat4.cross = float4_cross_impl;
}
}