Skip to content

Commit a89b530

Browse files
committed
commnets
1 parent ed7dac9 commit a89b530

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

libc/src/__support/CPP/simd.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static_assert(LIBC_HAS_VECTOR_TYPE, "compiler does not support vector types");
3333
namespace internal {
3434

3535
template <size_t Size> struct get_as_integer_type;
36-
3736
template <> struct get_as_integer_type<1> {
3837
using type = uint8_t;
3938
};
@@ -46,7 +45,6 @@ template <> struct get_as_integer_type<4> {
4645
template <> struct get_as_integer_type<8> {
4746
using type = uint64_t;
4847
};
49-
5048
template <class T>
5149
using get_as_integer_type_t = typename get_as_integer_type<sizeof(T)>::type;
5250

@@ -75,21 +73,18 @@ using simd_mask = simd<bool, internal::native_vector_size<T>>;
7573
// Type trait helpers.
7674
template <typename T> struct simd_size : cpp::integral_constant<size_t, 1> {};
7775
template <typename T, unsigned N>
78-
struct simd_size<T [[clang::ext_vector_type(N)]]>
79-
: cpp::integral_constant<size_t, N> {};
76+
struct simd_size<simd<T, N>> : cpp::integral_constant<size_t, N> {};
8077
template <class T> constexpr size_t simd_size_v = simd_size<T>::value;
8178

8279
template <typename T> struct is_simd : cpp::integral_constant<bool, false> {};
8380
template <typename T, unsigned N>
84-
struct is_simd<T [[clang::ext_vector_type(N)]]>
85-
: cpp::integral_constant<bool, true> {};
81+
struct is_simd<simd<T, N>> : cpp::integral_constant<bool, true> {};
8682
template <class T> constexpr bool is_simd_v = is_simd<T>::value;
8783

8884
template <typename T>
8985
struct is_simd_mask : cpp::integral_constant<bool, false> {};
9086
template <unsigned N>
91-
struct is_simd_mask<bool [[clang::ext_vector_type(N)]]>
92-
: cpp::integral_constant<bool, true> {};
87+
struct is_simd_mask<simd<bool, N>> : cpp::integral_constant<bool, true> {};
9388
template <class T> constexpr bool is_simd_mask_v = is_simd_mask<T>::value;
9489

9590
template <typename T>
@@ -176,27 +171,27 @@ LIBC_INLINE enable_if_simd_t<T> load_unaligned(const void *ptr) {
176171
}
177172
template <typename T>
178173
LIBC_INLINE enable_if_simd_t<T> load_aligned(const void *ptr) {
179-
return *reinterpret_cast<T *>(__builtin_assume_aligned(ptr, alignof(T)));
174+
return load_unaligned<T>(__builtin_assume_aligned(ptr, alignof(T)));
180175
}
181176
template <typename T>
182177
LIBC_INLINE enable_if_simd_t<T> store_unaligned(T v, void *ptr) {
183178
__builtin_memcpy(ptr, &v, sizeof(T));
184179
}
185180
template <typename T>
186181
LIBC_INLINE enable_if_simd_t<T> store_aligned(T v, void *ptr) {
187-
*reinterpret_cast<T *>(__builtin_assume_aligned(ptr, alignof(T))) = v;
182+
store_unaligned<T>(v, __builtin_assume_aligned(ptr, alignof(T)));
188183
}
189184
template <typename T>
190185
LIBC_INLINE enable_if_simd_t<T> masked_load(simd<bool, simd_size_v<T>> m,
191186
void *ptr) {
192187
return __builtin_masked_load(
193-
m, reinterpret_cast<T *>(__builtin_assume_aligned(ptr, alignof(T))));
188+
m, static_cast<T *>(__builtin_assume_aligned(ptr, alignof(T))));
194189
}
195190
template <typename T>
196191
LIBC_INLINE enable_if_simd_t<T> masked_store(simd<bool, simd_size_v<T>> m, T v,
197192
void *ptr) {
198193
__builtin_masked_store(
199-
m, v, reinterpret_cast<T *>(__builtin_assume_aligned(ptr, alignof(T))));
194+
m, v, static_cast<T *>(__builtin_assume_aligned(ptr, alignof(T))));
200195
}
201196

202197
// Construction helpers.

0 commit comments

Comments
 (0)