Compare commits

...

5 Commits

20 changed files with 26 additions and 24 deletions

View File

@ -19,12 +19,12 @@ struct Add : Expr<Add<L, R>>
private: private:
tnvx_ref_or_value_t<L> _l; tnvx_ref_or_value_t<L> _l;
tnvx_ref_or_value_t<L> _r; tnvx_ref_or_value_t<R> _r;
}; };
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Add<L, R> operator+(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept; Add<L, R> operator+(const L& l, const R& r) noexcept;
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
inline constexpr bool is_vec_expr<Add<L, R>> = true; inline constexpr bool is_vec_expr<Add<L, R>> = true;

View File

@ -22,7 +22,7 @@ vf4 Add<L, R>::eval() const noexcept
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Add<L, R> operator+(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept Add<L, R> operator+(const L& l, const R& r) noexcept
{ {
return { l, r }; return { l, r };
} }

View File

@ -24,7 +24,7 @@ private:
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Cross3<L, R> cross3(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept; Cross3<L, R> cross3(const L& l, const R& r) noexcept;
template<vec_expr L, vec_expr R> inline constexpr bool is_vec_expr<Cross3<L, R>> = true; template<vec_expr L, vec_expr R> inline constexpr bool is_vec_expr<Cross3<L, R>> = true;

View File

@ -22,7 +22,7 @@ vf4 Cross3<L, R>::eval() const noexcept
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
TNVX_INLINE TNVX_INLINE
Cross3<L, R> cross3(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept Cross3<L, R> cross3(const L& l, const R& r) noexcept
{ {
return { l, r }; return { l, r };
} }

View File

@ -26,7 +26,7 @@ private:
template<vec_expr E> template<vec_expr E>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Div<E, Scalar> operator/(const E& TNVX_RESTRICT l, float r) noexcept; Div<E, Scalar> operator/(const E& l, float r) noexcept;
template<vec_expr L, scalar_expr R> inline constexpr bool is_vec_expr<Div<L, R>> = true; template<vec_expr L, scalar_expr R> inline constexpr bool is_vec_expr<Div<L, R>> = true;

View File

@ -22,7 +22,7 @@ vf4 Div<L, R>::eval() const noexcept
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
Div<E, Scalar> operator/(const E& TNVX_RESTRICT l, float r) noexcept Div<E, Scalar> operator/(const E& l, float r) noexcept
{ {
return { l, Scalar(r) }; return { l, Scalar(r) };
} }

View File

@ -27,7 +27,7 @@ private:
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Dot3<L, R> dot3(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept; Dot3<L, R> dot3(const L& l, const R& r) noexcept;
template<vec_expr L, vec_expr R> inline constexpr bool is_scalar_expr<Dot3<L, R>> = true; template<vec_expr L, vec_expr R> inline constexpr bool is_scalar_expr<Dot3<L, R>> = true;

View File

@ -29,7 +29,7 @@ Dot3<L, R>::operator float() const noexcept
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
TNVX_INLINE TNVX_INLINE
Dot3<L, R> dot3(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept Dot3<L, R> dot3(const L& l, const R& r) noexcept
{ {
return { l, r }; return { l, r };
} }

View File

@ -26,7 +26,7 @@ private:
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
Magn3<E> magnitude3(const E& TNVX_RESTRICT e) noexcept; Magn3<E> magnitude3(const E& e) noexcept;
template<vec_expr E> inline constexpr bool is_scalar_expr<Magn3<E>> = true; template<vec_expr E> inline constexpr bool is_scalar_expr<Magn3<E>> = true;

View File

@ -29,7 +29,7 @@ Magn3<E>::operator float() const noexcept
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
Magn3<E> magnitude3(const E& TNVX_RESTRICT e) noexcept Magn3<E> magnitude3(const E& e) noexcept
{ {
return Magn3<E>(e); return Magn3<E>(e);
} }

View File

@ -26,15 +26,15 @@ private:
template<vec_expr E> template<vec_expr E>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Mul<E, Scalar> operator*(const E& TNVX_RESTRICT l, float r) noexcept; Mul<E, Scalar> operator*(const E& l, float r) noexcept;
template<vec_expr E> template<vec_expr E>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Mul<Scalar, E> operator*(float l, const E& TNVX_RESTRICT r) noexcept; Mul<Scalar, E> operator*(float l, const E& r) noexcept;
template<scalar_expr L, scalar_expr R> template<scalar_expr L, scalar_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Mul<L, R> operator*(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept; Mul<L, R> operator*(const L& l, const R& r) noexcept;
template<vec_expr L, scalar_expr R> inline constexpr bool is_vec_expr<Mul<L, R>> = true; template<vec_expr L, scalar_expr R> inline constexpr bool is_vec_expr<Mul<L, R>> = true;
template<scalar_expr L, vec_expr R> inline constexpr bool is_vec_expr<Mul<L, R>> = true; template<scalar_expr L, vec_expr R> inline constexpr bool is_vec_expr<Mul<L, R>> = true;

View File

@ -22,21 +22,21 @@ vf4 Mul<L, R>::eval() const noexcept
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
Mul<E, Scalar> operator*(const E& TNVX_RESTRICT l, float r) noexcept Mul<E, Scalar> operator*(const E& l, float r) noexcept
{ {
return { l, Scalar(r) }; return { l, Scalar(r) };
} }
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
Mul<Scalar, E> operator*(float l, const E& TNVX_RESTRICT r) noexcept Mul<Scalar, E> operator*(float l, const E& r) noexcept
{ {
return { Scalar(l), r }; return { Scalar(l), r };
} }
template<scalar_expr L, scalar_expr R> template<scalar_expr L, scalar_expr R>
TNVX_INLINE TNVX_INLINE
Mul<L, R> operator*(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept Mul<L, R> operator*(const L& l, const R& r) noexcept
{ {
return { l, r }; return { l, r };
} }

View File

@ -23,7 +23,7 @@ private:
template<vec_expr E> template<vec_expr E>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Norm3<E> norm3(const E& TNVX_RESTRICT e) noexcept; Norm3<E> norm3(const E& e) noexcept;
template<vec_expr E> inline constexpr bool is_vec_expr<Norm3<E>> = true; template<vec_expr E> inline constexpr bool is_vec_expr<Norm3<E>> = true;

View File

@ -21,7 +21,7 @@ vf4 Norm3<E>::eval() const noexcept
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
Norm3<E> norm3(const E& TNVX_RESTRICT e) noexcept Norm3<E> norm3(const E& e) noexcept
{ {
return Norm3<E>(e); return Norm3<E>(e);
} }

View File

@ -20,6 +20,8 @@ private:
vf4 _value; vf4 _value;
}; };
static_assert(is_stored_by_value_v<Scalar>, "Scalar must be stored by value");
template<> template<>
inline constexpr bool is_scalar_expr<Scalar> = true; inline constexpr bool is_scalar_expr<Scalar> = true;

View File

@ -24,7 +24,7 @@ private:
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Sub<L, R> operator-(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept; Sub<L, R> operator-(const L& l, const R& r) noexcept;
template<vec_expr L, vec_expr R> inline constexpr bool is_vec_expr<Sub<L, R>> = true; template<vec_expr L, vec_expr R> inline constexpr bool is_vec_expr<Sub<L, R>> = true;

View File

@ -22,7 +22,7 @@ vf4 Sub<L, R>::eval() const noexcept
template<vec_expr L, vec_expr R> template<vec_expr L, vec_expr R>
TNVX_INLINE TNVX_INLINE
Sub<L, R> operator-(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept Sub<L, R> operator-(const L& l, const R& r) noexcept
{ {
return { l, r }; return { l, r };
} }

View File

@ -18,7 +18,7 @@ struct alignas(16) vec4 : Expr<vec4>
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
vec4(const E& TNVX_RESTRICT e) noexcept; vec4(const E& e) noexcept;
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
vf4 eval() const noexcept; vf4 eval() const noexcept;

View File

@ -19,7 +19,7 @@ __m128 vec4::eval() const noexcept
template<vec_expr E> template<vec_expr E>
TNVX_INLINE TNVX_INLINE
vec4::vec4(const E& TNVX_RESTRICT e) noexcept vec4::vec4(const E& e) noexcept
: _data(e.eval()) : _data(e.eval())
{ {
} }

View File

@ -169,7 +169,7 @@ TEST(vec4, dot_commutative)
TEST(vec4, norm_magnitude) TEST(vec4, norm_magnitude)
{ {
vec4 a = { 3.0f, 1.0f, 4.0f, 0.0f }; vec4 a = { 3.0f, 1.0f, 4.0f, 0.0f };
EXPECT_NEAR(magnitude3(norm3(a)), 1.0f, 1e-5f); EXPECT_NEAR(magnitude3(norm3(a)), 1.0f, 1e-6f);
} }
TEST(vec4, dot_perpendicular) TEST(vec4, dot_perpendicular)