fix bug for multiplication collapsing

This commit is contained in:
Artem Zyktin 2026-05-31 00:45:44 +08:00
parent f6f25f931b
commit 8db1717752
2 changed files with 50 additions and 1 deletions

View File

@ -24,6 +24,11 @@ private:
tnvx_ref_or_value_t<R> _r; tnvx_ref_or_value_t<R> _r;
}; };
// this banch of reloads (instead of expression*expression) is required for two thigs:
// 1. to avoid ambiguity with operator* for vector-vector multiplication
// 2. to avoid scalar operator collapses to float instead of lazy-expressions
template<vec_expr E> template<vec_expr E>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Mul<E, Scalar> operator*(const E& l, float r) noexcept; Mul<E, Scalar> operator*(const E& l, float r) noexcept;
@ -36,6 +41,22 @@ template<scalar_expr L, scalar_expr R>
[[nodiscard]] TNVX_INLINE [[nodiscard]] TNVX_INLINE
Mul<L, R> operator*(const L& l, const R& r) noexcept; Mul<L, R> operator*(const L& l, const R& r) noexcept;
template<scalar_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE
Mul<L, R> operator*(const L& l, const R& r) noexcept;
template<vec_expr L, scalar_expr R>
[[nodiscard]] TNVX_INLINE
Mul<L, R> operator*(const L& l, const R& r) noexcept;
template<scalar_expr E>
[[nodiscard]] TNVX_INLINE
Mul<E, Scalar> operator*(const E& l, float r) noexcept;
template<scalar_expr E>
[[nodiscard]] TNVX_INLINE
Mul<Scalar, E> operator*(float l, const E& 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

@ -17,7 +17,7 @@ template<expression L, expression R>
TNVX_INLINE TNVX_INLINE
vf4 Mul<L, R>::eval() const noexcept vf4 Mul<L, R>::eval() const noexcept
{ {
return _mm_mul_ps(_l.eval(), _r.eval()); return detail::mul(_l.eval(), _r.eval());
} }
template<vec_expr E> template<vec_expr E>
@ -41,4 +41,32 @@ Mul<L, R> operator*(const L& l, const R& r) noexcept
return { l, r }; return { l, r };
} }
template<scalar_expr L, vec_expr R>
TNVX_INLINE
Mul<L, R> operator*(const L& l, const R& r) noexcept
{
return { l, r };
}
template<vec_expr L, scalar_expr R>
TNVX_INLINE
Mul<L, R> operator*(const L& l, const R& r) noexcept
{
return { l, r };
}
template<scalar_expr E>
TNVX_INLINE
Mul<E, Scalar> operator*(const E& l, float r) noexcept
{
return { l, Scalar(r) };
}
template<scalar_expr E>
TNVX_INLINE
Mul<Scalar, E> operator*(float l, const E& r) noexcept
{
return { Scalar(l), r };
}
} }