Add dot4 expression

This commit is contained in:
Artem Zyktin 2026-06-03 17:20:14 +08:00
parent fd917bffba
commit e4b5e656e7
4 changed files with 82 additions and 0 deletions

View File

@ -87,6 +87,14 @@ vf4 dot3(vf4 l, vf4 r) noexcept
return _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(0, 0, 0, 0));
}
[[nodiscard]] TNVX_INLINE
vf4 dot4(vf4 l, vf4 r) noexcept
{
vf4 t = _mm_mul_ps(l, r);
vf4 h = _mm_hadd_ps(t, t);
return _mm_hadd_ps(h, h);
}
[[nodiscard]] TNVX_INLINE
vf4 magnitude3(vf4 v) noexcept
{

View File

@ -0,0 +1,43 @@
#pragma once
#include "core.h"
#include "expression.h"
#include "traits.h"
#include "concepts.h"
namespace tnvx
{
template<vec_expr L, vec_expr R>
struct Dot4 : Expr<Dot4<L, R>>
{
TNVX_INLINE
Dot4(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept;
[[nodiscard]] TNVX_INLINE
vf4 eval() const noexcept;
[[nodiscard]] TNVX_INLINE
operator float() const noexcept;
private:
tnvx_ref_or_value_t<L> _l;
tnvx_ref_or_value_t<R> _r;
};
template<vec_expr L, vec_expr R> inline constexpr bool is_scalar_expr<Dot4<L, R>> = true;
template<vec_expr L, vec_expr R>
[[nodiscard]] TNVX_INLINE
Dot3<L, R> dot4(const L& l, const R& r) noexcept;
template<vec_expr L, vec_expr R>
TNVX_INLINE
Dot3<L, R> dot4(const L& l, const R& r) noexcept
{
return { l, r };
}
}
#include "dot4_impl.hpp"

View File

@ -0,0 +1,30 @@
#pragma once
#include "dot4.h"
namespace tnvx
{
template<vec_expr L, vec_expr R>
TNVX_INLINE
Dot4<L, R>::Dot4(const L& TNVX_RESTRICT l, const R& TNVX_RESTRICT r) noexcept
: _l(l)
, _r(r)
{
}
template<vec_expr L, vec_expr R>
TNVX_INLINE
vf4 Dot4<L, R>::eval() const noexcept
{
return detail::dot4(_l.eval(), _r.eval());
}
template<vec_expr L, vec_expr R>
TNVX_INLINE
Dot4<L, R>::operator float() const noexcept
{
return detail::to_float(eval());
}
}

View File

@ -7,6 +7,7 @@
#include "expressions/mul.h"
#include "expressions/div.h"
#include "expressions/dot3.h"
#include "expressions/dot4.h"
#include "expressions/magnitude3.h"
#include "expressions/norm3.h"
#include "expressions/cross3.h"