Skip to content

Commit

Permalink
simd constexpr vec: more improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkautarch committed Sep 15, 2024
1 parent d5f8676 commit 5716d8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
14 changes: 7 additions & 7 deletions glm/detail/simd_constexpr/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ namespace glm::detail
{
consteval bool NotEmpty(length_t I, length_t L) { return I <= L; }
struct Empty {};
struct RowTwo {
struct GLM_TRIVIAL RowTwo {
[[no_unique_address]] Empty y; [[no_unique_address]] Empty g; [[no_unique_address]] Empty t;
};
struct RowThree {
struct GLM_TRIVIAL RowThree {
[[no_unique_address]] Empty z; [[no_unique_address]] Empty b; [[no_unique_address]] Empty p;
};
struct RowFour {
struct GLM_TRIVIAL RowFour {
[[no_unique_address]] Empty w; [[no_unique_address]] Empty a; [[no_unique_address]] Empty q;
};
template <qualifier Q, typename T, length_t L>
struct ElementCollection;
template <qualifier Q, typename T>
struct ElementCollection<Q, T, 4> {
struct GLM_TRIVIAL ElementCollection<Q, T, 4> {
using data_t = typename detail::storage<4, T, detail::is_aligned<Q>::value>::type;
union
{
Expand All @@ -31,7 +31,7 @@ namespace glm::detail


template <qualifier Q, typename T>
struct ElementCollection<Q, T, 3> : RowFour {
struct GLM_TRIVIAL ElementCollection<Q, T, 3> : RowFour {
using data_t = typename detail::storage<3, T, detail::is_aligned<Q>::value>::type;
using RowFour::w;
using RowFour::a;
Expand All @@ -47,7 +47,7 @@ namespace glm::detail
};
};
template <qualifier Q, typename T>
struct ElementCollection<Q, T, 2> : RowThree, RowFour {
struct GLM_TRIVIAL ElementCollection<Q, T, 2> : RowThree, RowFour {
using data_t = typename detail::storage<2, T, detail::is_aligned<Q>::value>::type;
using RowThree::z;
using RowThree::b;
Expand All @@ -65,7 +65,7 @@ namespace glm::detail
};
};
template <qualifier Q, typename T>
struct ElementCollection<Q, T, 1> : RowTwo, RowThree, RowFour {
struct GLM_TRIVIAL ElementCollection<Q, T, 1> : RowTwo, RowThree, RowFour {
using data_t = typename detail::storage<1, T, detail::is_aligned<Q>::value>::type;
using RowTwo::y;
using RowTwo::g;
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/simd_constexpr/simd_helpers.inl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace glm::detail
{
//assuming that number of scalars is always the same as the length of the to-be-constructed vector
gcc_vec_t v;
std::array<T, sizeof...(scalars)> pack{scalars...};
std::array<T, sizeof...(scalars)> pack{static_cast<T>(scalars)...};
for (int i = 0; i != sizeof...(scalars); i++ ) {
v[i] = pack[i];
pack[i].T::~T();
Expand Down
20 changes: 11 additions & 9 deletions glm/detail/simd_constexpr/vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <ranges>
namespace glm
{
#ifdef __clang__
#define GLM_TRIVIAL __attribute__((trivial_abi))
#else
#define GLM_TRIVIAL
#endif
template <length_t L>
concept NotVec1 = !std::is_same_v<std::integral_constant<length_t, L>, std::integral_constant<length_t, 1>>;
template <qualifier Q>
Expand Down Expand Up @@ -119,7 +124,7 @@ namespace glm
template <length_t L, typename T, qualifier Q>
using EC = detail::ElementCollection<Q, T, L>;
template<length_t L, typename T, qualifier Q>
struct vec : detail::ElementCollection<Q, T, L>
struct vec GLM_TRIVIAL : detail::ElementCollection<Q, T, L>
{
// -- Data --
using detail::ElementCollection<Q, T, L>::x;
Expand Down Expand Up @@ -282,7 +287,7 @@ namespace glm
}
}
template <length_t len>
using RetArr = T[len];
using RetArr = std::array<T, len>;

template <typename Vs0>
static constexpr length_t ctor_mixed_constexpr_single_get_length()
Expand Down Expand Up @@ -353,19 +358,16 @@ namespace glm
const auto params = std::tuple{vecOrScalar...};

const auto arr = ctor_mixed_constexpr_single(std::get<0>(params));
if (arr) [[likely]]
std::memcpy(aa.a.p.begin()+i, arr, sizeof(T)*lengths[0]);
std::ranges::copy(arr.cbegin(), aa.a.p.begin()+i, aa.a.p.begin()+i + sizeof(T)*lengths[0]);
constexpr auto i2 = i + lengths[0];

if constexpr (sizeof...(VecOrScalar) > 1) {
const auto arr2 = ctor_mixed_constexpr_single(std::get<1>(params));
if (arr2) [[likely]]
std::memcpy(aa.a.p.begin()+i2, arr2, sizeof(T)*lengths[1]);
std::ranges::copy(arr2.cbegin(), aa.a.p.begin()+i2, aa.a.p.begin()+i2 + sizeof(T)*lengths[1]);
constexpr auto i3 = i2 + lengths[1];
if constexpr (sizeof...(VecOrScalar) > 2) {
const auto arr3 = ctor_mixed_constexpr_single(std::get<2>(params));
if (arr3) [[likely]]
std::memcpy(aa.a.p.begin()+i3, arr3, sizeof(T)*lengths[2]);
std::ranges::copy(arr3.cbegin(), aa.a.p.begin()+i3, aa.a.p.begin()+i3 + sizeof(T)*lengths[2]);
}
}

Expand Down Expand Up @@ -460,7 +462,7 @@ namespace glm
}

template<typename Tx>
inline GLM_CONSTEXPR vec<L, T, Q> & operator*=(vec<L, Tx, Q> const& __restrict__ v) __restrict__
inline GLM_CONSTEXPR vec<L, T, Q> & operator*=(vec<L, Tx, Q> const& __restrict__ v)
{
if constexpr (L < 3) {
this->data *= v.data;
Expand Down

0 comments on commit 5716d8e

Please sign in to comment.