Skip to content

Commit 2de3a6b

Browse files
store
1 parent f8fa585 commit 2de3a6b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

include/xsimd/arch/xsimd_altivec.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,24 @@ namespace xsimd
879879
template <class A, class T, class = typename std::enable_if<std::is_scalar<T>::value, void>::type>
880880
XSIMD_INLINE void store_unaligned(T* mem, batch<T, A> const& self, requires_arch<altivec>) noexcept
881881
{
882-
*(typename batch<T, A>::register_type)mem = self.data;
882+
// From: https://stackoverflow.com/questions/35317341/how-to-store-a-vector-to-an-unaligned-location-in-memory-with-altivec
883+
// Load the surrounding area
884+
auto low = vec_ld(0, dst);
885+
auto high = vec_ld(16, dst);
886+
// Prepare the constants that we need
887+
auto permuteVector = vec_lvsr(0, (int*)mem);
888+
auto oxFF = vec_splat_s8(-1);
889+
auto ox00 = vec_splat_s8(0);
890+
// Make a mask for which parts of the vectors to swap out
891+
auto mask = vec_perm(ox00, oxFF, permuteVector);
892+
// Right rotate our input data
893+
v = vec_perm(self, self, permuteVector);
894+
// Insert our data into the low and high vectors
895+
low = vec_sel(self, low, mask);
896+
high = vec_sel(high, self, mask);
897+
// Store the two aligned result vectors
898+
vec_st(low, 0, mem);
899+
vec_st(high, 16, mem);
883900
}
884901

885902
// sub

0 commit comments

Comments
 (0)