From b2c24f34357a6aefc208c29a500a4ed020f20b00 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 15 Oct 2023 20:52:54 +0200 Subject: [PATCH] audioconvert: fix unaligned writes Avoid some optimizations that cause unaligned writes. See #3572 --- spa/plugins/audioconvert/fmt-ops-avx2.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spa/plugins/audioconvert/fmt-ops-avx2.c b/spa/plugins/audioconvert/fmt-ops-avx2.c index 5469aec5d..be416a6bd 100644 --- a/spa/plugins/audioconvert/fmt-ops-avx2.c +++ b/spa/plugins/audioconvert/fmt-ops-avx2.c @@ -889,10 +889,14 @@ conv_f32d_to_s16_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const voi int16_t *d = dst[0]; uint32_t i = 0, n_channels = conv->n_channels; - for(; i + 3 < n_channels; i += 4) - conv_f32d_to_s16_4s_avx2(conv, &d[i], &src[i], n_channels, n_samples); - for(; i + 1 < n_channels; i += 2) - conv_f32d_to_s16_2s_avx2(conv, &d[i], &src[i], n_channels, n_samples); + if ((n_channels & 0x3) == 0) { + for(; i + 3 < n_channels; i += 4) + conv_f32d_to_s16_4s_avx2(conv, &d[i], &src[i], n_channels, n_samples); + } + if ((n_channels & 0x1) == 0) { + for(; i + 1 < n_channels; i += 2) + conv_f32d_to_s16_2s_avx2(conv, &d[i], &src[i], n_channels, n_samples); + } for(; i < n_channels; i++) conv_f32d_to_s16_1s_avx2(conv, &d[i], &src[i], n_channels, n_samples); }