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

@ -27,9 +27,6 @@ namespace
// Element-wise multiply
inline f32x4 v_mul(f32x4 a, f32x4 b) { return _mm_mul_ps(a, b); }
// Element-wise divide precise
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)
{
@ -38,6 +35,9 @@ namespace
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); }
@ -54,11 +54,24 @@ namespace
float float3_dot_avx(const float* a, const float* b)
{
f32x4 va = _mm_loadu_ps(a);
f32x4 vb = _mm_loadu_ps(b);
__m128 dp = _mm_dp_ps(va, vb, 0x71); // multiply 3 (0x71), sum all 4, lowest lane
f32x4 va = v_load3(a);
f32x4 vb = v_load3(b);
__m128 dp = _mm_dp_ps(va, vb, 0x71); // multiply 3 (0x71), sum 3, 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 "float3_impl.inl"
@ -80,5 +93,6 @@ namespace math_backend::float3::dispatch
gFloat3.normalize = float3_normalize_impl;
gFloat3.normalize_mag = float3_normalize_mag_impl;
gFloat3.lerp = float3_lerp_impl;
gFloat3.cross = float3_cross_impl;
}
}