From 63a228946e1352945abc6725665ed3a121e6180e Mon Sep 17 00:00:00 2001 From: Artem Zyktin Date: Fri, 29 May 2026 11:40:26 +0800 Subject: [PATCH] Fix vec4::norm and vec4::magnitude to use expresison instead of immidiate evaluating --- src/tenvex/internal/norm_impl.hpp | 1 + src/tenvex/vec4.h | 4 ++-- src/tenvex/vec4_impl.hpp | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/tenvex/internal/norm_impl.hpp b/src/tenvex/internal/norm_impl.hpp index d4af233..6ca617e 100644 --- a/src/tenvex/internal/norm_impl.hpp +++ b/src/tenvex/internal/norm_impl.hpp @@ -29,6 +29,7 @@ __m128 Norm::eval() const noexcept } template +TNVX_INLINE Norm norm(const Expr& e) noexcept { return { e.self() }; diff --git a/src/tenvex/vec4.h b/src/tenvex/vec4.h index 9554cd1..03bc9af 100644 --- a/src/tenvex/vec4.h +++ b/src/tenvex/vec4.h @@ -28,10 +28,10 @@ struct alignas(16) vec4 : Expr __m128 eval() const noexcept; [[nodiscard]] inline - float magnitude() const noexcept; + auto magnitude() const noexcept; [[nodiscard]] inline - vec4 norm() const noexcept; + auto norm() const noexcept; [[nodiscard]] inline float x() const noexcept; diff --git a/src/tenvex/vec4_impl.hpp b/src/tenvex/vec4_impl.hpp index 7078975..133d419 100644 --- a/src/tenvex/vec4_impl.hpp +++ b/src/tenvex/vec4_impl.hpp @@ -35,17 +35,29 @@ __m128 vec4::eval() const noexcept } TNVX_INLINE -float vec4::magnitude() const noexcept +auto vec4::magnitude() const noexcept { - return _mm_cvtss_f32(Magnitude(*this).eval()); + return Magnitude(*this); } TNVX_INLINE -vec4 vec4::norm() const noexcept +auto vec4::norm() const noexcept { - return { Norm(*this) }; + return Norm(*this); } +//TNVX_INLINE +//Magnitude vec4::magnitude() const noexcept +//{ +// return { *this }; +//} +// +//TNVX_INLINE +//Norm vec4::norm() const noexcept +//{ +// return { *this }; +//} + TNVX_INLINE float vec4::x() const noexcept {