From 9f03fde60295212c8b79d75c3d34648a3b61c418 Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Fri, 6 Dec 2024 11:16:48 +0100 Subject: [PATCH] Fix several issues in ulsch_mmse_2layers Fix incorrect array type of determ_fin which was set to int32_t while the array holds the results of simde_mm_abs_epi32 which produces unsigned values. Remove assert on right-shifting negative integers as it is impossible for determ_fin to hold negative values. Change type of sum_det to uint32_t to prevent possible overflow. Fix the type cast (int -> uint32_t) to prevent casting before shift in nr_ulsch_comp_muli_sum which might have resulted in right shifting negative integers. --- .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c index 6a57c1eafe..1ab6a8200d 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c @@ -351,7 +351,7 @@ static void nr_ulsch_det_HhH (int32_t *after_mf_00,//a int32_t *after_mf_01,//b int32_t *after_mf_10,//c int32_t *after_mf_11,//d - int32_t *det_fin,//1/ad-bc + uint32_t *det_fin,//1/ad-bc unsigned short nb_rb, unsigned char symbol, int32_t shift) @@ -493,11 +493,10 @@ static simde__m128i nr_ulsch_comp_muli_sum(simde__m128i input_x, //print_ints("rx_re:",(int32_t*)&xy_re_128[0]); //print_ints("rx_Img:",(int32_t*)&xy_im_128[0]); //divide by matrix det and convert back to Q15 before packing - int sum_det =0; - for (int k=0; k<4;k++) { - sum_det += ((((int *)&det)[k])>>2); - //printf("det_%d = %d log2 =%d \n",k,(((int *)&det[0])[k]),log2_approx(((int *)&det[0])[k])); - } + uint32_t sum_det = 0; + for (int k = 0; k < 4; k++) { + sum_det += (((uint32_t *)&det)[k]) >> 2; + } int b = log2_approx(sum_det) - 8; if (b > 0) { @@ -680,7 +679,7 @@ static uint8_t nr_ulsch_mmse_2layers(NR_DL_FRAME_PARMS *frame_parms, int32_t af_mf_01[12*nb_rb] __attribute__((aligned(32))); int32_t af_mf_10[12*nb_rb] __attribute__((aligned(32))); int32_t af_mf_11[12*nb_rb] __attribute__((aligned(32))); - int32_t determ_fin[12*nb_rb] __attribute__((aligned(32))); + uint32_t determ_fin[12*nb_rb] __attribute__((aligned(32))); switch (n_rx) { case 2:// @@ -945,11 +944,9 @@ static uint8_t nr_ulsch_mmse_2layers(NR_DL_FRAME_PARMS *frame_parms, // Magnitude computation if (mod_order > 2) { - - int sum_det = 0; + uint32_t sum_det = 0; for (int k = 0; k < 4; k++) { - AssertFatal(((int *)&determ_fin_128[0])[k] > 0 ,"Right shifting negative values is UB" ); - sum_det += ((((uint32_t *)&determ_fin_128[0])[k]) >> 2); + sum_det += (((uint32_t *)&determ_fin_128[0])[k]) >> 2; } int b = log2_approx(sum_det) - 8;