Fix undefined behavior in PPC load.

VSX vec_xl is Causing a bunch of test failures and failing `-fsanitize=undefined` with g++.
Removing the instruction allows tests to pass and eliminates the warning.
This commit is contained in:
Antonio Sanchez 2025-03-13 22:23:45 -07:00
parent 0ac1fc52dd
commit 5e8edd2186

View File

@ -224,29 +224,25 @@ inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v)
return s; return s;
} }
template <typename Packet> template <typename Packet, typename Scalar>
EIGEN_STRONG_INLINE Packet pload_common(const __UNPACK_TYPE__(Packet)* from) EIGEN_STRONG_INLINE Packet pload_common(const Scalar* from)
{ {
// some versions of GCC throw "unused-but-set-parameter". // some versions of GCC throw "unused-but-set-parameter".
// ignoring these warnings for now. // ignoring these warnings for now.
EIGEN_UNUSED_VARIABLE(from); EIGEN_UNUSED_VARIABLE(from);
EIGEN_DEBUG_ALIGNED_LOAD EIGEN_DEBUG_ALIGNED_LOAD
#ifdef __VSX__
return vec_xl(0, const_cast<__UNPACK_TYPE__(Packet)*>(from));
#else
return vec_ld(0, from); return vec_ld(0, from);
#endif
} }
// Need to define them first or we get specialization after instantiation errors // Need to define them first or we get specialization after instantiation errors
template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
{ {
return pload_common<Packet4f>(from); return pload_common<Packet4f, float>(from);
} }
template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from)
{ {
return pload_common<Packet4i>(from); return pload_common<Packet4i, int>(from);
} }
template <typename Packet> template <typename Packet>
@ -455,15 +451,11 @@ template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { re
template<typename Packet> EIGEN_STRONG_INLINE Packet ploadu_common(const __UNPACK_TYPE__(Packet)* from) template<typename Packet> EIGEN_STRONG_INLINE Packet ploadu_common(const __UNPACK_TYPE__(Packet)* from)
{ {
EIGEN_DEBUG_UNALIGNED_LOAD EIGEN_DEBUG_UNALIGNED_LOAD
#ifdef __VSX__
return vec_xl(0, const_cast<__UNPACK_TYPE__(Packet)*>(from));
#else
Packet16uc mask = vec_lvsl(0, from); // create the permute mask Packet16uc mask = vec_lvsl(0, from); // create the permute mask
Packet16uc MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword Packet16uc MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword
Packet16uc LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword Packet16uc LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword
//TODO: Add static_cast here //TODO: Add static_cast here
return (Packet) vec_perm(MSQ, LSQ, mask); // align the data return (Packet) vec_perm(MSQ, LSQ, mask); // align the data
#endif
} }
template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from)