Merge branch 'perf/dot3'

This commit is contained in:
Artem Zyktin 2026-06-02 05:12:30 +08:00
commit aecca0d9a8
2 changed files with 11 additions and 2 deletions

View File

@ -66,13 +66,19 @@ vf4 div(vf4 l, vf4 r) noexcept
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
vf4 dot3(vf4 l, vf4 r) noexcept vf4 dot3(vf4 l, vf4 r) noexcept
{ {
return _mm_dp_ps(l, r, 0b01111111); //return _mm_dp_ps(l, r, 0b01111111);
vf4 t = _mm_mul_ps(l, r);
vf4 ty = _mm_shuffle_ps(t, t, _MM_SHUFFLE(1, 1, 1, 1));
vf4 xy = _mm_add_ss(t, ty);
vf4 tz = _mm_movehl_ps(t, t);
vf4 xyz = _mm_add_ss(xy, tz);
return _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(0, 0, 0, 0));
} }
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
vf4 magnitude3(vf4 v) noexcept vf4 magnitude3(vf4 v) noexcept
{ {
return _mm_sqrt_ps(_mm_dp_ps(v, v, 0b01111111)); return _mm_sqrt_ps(dot3(v, v));
} }
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE

View File

@ -35,6 +35,9 @@ struct alignas(16) vec4 : Expr<vec4>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
vf4 eval() const noexcept; vf4 eval() const noexcept;
[[nodiscard]] TNVX_INLINE
vec4 operator-() const noexcept;
private: private:
vf4 _data; vf4 _data;