Commit 24baf08c authored by Robert Schmidt's avatar Robert Schmidt

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.
parent 8e7ecaa7
...@@ -391,8 +391,8 @@ void build_polar_tables(t_nrPolar_params *polarParams) { ...@@ -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 // 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 i = 0; i < polarParams->N; i++) {
for (int j = 0; j < polarParams->N; j += 64) { 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 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__m256i *)&polarParams->G_N[i][j + 32], 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) // 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 part1 = simde_mm256_movemask_epi8(tmp1);
const uint32_t part2 = simde_mm256_movemask_epi8(tmp2); const uint32_t part2 = simde_mm256_movemask_epi8(tmp2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment