From 4c3d8e758164ccc40c6cc0b7ae7129de62e3a266 Mon Sep 17 00:00:00 2001 From: Laurent THOMAS <laurent.thomas@open-cells.com> Date: Thu, 17 Aug 2023 13:39:26 +0200 Subject: [PATCH] fix-mem-overflow_64qam fix the 64QAM modulator case, that process 192 bits per iteration, then 24 bits per iteration of the tail bits, then added the last two symboles processing (no odd number of symbols case) --- openair1/PHY/MODULATION/nr_modulation.c | 109 ++++++++++----------- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 5 +- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/openair1/PHY/MODULATION/nr_modulation.c b/openair1/PHY/MODULATION/nr_modulation.c index 310b2f0e75..7396b2af8f 100644 --- a/openair1/PHY/MODULATION/nr_modulation.c +++ b/openair1/PHY/MODULATION/nr_modulation.c @@ -121,10 +121,7 @@ void nr_modulation(uint32_t *in, uint8_t* in_bytes = (uint8_t*) in; uint64_t* in64 = (uint64_t*) in; int64_t* out64 = (int64_t*) out; - uint8_t idx; - uint32_t i,j; - uint32_t bit_cnt; - uint64_t x,x1,x2; + uint32_t i; #if defined(__SSE2__) __m128i *nr_mod_table128; @@ -145,7 +142,7 @@ void nr_modulation(uint32_t *in, i = i*8/2; nr_mod_table32 = (int32_t*) nr_qpsk_mod_table; while (i<length/2) { - idx = ((in_bytes[(i*2)/8]>>((i*2)&0x7)) & mask); + const int idx = ((in_bytes[(i * 2) / 8] >> ((i * 2) & 0x7)) & mask); out32[i] = nr_mod_table32[idx]; i++; } @@ -154,7 +151,7 @@ void nr_modulation(uint32_t *in, case 2: nr_mod_table32 = (int32_t*) nr_qpsk_mod_table; for (i=0; i<length/mod_order; i++) { - idx = ((in[i*2/32]>>((i*2)&0x1f)) & mask); + const int idx = ((in[i * 2 / 32] >> ((i * 2) & 0x1f)) & mask); out32[i] = nr_mod_table32[idx]; } return; @@ -167,66 +164,68 @@ void nr_modulation(uint32_t *in, // the bits that are left out i = i*8/4; while (i<length/4) { - idx = ((in_bytes[(i*4)/8]>>((i*4)&0x7)) & mask); + const int idx = ((in_bytes[(i * 4) / 8] >> ((i * 4) & 0x7)) & mask); out32[i] = nr_16qam_mod_table[idx]; i++; } return; case 6: - j = 0; - for (i=0; i<length/192; i++) { - x = in64[i*3]; - x1 = x&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x>>12)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x>>24)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x>>36)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x>>48)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x2 = (x>>60); - x = in64[i*3+1]; + for (i = 0; i < length - 3 * 64; i += 3 * 64) { + uint64_t x = *in64++; + uint64_t x1 = x & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x >> 12) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x >> 24) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x >> 36) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x >> 48) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + uint64_t x2 = (x >> 60); + x = *in64++; x2 |= x<<4; - x1 = x2&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>12)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>24)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>36)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>48)&4095; - out64[j++] = nr_64qam_mod_table[x1]; + x1 = x2 & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 12) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 24) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 36) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 48) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; x2 = ((x>>56)&0xf0) | (x2>>60); - x = in64[i*3+2]; + x = *in64++; x2 |= x<<8; - x1 = x2&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>12)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>24)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>36)&4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (x2>>48)&4095; - out64[j++] = nr_64qam_mod_table[x1]; + x1 = x2 & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 12) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 24) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 36) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (x2 >> 48) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; x2 = ((x>>52)&0xff0) | (x2>>60); - out64[j++] = nr_64qam_mod_table[x2]; + *out64++ = nr_64qam_mod_table[x2]; } - i *= 24; - bit_cnt = i * 8; - while (bit_cnt < length) { - uint32_t xx; - memcpy(&xx, in_bytes+i, sizeof(xx)); - x1 = xx & 4095; - out64[j++] = nr_64qam_mod_table[x1]; - x1 = (xx >> 12) & 4095; - out64[j++] = nr_64qam_mod_table[x1]; - i += 3; - bit_cnt += 24; + while (i + 24 <= length) { + uint32_t xx = 0; + memcpy(&xx, in_bytes + i / 8, 3); + uint64_t x1 = xx & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + x1 = (xx >> 12) & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; + i += 24; + } + if (i != length) { + uint32_t xx = 0; + memcpy(&xx, in_bytes + i / 8, 2); + uint64_t x1 = xx & 0xfff; + *out64++ = nr_64qam_mod_table[x1]; } return; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index 0d4806f74e..7f8bfb8298 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -184,8 +184,9 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, /////////// uint32_t available_bits = G; - uint32_t scrambled_output[(available_bits>>5)+1]; - memset(scrambled_output, 0, ((available_bits>>5)+1)*sizeof(uint32_t)); + // +1 because size can be not modulo 4 + uint32_t scrambled_output[available_bits / (8 * sizeof(uint32_t)) + 1]; + memset(scrambled_output, 0, sizeof(scrambled_output)); nr_pusch_codeword_scrambling(harq_process_ul_ue->f, available_bits, -- 2.26.2