From 321a20ea787fccd15e18929a04e0e57a9394af05 Mon Sep 17 00:00:00 2001 From: Sakthivel Velumani Date: Thu, 19 Sep 2024 09:54:53 -0400 Subject: [PATCH] Fix vector mult function for out of bound access --- openair1/PHY/TOOLS/cmult_sv.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/openair1/PHY/TOOLS/cmult_sv.c b/openair1/PHY/TOOLS/cmult_sv.c index ea567b0de1..c20bd24f71 100644 --- a/openair1/PHY/TOOLS/cmult_sv.c +++ b/openair1/PHY/TOOLS/cmult_sv.c @@ -30,28 +30,30 @@ void multadd_complex_vector_real_scalar(int16_t *x, uint8_t zero_flag, uint32_t N) { - simd_q15_t alpha_128,*x_128=(simd_q15_t *)x,*y_128=(simd_q15_t*)y; int n; alpha_128 = set1_int16(alpha); - const uint32_t num_adds = (N + 3) / 4; // ceil(N/4) + const uint32_t num_simd_adds = N / 4; + const uint32_t num_adds = N % 4; if (zero_flag == 1) { - for (n = 0; n < num_adds; n++) { - // print_shorts("x_128[n]=", &x_128[n]); - // print_shorts("alpha_128", &alpha_128); + for (n = 0; n < num_simd_adds; n++) { y_128[n] = mulhi_int16(x_128[n],alpha_128); - // print_shorts("y_128[n]=", &y_128[n]); + } + for (n = 0; n < num_adds; n++) { + const uint32_t offset = num_simd_adds * 4; + y[offset + n] = (x[offset + n] * alpha) >> 16; } } else { - for (n = 0; n < num_adds; n++) { + for (n = 0; n < num_simd_adds; n++) { y_128[n] = adds_int16(y_128[n],mulhi_int16(x_128[n],alpha_128)); } + for (n = 0; n < num_adds; n++) { + const uint32_t offset = num_simd_adds * 4; + y[offset + n] += (x[offset + n] * alpha) >> 16; + } } - - simde_mm_empty(); - simde_m_empty(); } void multadd_real_vector_complex_scalar(const int16_t *x, const int16_t *alpha, int16_t *y, uint32_t N)