Skip to content

Commit 7144171

Browse files
committed
simd constexpr vec: more improvement
1 parent d5f8676 commit 7144171

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

glm/detail/simd_constexpr/element.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ namespace glm::detail
33
{
44
consteval bool NotEmpty(length_t I, length_t L) { return I <= L; }
55
struct Empty {};
6-
struct RowTwo {
6+
struct GLM_TRIVIAL RowTwo {
77
[[no_unique_address]] Empty y; [[no_unique_address]] Empty g; [[no_unique_address]] Empty t;
88
};
9-
struct RowThree {
9+
struct GLM_TRIVIAL RowThree {
1010
[[no_unique_address]] Empty z; [[no_unique_address]] Empty b; [[no_unique_address]] Empty p;
1111
};
12-
struct RowFour {
12+
struct GLM_TRIVIAL RowFour {
1313
[[no_unique_address]] Empty w; [[no_unique_address]] Empty a; [[no_unique_address]] Empty q;
1414
};
1515
template <qualifier Q, typename T, length_t L>
1616
struct ElementCollection;
1717
template <qualifier Q, typename T>
18-
struct ElementCollection<Q, T, 4> {
18+
struct GLM_TRIVIAL ElementCollection<Q, T, 4> {
1919
using data_t = typename detail::storage<4, T, detail::is_aligned<Q>::value>::type;
2020
union
2121
{
@@ -31,7 +31,7 @@ namespace glm::detail
3131

3232

3333
template <qualifier Q, typename T>
34-
struct ElementCollection<Q, T, 3> : RowFour {
34+
struct GLM_TRIVIAL ElementCollection<Q, T, 3> : RowFour {
3535
using data_t = typename detail::storage<3, T, detail::is_aligned<Q>::value>::type;
3636
using RowFour::w;
3737
using RowFour::a;
@@ -47,7 +47,7 @@ namespace glm::detail
4747
};
4848
};
4949
template <qualifier Q, typename T>
50-
struct ElementCollection<Q, T, 2> : RowThree, RowFour {
50+
struct GLM_TRIVIAL ElementCollection<Q, T, 2> : RowThree, RowFour {
5151
using data_t = typename detail::storage<2, T, detail::is_aligned<Q>::value>::type;
5252
using RowThree::z;
5353
using RowThree::b;
@@ -65,7 +65,7 @@ namespace glm::detail
6565
};
6666
};
6767
template <qualifier Q, typename T>
68-
struct ElementCollection<Q, T, 1> : RowTwo, RowThree, RowFour {
68+
struct GLM_TRIVIAL ElementCollection<Q, T, 1> : RowTwo, RowThree, RowFour {
6969
using data_t = typename detail::storage<1, T, detail::is_aligned<Q>::value>::type;
7070
using RowTwo::y;
7171
using RowTwo::g;

glm/detail/simd_constexpr/simd_helpers.inl

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace glm::detail
6969
{
7070
//assuming that number of scalars is always the same as the length of the to-be-constructed vector
7171
gcc_vec_t v;
72-
std::array<T, sizeof...(scalars)> pack{scalars...};
72+
std::array<T, sizeof...(scalars)> pack{static_cast<T>(scalars)...};
7373
for (int i = 0; i != sizeof...(scalars); i++ ) {
7474
v[i] = pack[i];
7575
pack[i].T::~T();

glm/detail/simd_constexpr/vec.hpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include <ranges>
1717
namespace glm
1818
{
19+
#ifdef __clang__
20+
#define GLM_TRIVIAL __attribute__((trivial_abi))
21+
#else
22+
#define GLM_TRIVIAL
23+
#endif
1924
template <length_t L>
2025
concept NotVec1 = !std::is_same_v<std::integral_constant<length_t, L>, std::integral_constant<length_t, 1>>;
2126
template <qualifier Q>
@@ -119,7 +124,7 @@ namespace glm
119124
template <length_t L, typename T, qualifier Q>
120125
using EC = detail::ElementCollection<Q, T, L>;
121126
template<length_t L, typename T, qualifier Q>
122-
struct vec : detail::ElementCollection<Q, T, L>
127+
struct GLM_TRIVIAL vec : detail::ElementCollection<Q, T, L>
123128
{
124129
// -- Data --
125130
using detail::ElementCollection<Q, T, L>::x;
@@ -282,7 +287,7 @@ namespace glm
282287
}
283288
}
284289
template <length_t len>
285-
using RetArr = T[len];
290+
using RetArr = std::array<T, len>;
286291

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

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

360364
if constexpr (sizeof...(VecOrScalar) > 1) {
361365
const auto arr2 = ctor_mixed_constexpr_single(std::get<1>(params));
362-
if (arr2) [[likely]]
363-
std::memcpy(aa.a.p.begin()+i2, arr2, sizeof(T)*lengths[1]);
366+
std::ranges::copy(arr2.cbegin(), aa.a.p.begin()+i2, aa.a.p.begin()+i2 + sizeof(T)*lengths[1]);
364367
constexpr auto i3 = i2 + lengths[1];
365368
if constexpr (sizeof...(VecOrScalar) > 2) {
366369
const auto arr3 = ctor_mixed_constexpr_single(std::get<2>(params));
367-
if (arr3) [[likely]]
368-
std::memcpy(aa.a.p.begin()+i3, arr3, sizeof(T)*lengths[2]);
370+
std::ranges::copy(arr3.cbegin(), aa.a.p.begin()+i3, aa.a.p.begin()+i3 + sizeof(T)*lengths[2]);
369371
}
370372
}
371373

@@ -460,7 +462,7 @@ namespace glm
460462
}
461463

462464
template<typename Tx>
463-
inline GLM_CONSTEXPR vec<L, T, Q> & operator*=(vec<L, Tx, Q> const& __restrict__ v) __restrict__
465+
inline GLM_CONSTEXPR vec<L, T, Q> & operator*=(vec<L, Tx, Q> const& __restrict__ v)
464466
{
465467
if constexpr (L < 3) {
466468
this->data *= v.data;

0 commit comments

Comments
 (0)