From 96ff859cb76e573235775ab64bf8cb8f7fec9dc1 Mon Sep 17 00:00:00 2001 From: francescomani Date: Wed, 13 Mar 2024 13:25:04 +0100 Subject: [PATCH] shiftTooManyBitsSigned --- common/utils/nr/nr_common.h | 8 ++- .../nrPolar_tools/nr_polar_procedures.c | 1 - openair1/PHY/NR_TRANSPORT/nr_pbch.c | 6 +-- openair1/PHY/TOOLS/tools_defs.h | 5 -- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 13 ++--- openair1/SIMULATION/TOOLS/gauss.c | 26 +++++----- openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c | 49 +++++++------------ 7 files changed, 47 insertions(+), 61 deletions(-) diff --git a/common/utils/nr/nr_common.h b/common/utils/nr/nr_common.h index 7b790978a3..fb3abd1247 100644 --- a/common/utils/nr/nr_common.h +++ b/common/utils/nr/nr_common.h @@ -169,12 +169,18 @@ uint32_t nr_timer_elapsed_time(NR_timer_t timer); extern const nr_bandentry_t nr_bandtable[]; -static inline int get_num_dmrs(uint16_t dmrs_mask ) { +static inline int get_num_dmrs(uint16_t dmrs_mask ) +{ int num_dmrs=0; for (int i=0;i<16;i++) num_dmrs+=((dmrs_mask>>i)&1); return(num_dmrs); } +static __attribute__((always_inline)) inline int count_bits_set(uint64_t v) +{ + return __builtin_popcountll(v); +} + uint64_t reverse_bits(uint64_t in, int n_bits); void reverse_bits_u8(uint8_t const* in, size_t sz, uint8_t* out); diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c index 7a62d6d48f..2f8f28c571 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c @@ -32,7 +32,6 @@ #include "common/utils/nr/nr_common.h" #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" - #include #include #include diff --git a/openair1/PHY/NR_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_TRANSPORT/nr_pbch.c index dd2493984e..8c2ab883c2 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pbch.c @@ -265,10 +265,10 @@ int nr_generate_pbch(nfapi_nr_dl_tti_ssb_pdu *ssb_pdu, pbch->pbch_a |= n_hf<<28; // half frame index bit if (Lmax == 64) - for (int i=0; i<3; i++) - pbch->pbch_a |= ((ssb_index>>(5-i))&1)<<(29+i); // resp. 6th, 5th and 4th bits of ssb_index + for (int i = 0; i < 3; i++) + pbch->pbch_a |= (uint32_t)((ssb_index >> (5 - i)) & 1) << (29 + i); // resp. 6th, 5th and 4th bits of ssb_index else - pbch->pbch_a |= ((ssb_sc_offset>>4)&1)<<29; //MSB of k_SSB (bit index 4) + pbch->pbch_a |= ((ssb_sc_offset >> 4) & 1) << 29; //MSB of k_SSB (bit index 4) LOG_D(PHY,"After extra byte: pbch_a = 0x%08x\n",pbch->pbch_a); diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h index 06e31542d5..4a418d43b1 100644 --- a/openair1/PHY/TOOLS/tools_defs.h +++ b/openair1/PHY/TOOLS/tools_defs.h @@ -813,11 +813,6 @@ double interp(double x, double *xs, double *ys, int count); void simde_mm128_separate_real_imag_parts(simde__m128i *out_re, simde__m128i *out_im, simde__m128i in0, simde__m128i in1); void simde_mm256_separate_real_imag_parts(simde__m256i *out_re, simde__m256i *out_im, simde__m256i in0, simde__m256i in1); -static __attribute__((always_inline)) inline int count_bits_set(uint64_t v) -{ - return __builtin_popcountll(v); -} - #ifdef __cplusplus } #endif diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 0a348e9c03..5d564e957b 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -544,13 +544,14 @@ void fill_ul_rb_mask(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx) { int rb2 = 0; int prbpos = 0; - for (int symbol=0;symbol<14;symbol++) { - for (int m=0;m<9;m++) { + for (int symbol = 0; symbol < 14; symbol++) { + for (int m = 0; m < 9; m++) { gNB->rb_mask_ul[symbol][m] = 0; - for (int i=0;i<32;i++) { - prbpos = (m*32)+i; - if (prbpos>gNB->frame_parms.N_RB_UL) break; - gNB->rb_mask_ul[symbol][m] |= (gNB->ulprbbl[prbpos]>0 ? 1 : 0)<gNB->frame_parms.N_RB_UL) + break; + gNB->rb_mask_ul[symbol][m] |= (gNB->ulprbbl[prbpos] > 0 ? 1U : 0) << i; } } } diff --git a/openair1/SIMULATION/TOOLS/gauss.c b/openair1/SIMULATION/TOOLS/gauss.c index cc4b1fb793..fe4c684e66 100644 --- a/openair1/SIMULATION/TOOLS/gauss.c +++ b/openair1/SIMULATION/TOOLS/gauss.c @@ -25,28 +25,24 @@ #include "defs.h" -unsigned int *generate_gauss_LUT(unsigned char Nbits, - unsigned char L - ) { - unsigned int *LUT_ptr,i; - LUT_ptr = (unsigned int *)malloc((1<<(Nbits-1))*sizeof(int)); +unsigned int *generate_gauss_LUT(unsigned char Nbits, unsigned char L) +{ + unsigned int *LUT_ptr = calloc((1U << (Nbits - 1)), sizeof(int)); assert(LUT_ptr); - for (i=0; i<(1<<(Nbits-1)); i++) { - LUT_ptr[i] = (unsigned int)((double)((unsigned int)(1<<31))*erf(i*L/(double)(1<<(Nbits-1)))); + for (int i = 0; i < (1 << (Nbits - 1)); i++) { + LUT_ptr[i] = (unsigned int)((double)((unsigned int)(1U << 31)) * erf(i * L / (double)(1 << (Nbits - 1)))); #ifdef LUTDEBUG - printf("pos %u : LUT_ptr[%u]=%x (%f)\n",i,i,LUT_ptr[i],(double)(erf(i*L/(double)(1<<(Nbits-1))))); + printf("pos %d : LUT_ptr[%d]=%x (%f)\n", i, i, LUT_ptr[i], (double)(erf(i * L / (double)(1 << (Nbits -1 ))))); #endif //LUTDEBUG } - return(LUT_ptr); } -int gauss(unsigned int *gauss_LUT, - unsigned char Nbits - ) { +int gauss(unsigned int *gauss_LUT, unsigned char Nbits) +{ unsigned int search_pos,step_size,u,tmp,tmpm1,tmpp1,s; // Get a 32-bit uniform random-variable u = taus(); @@ -127,8 +123,10 @@ void main(int argc,char **argv) { // printf("%d\n",gauss(gauss_LUT_ptr,Nbits)); } - printf("Tail probability = %e(%x)\n",2*erfc((double)L*gauss_LUT_ptr[(1<<(Nbits-1))-1]/(unsigned int)(1<<31)),gauss_LUT_ptr[(1<<(Nbits-1))-1]); - printf("max %d, min %d, mean %f, stddev %f, Pr(maxnum)=%e(%d)\n",maxg,ming,meang,sqrt(varg),(double)maxnum/Ntrials,maxnum); + printf("Tail probability = %e(%x)\n", + 2 * erfc((double)L * gauss_LUT_ptr[(1U << (Nbits - 1)) - 1] / (unsigned int)(1U << 31)), + gauss_LUT_ptr[(1U << (Nbits - 1)) - 1]); + printf("max %d, min %d, mean %f, stddev %f, Pr(maxnum)=%e(%d)\n", maxg, ming, meang, sqrt(varg), (double)maxnum / Ntrials, maxnum); // for (i=0;i<(1< 2016666) { //FR2 x = table_6_3_3_2_4_prachConfig_Index[index][2]; s_map = table_6_3_3_2_4_prachConfig_Index[index][5]; - for(int i = 0; i < 64 ;i++) { - if ( (s_map >> i) & 0x01) { - (*N_RA_sfn)++; - } - } + *N_RA_sfn += count_bits_set(s_map); *N_RA_slot = table_6_3_3_2_4_prachConfig_Index[index][7]; // Number of RACH slots within a subframe *max_association_period = 160/(x * 10); if (start_symbol != NULL && N_t_slot != NULL && N_dur != NULL && format != NULL){ @@ -1722,15 +1718,10 @@ int get_nr_prach_occasion_info_from_index(uint8_t index, return 1; } else { - if (unpaired) { x = table_6_3_3_2_3_prachConfig_Index[index][2]; s_map = table_6_3_3_2_3_prachConfig_Index[index][4]; - for(int i = 0; i < 64 ;i++) { - if ( (s_map >> i) & 0x01) { - (*N_RA_sfn)++; - } - } + *N_RA_sfn += count_bits_set(s_map); *N_RA_slot = table_6_3_3_2_3_prachConfig_Index[index][6]; // Number of RACH slots within a subframe *max_association_period = 160/(x * 10); if (start_symbol != NULL && N_t_slot != NULL && N_dur != NULL && format != NULL){ @@ -1748,18 +1739,14 @@ int get_nr_prach_occasion_info_from_index(uint8_t index, *start_symbol, *N_t_slot, *N_dur, - *N_RA_sfn); + *N_RA_sfn); } - return 1; - } + return 1; + } else { // FDD x = table_6_3_3_2_2_prachConfig_Index[index][2]; s_map = table_6_3_3_2_2_prachConfig_Index[index][4]; - for(int i = 0; i < 64 ; i++) { - if ( (s_map >> i) & 0x01) { - (*N_RA_sfn)++; - } - } + *N_RA_sfn += count_bits_set(s_map); *N_RA_slot = table_6_3_3_2_2_prachConfig_Index[index][6]; if (start_symbol != NULL && N_t_slot != NULL && N_dur != NULL && format != NULL){ *start_symbol = table_6_3_3_2_2_prachConfig_Index[index][5];