@@ -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