Skip to content

Commit

Permalink
Request aligned loads
Browse files Browse the repository at this point in the history
  • Loading branch information
Pencilcaseman committed Aug 20, 2023
1 parent 50f93a7 commit 2d79293
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions librapid/include/librapid/array/arrayContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,17 @@ namespace librapid {

template<typename ShapeType_, typename StorageType_>
auto ArrayContainer<ShapeType_, StorageType_>::packet(size_t index) const -> Packet {
auto ptr = LIBRAPID_ASSUME_ALIGNED(m_storage.begin());

#if defined(LIBRAPID_NATIVE_ARCH) && !defined(LIBRAPID_OSX)
// On MacOS (and other platforms??) we cannot use aligned loads in arrays due to one
// annoying edge case. Normally, all SIMD loads will be aligned to a 64-byte boundary.
// Say, however, this array is a sub-array of a larger array. If the outer dimension
// of the larger array does not result in a 64-byte alignment, the data of *this* array
// will not be correctly aligned, hence causing a segfault.
return xsimd::load_aligned(m_storage.begin() + index);
return xsimd::load_aligned(ptr + index);
#else
return xsimd::load_unaligned(m_storage.begin() + index);
return xsimd::load_unaligned(ptr + index);
#endif
}

Expand Down

0 comments on commit 2d79293

Please sign in to comment.