@@ -107,36 +107,21 @@ namespace detail
107
107
};
108
108
# endif
109
109
110
- # if GLM_ARCH & GLM_ARCH_SSE2_BIT
111
110
#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
+
129
114
template <typename T>
130
- struct ATTR ( sizeof (T)/ 2 ) storage<2 , T, false >
115
+ struct __attribute__ ((packed,aligned(requiredAlignment<T>)) ) storage<2 , T, false >
131
116
{
132
117
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))));
134
119
};
135
120
template <typename T>
136
- struct ATTR ( 1 ) storage<1 , T, false >
121
+ struct __attribute__ ((packed,aligned(requiredAlignment<T>)) ) storage<1 , T, false >
137
122
{
138
123
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))));
140
125
};
141
126
template <typename T>
142
127
struct storage <2 , T, true >
@@ -151,15 +136,24 @@ consteval uint32_t roundToPow2(uint32_t n) { // https://stackoverflow.com/a/4662
151
136
using VType = std::conditional_t < std::is_same_v<T, bool >, uint8_t , T>;
152
137
typedef VType type __attribute__ ((aligned(sizeof (VType)),vector_size(sizeof (VType))));
153
138
};
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 >
156
148
{
157
149
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))));
159
151
};
160
152
#undef ATTR
161
153
#undef ALIGNED
162
154
#endif
155
+
156
+ # if GLM_ARCH & GLM_ARCH_SSE2_BIT
163
157
template <>
164
158
struct storage <4 , float , true >
165
159
{
0 commit comments