From 89004ef241632dc526378a3366ea313b573f9492 Mon Sep 17 00:00:00 2001 From: francescomani Date: Mon, 25 Aug 2025 16:41:37 +0200 Subject: [PATCH 1/3] use common scale channel functions for DLSCH and ULSCH --- doc/SW_archi.md | 2 +- .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c | 52 +++------------- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 61 +------------------ .../PHY/nr_phy_common/inc/nr_phy_common.h | 1 + .../PHY/nr_phy_common/src/nr_phy_common.c | 27 ++++++++ 5 files changed, 37 insertions(+), 106 deletions(-) diff --git a/doc/SW_archi.md b/doc/SW_archi.md index 433a1ac3d1..9c3736ac2a 100644 --- a/doc/SW_archi.md +++ b/doc/SW_archi.md @@ -151,7 +151,7 @@ populates UL_INFO.uci_ind, actual uci data is in gNB->pucch {: .func4} * nr_ulsch_extract_rbs_single() {: .func4} - * nr_ulsch_scale_channel() + * nr_scale_channel() {: .func4} * nr_ulsch_channel_level() {: .func4} diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c index bd4ee92284..28f3e2cc67 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c @@ -159,42 +159,6 @@ static void nr_ulsch_extract_rbs(c16_t* const rxdataF, } } -static void nr_ulsch_scale_channel(int size_est, - int ul_ch_estimates_ext[][size_est], - NR_DL_FRAME_PARMS *frame_parms, - uint8_t symbol, - uint8_t is_dmrs_symbol, - uint32_t len, - uint8_t nrOfLayers, - unsigned short nb_rb, - int shift_ch_ext) -{ - // Determine scaling amplitude based the symbol - int b = 3; - short ch_amp = 1024 * 8; - if (shift_ch_ext > 3) { - b = 0; - ch_amp >>= (shift_ch_ext - 3); - if (ch_amp == 0) { - ch_amp = 1; - } - } else { - b -= shift_ch_ext; - } - simde__m128i ch_amp128 = simde_mm_set1_epi16(ch_amp); // Q3.13 - LOG_D(PHY, "Scaling PUSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n", symbol, ch_amp, is_dmrs_symbol, nb_rb, frame_parms->Ncp, symbol); - - for (int aatx = 0; aatx < nrOfLayers; aatx++) { - for (int aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) { - simde__m128i *ul_ch128 = (simde__m128i *)&ul_ch_estimates_ext[aatx * frame_parms->nb_antennas_rx + aarx][symbol * len]; - for (int i = 0; i < len >> 2; i++) { - ul_ch128[i] = simde_mm_mulhi_epi16(ul_ch128[i], ch_amp128); - ul_ch128[i] = simde_mm_slli_epi16(ul_ch128[i], b); - } - } - } -} - static int get_nb_re_pusch (NR_DL_FRAME_PARMS *frame_parms, nfapi_nr_pusch_pdu_t *rel15_ul,int symbol) { uint8_t dmrs_symbol_flag = (rel15_ul->ul_dmrs_symb_pos >> symbol) & 0x01; @@ -1375,15 +1339,13 @@ int nr_rx_pusch_tp(PHY_VARS_gNB *gNB, //---------------------------------------------------------- //--------------------- Channel Scaling -------------------- //---------------------------------------------------------- - nr_ulsch_scale_channel(size_est, - ul_ch_estimates_ext, - frame_parms, - meas_symbol, - (rel15_ul->ul_dmrs_symb_pos >> meas_symbol) & 0x01, - nb_re_pusch, - rel15_ul->nrOfLayers, - rel15_ul->rb_size, - shift_ch_ext); + nr_scale_channel(size_est, + ul_ch_estimates_ext, + meas_symbol, + nb_re_pusch, + rel15_ul->nrOfLayers, + frame_parms->nb_antennas_rx, + shift_ch_ext); int avg[frame_parms->nb_antennas_rx*rel15_ul->nrOfLayers]; nr_channel_level(meas_symbol, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index e281e1851d..10294bccb4 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -193,15 +193,6 @@ static void nr_dlsch_channel_compensation(uint32_t rx_size_symbol, unsigned char output_shift, PHY_NR_MEASUREMENTS *measurements); -void nr_dlsch_scale_channel(uint32_t rx_size_symbol, - int32_t dl_ch_estimates_ext[][rx_size_symbol], - NR_DL_FRAME_PARMS *frame_parms, - uint8_t n_tx, - uint8_t n_rx, - uint8_t symbol, - uint8_t pilots, - uint32_t len, - unsigned short nb_rb); static void nr_dlsch_detection_mrc(uint32_t rx_size_symbol, short nl, short n_rx, @@ -507,7 +498,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, //--------------------- Channel Scaling -------------------- //---------------------------------------------------------- start_meas_nr_ue_phy(ue, DLSCH_CHANNEL_SCALE_STATS); - nr_dlsch_scale_channel(rx_size_symbol, dl_ch_estimates_ext, frame_parms, nl, n_rx, symbol, pilots, nb_re_pdsch, nb_rb_pdsch); + nr_scale_channel(rx_size_symbol, dl_ch_estimates_ext, 0, nb_re_pdsch, nl, n_rx, 0); stop_meas_nr_ue_phy(ue, DLSCH_CHANNEL_SCALE_STATS); if (meas_enabled) { LOG_D(PHY, @@ -921,56 +912,6 @@ static void nr_dlsch_channel_compensation(uint32_t rx_size_symbol, } } -void nr_dlsch_scale_channel(uint32_t rx_size_symbol, - int32_t dl_ch_estimates_ext[][rx_size_symbol], - NR_DL_FRAME_PARMS *frame_parms, - uint8_t n_tx, - uint8_t n_rx, - uint8_t symbol, - uint8_t pilots, - uint32_t len, - unsigned short nb_rb) - -{ - - - short rb, ch_amp; - unsigned char aatx,aarx; - simde__m128i *dl_ch128, ch_amp128; - - uint32_t nb_rb_0 = len/12 + ((len%12)?1:0); - - // Determine scaling amplitude based the symbol - - ch_amp = 1024*8; //((pilots) ? (dlsch_ue[0]->sqrt_rho_b) : (dlsch_ue[0]->sqrt_rho_a)); - - LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol); - // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp); - - ch_amp128 = simde_mm_set1_epi16(ch_amp); // Q3.13 - - for (aatx=0; aatx 3) { + b = 0; + ch_amp >>= (shift_ch_ext - 3); + if (ch_amp == 0) { + ch_amp = 1; + } + } else { + b -= shift_ch_ext; + } + simde__m128i ch_amp128 = simde_mm_set1_epi16(ch_amp); // Q3.13 + LOG_D(PHY, "Scaling channel est in OFDM symbol %d by %d\n", symb, ch_amp); + + for (int l = 0; l < nrOfLayers; l++) { + for (int aarx = 0; aarx < nb_rx; aarx++) { + simde__m128i *ul_ch128 = (simde__m128i *)&ch_estimates_ext[l * nb_rx + aarx][symb * len]; + for (int i = 0; i < len >> 2; i++) { + ul_ch128[i] = simde_mm_mulhi_epi16(ul_ch128[i], ch_amp128); + ul_ch128[i] = simde_mm_slli_epi16(ul_ch128[i], b); + } + } + } +} void nr_fo_compensation(double fo_Hz, int samples_per_ms, int sample_offset, const c16_t *rxdata_in, c16_t *rxdata_out, int size) { From c88b7bac72955433e7a3d43c732514cc7405bb7c Mon Sep 17 00:00:00 2001 From: francescomani Date: Wed, 17 Sep 2025 09:40:50 +0200 Subject: [PATCH 2/3] process the remaining elements in scale channel --- openair1/PHY/nr_phy_common/src/nr_phy_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openair1/PHY/nr_phy_common/src/nr_phy_common.c b/openair1/PHY/nr_phy_common/src/nr_phy_common.c index cdc4e6f13a..aacabeed3b 100644 --- a/openair1/PHY/nr_phy_common/src/nr_phy_common.c +++ b/openair1/PHY/nr_phy_common/src/nr_phy_common.c @@ -445,10 +445,17 @@ void nr_scale_channel(int size, int ch_estimates_ext[][size], int symb, uint32_t for (int l = 0; l < nrOfLayers; l++) { for (int aarx = 0; aarx < nb_rx; aarx++) { simde__m128i *ul_ch128 = (simde__m128i *)&ch_estimates_ext[l * nb_rx + aarx][symb * len]; - for (int i = 0; i < len >> 2; i++) { + int loop_end = len >> 2; + for (int i = 0; i < loop_end; i++) { ul_ch128[i] = simde_mm_mulhi_epi16(ul_ch128[i], ch_amp128); ul_ch128[i] = simde_mm_slli_epi16(ul_ch128[i], b); } + // loop for the remaining elements + int start_index = loop_end * 4; + for (int j = start_index; j < len; j++) { + c16_t *temp = ((c16_t *)ul_ch128) + j; + *temp = c16Shift(*temp, b); + } } } } From 2bf7c2500e387c9afd34dae0e405e6341c575543 Mon Sep 17 00:00:00 2001 From: rmagueta Date: Thu, 18 Sep 2025 16:50:41 +0100 Subject: [PATCH 3/3] Simplifying bit shift in the nr_scale_channel() function --- .../PHY/nr_phy_common/src/nr_phy_common.c | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/openair1/PHY/nr_phy_common/src/nr_phy_common.c b/openair1/PHY/nr_phy_common/src/nr_phy_common.c index aacabeed3b..a723780f94 100644 --- a/openair1/PHY/nr_phy_common/src/nr_phy_common.c +++ b/openair1/PHY/nr_phy_common/src/nr_phy_common.c @@ -427,34 +427,18 @@ void nr_channel_level(const int symbol, void nr_scale_channel(int size, int ch_estimates_ext[][size], int symb, uint32_t len, int nrOfLayers, int nb_rx, int shift_ch_ext) { - // Determine scaling amplitude based the symbol - int b = 3; - short ch_amp = 1024 * 8; - if (shift_ch_ext > 3) { - b = 0; - ch_amp >>= (shift_ch_ext - 3); - if (ch_amp == 0) { - ch_amp = 1; - } - } else { - b -= shift_ch_ext; - } - simde__m128i ch_amp128 = simde_mm_set1_epi16(ch_amp); // Q3.13 - LOG_D(PHY, "Scaling channel est in OFDM symbol %d by %d\n", symb, ch_amp); - for (int l = 0; l < nrOfLayers; l++) { for (int aarx = 0; aarx < nb_rx; aarx++) { simde__m128i *ul_ch128 = (simde__m128i *)&ch_estimates_ext[l * nb_rx + aarx][symb * len]; int loop_end = len >> 2; for (int i = 0; i < loop_end; i++) { - ul_ch128[i] = simde_mm_mulhi_epi16(ul_ch128[i], ch_amp128); - ul_ch128[i] = simde_mm_slli_epi16(ul_ch128[i], b); + ul_ch128[i] = simde_mm_srai_epi16(ul_ch128[i], shift_ch_ext); } // loop for the remaining elements int start_index = loop_end * 4; for (int j = start_index; j < len; j++) { c16_t *temp = ((c16_t *)ul_ch128) + j; - *temp = c16Shift(*temp, b); + *temp = c16Shift(*temp, shift_ch_ext); } } }