From 83c59b05e9160fd69332ec7ed24a2c0b708732a5 Mon Sep 17 00:00:00 2001 From: francescomani Date: Wed, 10 Jul 2024 18:41:11 +0200 Subject: [PATCH] code cleanup and small fixes --- openair1/PHY/CODING/nr_rate_matching.c | 4 +- openair1/PHY/NR_REFSIG/dmrs_nr.c | 6 +-- openair1/PHY/NR_REFSIG/dmrs_nr.h | 2 +- openair1/PHY/NR_TRANSPORT/nr_scrambling.c | 14 +++---- openair1/SIMULATION/NR_PHY/ulsim.c | 17 +++++++-- .../NR_MAC_COMMON/nr_compute_tbs_common.c | 13 +++++-- openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c | 38 ++++++++++--------- 7 files changed, 54 insertions(+), 40 deletions(-) diff --git a/openair1/PHY/CODING/nr_rate_matching.c b/openair1/PHY/CODING/nr_rate_matching.c index 5a6d2885a5..1ed520cf12 100644 --- a/openair1/PHY/CODING/nr_rate_matching.c +++ b/openair1/PHY/CODING/nr_rate_matching.c @@ -452,7 +452,7 @@ int nr_rate_matching_ldpc(uint32_t Tbslbrm, ind = (index_k0[BG-1][rvidx]*Ncb/N)*Z; #ifdef RM_DEBUG - printf("nr_rate_matching_ldpc: E %u, F %u, Foffset %u, k0 %u, Ncb %u, rvidx %d, Tbslbrm %u\n", E, F, Foffset,ind, Ncb, rvidx, Tbslbrm); + printf("nr_rate_matching_ldpc: E %u, F %u, Foffset %u, k0 %u, Ncb %u, rvidx %d, Tbslbrm %u\n", E, F, Foffset, ind, Ncb, rvidx, Tbslbrm); #endif if (Foffset > E) { @@ -548,7 +548,7 @@ int nr_rate_matching_ldpc_rx(uint32_t Tbslbrm, } #ifdef RM_DEBUG - printf("nr_rate_matching_ldpc_rx: Clear %d, E %u, k0 %u, Ncb %u, rvidx %d, Tbslbrm %u\n", clear, E, ind, Ncb, rvidx, Tbslbrm); + printf("nr_rate_matching_ldpc_rx: Clear %d, E %u, Foffset %u, k0 %u, Ncb %u, rvidx %d, Tbslbrm %u\n", clear, E, Foffset, ind, Ncb, rvidx, Tbslbrm); #endif if (clear == 1) diff --git a/openair1/PHY/NR_REFSIG/dmrs_nr.c b/openair1/PHY/NR_REFSIG/dmrs_nr.c index 4576f322f3..377eb4d89b 100644 --- a/openair1/PHY/NR_REFSIG/dmrs_nr.c +++ b/openair1/PHY/NR_REFSIG/dmrs_nr.c @@ -308,10 +308,10 @@ int8_t get_next_dmrs_symbol_in_slot(uint16_t ul_dmrs_symb_pos, uint8_t counter, /* return the total number of dmrs symbol in a slot */ -uint8_t get_dmrs_symbols_in_slot(uint16_t l_prime_mask, uint16_t nb_symb) +uint8_t get_dmrs_symbols_in_slot(uint16_t l_prime_mask, uint16_t nb_symb, uint8_t start) { uint8_t tmp = 0; - for (int i = 0; i < nb_symb; i++) { + for (int i = start; i < start + nb_symb; i++) { tmp += (l_prime_mask >> i) & 0x01; } return tmp; @@ -351,7 +351,7 @@ void nr_chest_time_domain_avg(NR_DL_FRAME_PARMS *frame_parms, simde__m128i *ul_ch128_1; int16_t *ul_ch16_0; int total_symbols = start_symbol + num_symbols; - int num_dmrs_symb = get_dmrs_symbols_in_slot(dmrs_bitmap, total_symbols); + int num_dmrs_symb = get_dmrs_symbols_in_slot(dmrs_bitmap, total_symbols, start_symbol); int first_dmrs_symb = get_next_dmrs_symbol_in_slot(dmrs_bitmap, start_symbol, total_symbols); AssertFatal(first_dmrs_symb > -1, "No DMRS symbol present in this slot\n"); for (int aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) { diff --git a/openair1/PHY/NR_REFSIG/dmrs_nr.h b/openair1/PHY/NR_REFSIG/dmrs_nr.h index 8b9da28abc..2c1005a19b 100644 --- a/openair1/PHY/NR_REFSIG/dmrs_nr.h +++ b/openair1/PHY/NR_REFSIG/dmrs_nr.h @@ -63,7 +63,7 @@ uint8_t allowed_xlsch_re_in_dmrs_symbol(uint16_t k, void nr_gen_ref_conj_symbols(uint32_t *in, uint32_t length, int16_t *output, uint16_t offset, int mod_order); int8_t get_next_dmrs_symbol_in_slot(uint16_t ul_dmrs_symb_pos, uint8_t counter, uint8_t end_symbol); -uint8_t get_dmrs_symbols_in_slot(uint16_t l_prime_mask, uint16_t nb_symb); +uint8_t get_dmrs_symbols_in_slot(uint16_t l_prime_mask, uint16_t nb_symb, uint8_t start); int8_t get_valid_dmrs_idx_for_channel_est(uint16_t dmrs_symb_pos, uint8_t counter); void nr_chest_time_domain_avg(NR_DL_FRAME_PARMS *frame_parms, int32_t **ch_estimates, diff --git a/openair1/PHY/NR_TRANSPORT/nr_scrambling.c b/openair1/PHY/NR_TRANSPORT/nr_scrambling.c index b54a5c2c0c..353db70454 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_scrambling.c +++ b/openair1/PHY/NR_TRANSPORT/nr_scrambling.c @@ -32,16 +32,14 @@ void nr_codeword_scrambling(uint8_t *in, uint32_t* out) { uint32_t x1; - uint32_t x2 = (n_RNTI<<15) + (q<<14) + Nid; - uint32_t s = 0; - - s=lte_gold_generic(&x1, &x2, 1); - for (int i=0; i<((size>>5)+((size&0x1f) > 0 ? 1 : 0)); i++) { + uint32_t x2 = (n_RNTI << 15) + (q << 14) + Nid; + uint32_t s = lte_gold_generic(&x1, &x2, 1); + for (int i = 0; i < ((size >> 5) + ((size & 0x1f) > 0 ? 1 : 0)); i++) { simde__m256i c = ((simde__m256i*)in)[i]; - uint32_t in32 = simde_mm256_movemask_epi8(simde_mm256_slli_epi16(c,7)); - out[i]=(in32^s); + uint32_t in32 = simde_mm256_movemask_epi8(simde_mm256_slli_epi16(c, 7)); + out[i] = (in32 ^ s); DEBUG_SCRAMBLING(LOG_D(PHY, "in[%d] %x => %x\n", i, in32, out[i])); - s=lte_gold_generic(&x1, &x2, 0); + s = lte_gold_generic(&x1, &x2, 0); } } diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index 822153fd14..a3b5bb9eb2 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -775,8 +775,7 @@ int main(int argc, char *argv[]) uint8_t length_dmrs = pusch_len1; uint16_t l_prime_mask = get_l_prime(nb_symb_sch, mapping_type, add_pos, length_dmrs, start_symbol, NR_MIB__dmrs_TypeA_Position_pos2); - uint16_t number_dmrs_symbols = get_dmrs_symbols_in_slot(l_prime_mask, nb_symb_sch); - printf("num dmrs sym %d\n",number_dmrs_symbols); + uint16_t number_dmrs_symbols = get_dmrs_symbols_in_slot(l_prime_mask, nb_symb_sch, start_symbol); uint8_t nb_re_dmrs = (dmrs_config_type == pusch_dmrs_type1) ? 6 : 4; uint32_t tbslbrm = 0; @@ -804,8 +803,18 @@ int main(int argc, char *argv[]) nb_re_dmrs = nb_re_dmrs * num_dmrs_cdm_grps_no_data; unsigned int TBS = nr_compute_tbs(mod_order, code_rate, nb_rb, nb_symb_sch, nb_re_dmrs * number_dmrs_symbols, 0, 0, precod_nbr_layers); - printf("[ULSIM]: length_dmrs: %u, l_prime_mask: %u number_dmrs_symbols: %u, mapping_type: %u add_pos: %d \n", length_dmrs, l_prime_mask, number_dmrs_symbols, mapping_type, add_pos); - printf("[ULSIM]: CDM groups: %u, dmrs_config_type: %d, num_rbs: %u, nb_symb_sch: %u\n", num_dmrs_cdm_grps_no_data, dmrs_config_type, nb_rb, nb_symb_sch); + printf("[ULSIM]: length_dmrs: %u, l_prime_mask: %u number_dmrs_symbols: %u, mapping_type: %u add_pos: %d \n", + length_dmrs, + l_prime_mask, + number_dmrs_symbols, + mapping_type, + add_pos); + printf("[ULSIM]: CDM groups: %u, dmrs_config_type: %d, num_rbs: %u, nb_symb_sch: %u, start_symbol %u\n", + num_dmrs_cdm_grps_no_data, + dmrs_config_type, + nb_rb, + nb_symb_sch, + start_symbol); printf("[ULSIM]: MCS: %d, mod order: %u, code_rate: %u\n", Imcs, mod_order, code_rate); uint8_t ulsch_input_buffer[TBS/8]; diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c index aa1042491b..91c8b9b9c4 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c @@ -50,8 +50,14 @@ uint32_t nr_compute_tbs(uint16_t Qm, uint8_t tb_scaling, uint8_t Nl) { - - LOG_D(NR_MAC, "In %s: nb_symb_sch %d, nb_dmrs_prb %d, nb_rb %d, nb_rb_oh %d, tb_scaling %d Nl %d\n", __FUNCTION__, nb_symb_sch, nb_dmrs_prb, nb_rb, nb_rb_oh, tb_scaling, Nl); + LOG_D(NR_MAC, + "nb_symb_sch %d, nb_dmrs_prb %d, nb_rb %d, nb_rb_oh %d, tb_scaling %d Nl %d\n", + nb_symb_sch, + nb_dmrs_prb, + nb_rb, + nb_rb_oh, + tb_scaling, + Nl); const int nb_subcarrier_per_rb = 12; const uint32_t nbp_re = nb_subcarrier_per_rb * nb_symb_sch - nb_dmrs_prb - nb_rb_oh; @@ -91,10 +97,9 @@ uint32_t nr_compute_tbs(uint16_t Qm, } } - LOG_D(NR_MAC, "In %s: Ninfo %u nbp_re %d nb_re %d Qm %d, R %d, tbs %d bits\n", __FUNCTION__, Ninfo, nbp_re, nb_re, Qm, R, nr_tbs); + LOG_D(NR_MAC, "Ninfo %u nbp_re %d nb_re %d Qm %d, R %d, tbs %d bits\n", Ninfo, nbp_re, nb_re, Qm, R, nr_tbs); return nr_tbs; - } //tbslbrm calculation according to 5.4.2.1 of 38.212 diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c index b91da1152b..151cee026d 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c @@ -2473,25 +2473,26 @@ uint8_t getAntPortBitWidth(NR_SetupRelease_DMRS_DownlinkConfig_t *typeA, NR_Setu * *********************************************************************/ -uint8_t get_l0_ul(uint8_t mapping_type, uint8_t dmrs_typeA_position) { - +uint8_t get_l0_ul(uint8_t mapping_type, uint8_t dmrs_typeA_position) +{ return ((mapping_type==typeA)?dmrs_typeA_position:0); - } -int32_t get_l_prime(uint8_t duration_in_symbols, uint8_t mapping_type, pusch_dmrs_AdditionalPosition_t additional_pos, pusch_maxLength_t pusch_maxLength, uint8_t start_symbol, uint8_t dmrs_typeA_position) { - - uint8_t row, colomn; - int32_t l_prime; - - LOG_D(NR_MAC, "In %s: PUSCH NrofSymbols:%d, startSymbol:%d, mappingtype:%d, dmrs_TypeA_Position:%d additional_pos:%d, pusch_maxLength:%d\n", - __FUNCTION__, - duration_in_symbols, - start_symbol, - mapping_type, - dmrs_typeA_position, - additional_pos, - pusch_maxLength); +int32_t get_l_prime(uint8_t duration_in_symbols, + uint8_t mapping_type, + pusch_dmrs_AdditionalPosition_t additional_pos, + pusch_maxLength_t pusch_maxLength, + uint8_t start_symbol, + uint8_t dmrs_typeA_position) +{ + LOG_D(NR_MAC, + "PUSCH NrofSymbols:%d, startSymbol:%d, mappingtype:%d, dmrs_TypeA_Position:%d additional_pos:%d, pusch_maxLength:%d\n", + duration_in_symbols, + start_symbol, + mapping_type, + dmrs_typeA_position, + additional_pos, + pusch_maxLength); // Section 6.4.1.1.3 in Spec 38.211 // For PDSCH Mapping TypeA, ld is duration between first OFDM of the slot and last OFDM symbol of the scheduled PUSCH resources @@ -2499,16 +2500,18 @@ int32_t get_l_prime(uint8_t duration_in_symbols, uint8_t mapping_type, pusch_dmr uint8_t ld = (mapping_type == typeA) ? (duration_in_symbols + start_symbol) : duration_in_symbols; uint8_t l0 = (dmrs_typeA_position == NR_MIB__dmrs_TypeA_Position_pos2) ? 2 : 3 ; - colomn = additional_pos; + uint8_t colomn = additional_pos; if (mapping_type == typeB) colomn += 4; + uint8_t row; if (ld < 4) row = 0; else row = ld - 3; + uint32_t l_prime; if (pusch_maxLength == pusch_len1) { l_prime = table_6_4_1_1_3_3_pusch_dmrs_positions_l[row][colomn]; l0 = 1 << l0; @@ -2525,7 +2528,6 @@ int32_t get_l_prime(uint8_t duration_in_symbols, uint8_t mapping_type, pusch_dmr LOG_D(MAC, " PUSCH DMRS MASK in HEX:%x\n", l_prime); return l_prime; - } /*******************************************************************