Skip to content

Commit c273819

Browse files
committed
cleanup my stuff in qualifiers
1 parent 8f0048a commit c273819

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

glm/detail/qualifier.hpp

+19-27
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,21 @@ namespace detail
107107
};
108108
# endif
109109

110-
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
111110
#if (defined(__clang__) || defined(__GNUC__)) && (GLM_LANG_CXX20_FLAG & GLM_LANG)
112-
#if __x86_64__
113-
consteval uint32_t roundToPow2(uint32_t n) { // https://stackoverflow.com/a/466242
114-
n--;
115-
n |= n >> 1u;
116-
n |= n >> 2u;
117-
n |= n >> 4u;
118-
n |= n >> 8u;
119-
n |= n >> 16u;
120-
n++;
121-
return std::max(n, 1u);
122-
}
123-
#define ALIGNED(size) aligned(roundToPow2( (size) )),
124-
#define ATTR(size) __attribute__((packed,aligned(roundToPow2( (size) ))))
125-
#else
126-
#define ATTR(size)
127-
#define ALIGNED(size)
128-
#endif
111+
template <typename T>
112+
static constexpr size_t requiredAlignment = alignof(T);
113+
129114
template<typename T>
130-
struct ATTR(sizeof(T)/2) storage<2, T, false>
115+
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<2, T, false>
131116
{
132117
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
133-
typedef VType type __attribute__((ALIGNED(sizeof(VType)/2) vector_size(2*sizeof(VType))));
118+
typedef VType type __attribute__((aligned( requiredAlignment<T> ), vector_size(2*sizeof(VType))));
134119
};
135120
template<typename T>
136-
struct ATTR(1) storage<1, T, false>
121+
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<1, T, false>
137122
{
138123
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
139-
typedef VType type __attribute__((aligned(sizeof(VType)),vector_size(sizeof(VType))));
124+
typedef VType type __attribute__((aligned( requiredAlignment<T> ),vector_size(sizeof(VType))));
140125
};
141126
template<typename T>
142127
struct storage<2, T, true>
@@ -151,15 +136,22 @@ consteval uint32_t roundToPow2(uint32_t n) { // https://stackoverflow.com/a/4662
151136
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
152137
typedef VType type __attribute__((aligned(sizeof(VType)),vector_size(sizeof(VType))));
153138
};
154-
template<typename T> requires (roundToPow2(sizeof(T)) == sizeof(T))
155-
struct storage<4, T, false>
139+
template <typename T>
140+
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<3, T, false>
141+
{
142+
typedef struct __attribute__((packed,aligned(requiredAlignment<T>))) type {
143+
T data[3] __attribute__((packed,aligned(requiredAlignment<T>)));
144+
} type;
145+
};
146+
template <typename T>
147+
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<4, T, false>
156148
{
157149
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
158-
typedef VType type __attribute__((vector_size(4*sizeof(VType))));
150+
typedef VType type __attribute__((aligned( requiredAlignment<T> ), vector_size(4*sizeof(VType))));
159151
};
160-
#undef ATTR
161-
#undef ALIGNED
162152
#endif
153+
154+
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
163155
template<>
164156
struct storage<4, float, true>
165157
{

0 commit comments

Comments
 (0)