Fix vec4::norm and vec4::magnitude to use expresison instead of immidiate evaluating

This commit is contained in:
Artem Zyktin 2026-05-29 11:40:26 +08:00
parent 23b5a2aa0e
commit 63a228946e
3 changed files with 19 additions and 6 deletions

View File

@ -29,6 +29,7 @@ __m128 Norm<E>::eval() const noexcept
} }
template<vector_expression E> template<vector_expression E>
TNVX_INLINE
Norm<E> norm(const Expr<E>& e) noexcept Norm<E> norm(const Expr<E>& e) noexcept
{ {
return { e.self() }; return { e.self() };

View File

@ -28,10 +28,10 @@ struct alignas(16) vec4 : Expr<vec4>
__m128 eval() const noexcept; __m128 eval() const noexcept;
[[nodiscard]] inline [[nodiscard]] inline
float magnitude() const noexcept; auto magnitude() const noexcept;
[[nodiscard]] inline [[nodiscard]] inline
vec4 norm() const noexcept; auto norm() const noexcept;
[[nodiscard]] inline [[nodiscard]] inline
float x() const noexcept; float x() const noexcept;

View File

@ -35,17 +35,29 @@ __m128 vec4::eval() const noexcept
} }
TNVX_INLINE TNVX_INLINE
float vec4::magnitude() const noexcept auto vec4::magnitude() const noexcept
{ {
return _mm_cvtss_f32(Magnitude<vec4>(*this).eval()); return Magnitude<vec4>(*this);
} }
TNVX_INLINE TNVX_INLINE
vec4 vec4::norm() const noexcept auto vec4::norm() const noexcept
{ {
return { Norm<vec4>(*this) }; return Norm<vec4>(*this);
} }
//TNVX_INLINE
//Magnitude<vec4> vec4::magnitude() const noexcept
//{
// return { *this };
//}
//
//TNVX_INLINE
//Norm<vec4> vec4::norm() const noexcept
//{
// return { *this };
//}
TNVX_INLINE TNVX_INLINE
float vec4::x() const noexcept float vec4::x() const noexcept
{ {