Load unaligned data for SIMD processing to avoid segv

We access G_N at indexes that are not necessarily 32-byte aligned,
leading to segfaults. Use simde_mm256_loadu_si256() to load from memory
at an unaligned memory address to avoid the segfault.

Discovered using clang; it is unclear why gcc did not encounter the same
segfault.
This commit is contained in:
Robert Schmidt
2024-04-18 14:06:05 +02:00
parent 8e7ecaa73a
commit 24baf08c87
@@ -391,8 +391,8 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
// this code packs the one bit per byte of G_N into a packed bits G_N_tab
for (int i = 0; i < polarParams->N; i++) {
for (int j = 0; j < polarParams->N; j += 64) {
const simde__m256i tmp1 = simde_mm256_cmpgt_epi8(*(simde__m256i *)&polarParams->G_N[i][j], zeros);
const simde__m256i tmp2 = simde_mm256_cmpgt_epi8(*(simde__m256i *)&polarParams->G_N[i][j + 32], zeros);
const simde__m256i tmp1 = simde_mm256_cmpgt_epi8(simde_mm256_loadu_si256((simde__m256i *)&polarParams->G_N[i][j]), zeros);
const simde__m256i tmp2 = simde_mm256_cmpgt_epi8(simde_mm256_loadu_si256((simde__m256i *)&polarParams->G_N[i][j + 32]), zeros);
// cast directly to uint64_t from int32_t propagates the sign bit (in gcc)
const uint32_t part1 = simde_mm256_movemask_epi8(tmp1);
const uint32_t part2 = simde_mm256_movemask_epi8(tmp2);