Skip to content

Commit 8df8da7

Browse files
Andreas-Krebbelserge-sans-paille
authored andcommitted
Fix VSX clang build
1 parent 3a61c90 commit 8df8da7

2 files changed

Lines changed: 60 additions & 22 deletions

File tree

include/xsimd/arch/xsimd_vsx.hpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ namespace xsimd
3333

3434
namespace kernel
3535
{
36+
// builtin_t<T> - the scalar type as it would be used for a vector intrinsic
37+
// VSX vector intrinsics do not support long, unsigned long, and char
38+
// The builtin<T> definition can be used to map the incoming
39+
// type to the right one to be used with the intrinsics.
40+
template <typename T>
41+
struct builtin_scalar
42+
{
43+
using type = T;
44+
};
45+
46+
template <>
47+
struct builtin_scalar<unsigned long>
48+
{
49+
using type = unsigned long long;
50+
};
51+
52+
template <>
53+
struct builtin_scalar<long>
54+
{
55+
using type = long long;
56+
};
57+
58+
template <>
59+
struct builtin_scalar<char>
60+
{
61+
using type = typename std::conditional<std::is_signed<char>::value, signed char, unsigned char>::type;
62+
};
63+
64+
template <typename T>
65+
using builtin_t = typename builtin_scalar<T>::type;
66+
3667
template <class A, class T>
3768
XSIMD_INLINE batch<T, A> avg(batch<T, A> const&, batch<T, A> const&, requires_arch<common>) noexcept;
3869
template <class A, class T>
@@ -218,7 +249,7 @@ namespace xsimd
218249
template <class A, class T, class = std::enable_if_t<std::is_scalar<T>::value>>
219250
XSIMD_INLINE batch<T, A> broadcast(T val, requires_arch<vsx>) noexcept
220251
{
221-
return vec_splats(val);
252+
return vec_splats(static_cast<builtin_t<T>>(val));
222253
}
223254

224255
// ceil
@@ -421,18 +452,18 @@ namespace xsimd
421452
return ~vec_cmpeq(self.data, self.data);
422453
}
423454

424-
// load_aligned
455+
// load_unaligned
425456
template <class A, class T, class = std::enable_if_t<std::is_scalar<T>::value>>
426-
XSIMD_INLINE batch<T, A> load_aligned(T const* mem, convert<T>, requires_arch<vsx>) noexcept
457+
XSIMD_INLINE batch<T, A> load_unaligned(T const* mem, convert<T>, requires_arch<vsx>) noexcept
427458
{
428-
return vec_ld(0, reinterpret_cast<const typename batch<T, A>::register_type*>(mem));
459+
return (typename batch<T, A>::register_type)vec_xl(0, (builtin_t<T>*)mem);
429460
}
430461

431-
// load_unaligned
462+
// load_aligned
432463
template <class A, class T, class = std::enable_if_t<std::is_scalar<T>::value>>
433-
XSIMD_INLINE batch<T, A> load_unaligned(T const* mem, convert<T>, requires_arch<vsx>) noexcept
464+
XSIMD_INLINE batch<T, A> load_aligned(T const* mem, convert<T>, requires_arch<vsx>) noexcept
434465
{
435-
return vec_vsx_ld(0, (typename batch<T, A>::register_type const*)mem);
466+
return load_unaligned<A>(mem, kernel::convert<T> {}, vsx {});
436467
}
437468

438469
// load_complex
@@ -758,14 +789,14 @@ namespace xsimd
758789
template <class A, class T, class = std::enable_if_t<std::is_scalar<T>::value>>
759790
XSIMD_INLINE void store_aligned(T* mem, batch<T, A> const& self, requires_arch<vsx>) noexcept
760791
{
761-
return vec_st(self.data, 0, reinterpret_cast<typename batch<T, A>::register_type*>(mem));
792+
vec_xst((typename batch<T, A>::register_type)self.data, 0, (builtin_t<T>*)mem);
762793
}
763794

764795
// store_unaligned
765796
template <class A, class T, class = std::enable_if_t<std::is_scalar<T>::value>>
766797
XSIMD_INLINE void store_unaligned(T* mem, batch<T, A> const& self, requires_arch<vsx>) noexcept
767798
{
768-
return vec_vsx_st(self.data, 0, reinterpret_cast<typename batch<T, A>::register_type*>(mem));
799+
store_aligned<A>(mem, self, vsx {});
769800
}
770801

771802
// sub

include/xsimd/types/xsimd_vsx_register.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace xsimd
3939
namespace types
4040
{
4141

42-
#define XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(T, Tb) \
42+
#define XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(T, Tv, Tb) \
4343
template <> \
4444
struct get_bool_simd_register<T, vsx> \
4545
{ \
@@ -55,19 +55,26 @@ namespace xsimd
5555
operator register_type() const noexcept { return data; } \
5656
}; \
5757
}; \
58-
XSIMD_DECLARE_SIMD_REGISTER(T, vsx, __vector T)
58+
XSIMD_DECLARE_SIMD_REGISTER(T, vsx, __vector Tv)
5959

60-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(signed char, char);
61-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned char, char);
62-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(char, char);
63-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned short, short);
64-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(short, short);
65-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned int, int);
66-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(int, int);
67-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned long, long);
68-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(long, long);
69-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(float, int);
70-
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(double, long);
60+
// The VSX vector intrinsics do not support long, unsigned long,
61+
// and char data types. batches of these types are vectors of
62+
// equivalent types.
63+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(signed char, signed char, char);
64+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned char, unsigned char, char);
65+
#ifdef __CHAR_UNSIGNED__
66+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(char, unsigned char, char);
67+
#else
68+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(char, signed char, char);
69+
#endif
70+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned short, unsigned short, short);
71+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(short, short, short);
72+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned int, unsigned int, int);
73+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(int, int, int);
74+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(unsigned long, unsigned long long, long long);
75+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(long, long long, long long);
76+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(float, float, int);
77+
XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER(double, double, long long);
7178

7279
#undef XSIMD_DECLARE_SIMD_BOOL_VSX_REGISTER
7380
}

0 commit comments

Comments
 (0)