Commit e0800d42 authored by Jaroslava Fiedlerova's avatar Jaroslava Fiedlerova

Merge remote-tracking branch 'origin/fix_log2_approx' into integration_2024_w39

parents 4093a485 1b97cdaf
......@@ -1682,15 +1682,13 @@ int nr_rx_pusch_tp(PHY_VARS_gNB *gNB,
for (int nl = 0; nl < rel15_ul->nrOfLayers; nl++)
for (int aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
avgs = cmax(avgs, avg[nl * frame_parms->nb_antennas_rx + aarx]);
pusch_vars->log2_maxh = (log2_approx(avgs) >> 1);
avgs = cmax(avgs, avg[nl * frame_parms->nb_antennas_rx + aarx]);
if (rel15_ul->nrOfLayers == 2 && rel15_ul->qam_mod_order >= 6)
pusch_vars->log2_maxh = (log2_approx(avgs) >> 1) - 3; // for MMSE
else if (rel15_ul->nrOfLayers == 1)
pusch_vars->log2_maxh = (log2_approx(avgs) >> 1) + 1 + log2_approx(frame_parms->nb_antennas_rx >> 2);
else
pusch_vars->log2_maxh = (log2_approx(avgs) >> 1) + 1 + log2_approx(frame_parms->nb_antennas_rx >> 1);
if (pusch_vars->log2_maxh < 0)
pusch_vars->log2_maxh = 0;
......
......@@ -509,9 +509,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
int32_t median[MAX_ANT][MAX_ANT];
for (int aatx = 0; aatx < nl; aatx++)
for (int aarx = 0; aarx < n_rx; aarx++) {
// LOG_I(PHY, "nb_rb %d len %d avg_%d_%d Power per SC is %d\n",nb_rb, len,aarx, aatx,avg[aatx*n_rx+aarx]);
avgs = cmax(avgs, avg[aatx][aarx]);
// LOG_I(PHY, "avgs Power per SC is %d\n", avgs);
LOG_D(PHY, "nb_rb %d avg_%d_%d Power per SC is %d\n", nb_rb_pdsch, aarx, aatx, avg[aatx][aarx]);
LOG_D(PHY, "avgs Power per SC is %d\n", avgs);
median[aatx][aarx] = avg[aatx][aarx];
}
if (nl > 1) {
......@@ -523,7 +523,6 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
}
}
*log2_maxh = (log2_approx(avgs) / 2) + 1;
// LOG_I(PHY, "avgs Power per SC is %d lg2_maxh %d\n", avgs, log2_maxh);
LOG_D(PHY, "[DLSCH] AbsSubframe %d.%d log2_maxh = %d (%d)\n", frame % 1024, nr_slot_rx, *log2_maxh, avgs);
}
stop_meas_nr_ue_phy(ue, DLSCH_CHANNEL_LEVEL_STATS);
......@@ -1099,10 +1098,9 @@ void nr_dlsch_channel_level(uint32_t rx_size_symbol,
simde__m128i *dl_ch128, avg128D;
//nb_rb*nre = y * 2^x
int16_t x = factor2(len);
int16_t y = (len)>>x;
LOG_D(NR_PHY, "%s: %d = %d * 2^(%d)\n", __func__, len, y, x);
int16_t y = (len) >> x;
uint32_t nb_rb_0 = len / NR_NB_SC_PER_RB + ((len % NR_NB_SC_PER_RB) ? 1 : 0);
LOG_D(NR_PHY, "nb_rb_0 %d len %d = %d * 2^(%d)\n", nb_rb_0, len, y, x);
for (int aatx = 0; aatx < n_tx; aatx++) {
for (int aarx = 0; aarx < n_rx; aarx++) {
//clear average level
......@@ -1118,7 +1116,7 @@ void nr_dlsch_channel_level(uint32_t rx_size_symbol,
}
int32_t *tmp = (int32_t *)&avg128D;
avg[aatx][aarx] = ((int64_t)tmp[0] + tmp[1] + tmp[2] + tmp[3]) / y;
// printf("Channel level : %d\n",avg[(aatx<<1)+aarx]);
LOG_D(PHY, "Channel level: %d\n", avg[aatx][aarx]);
}
}
}
......@@ -1152,7 +1150,7 @@ static void nr_dlsch_channel_level_median(uint32_t rx_size_symbol,
}
median[aatx][aarx] = (max + min) >> 1;
//printf("Channel level median [%d]: %d max = %d min = %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx],max,min);
LOG_D(PHY, "Channel level median [%d][%d]: %d max = %ld min = %ld\n", aatx, aarx, median[aatx][aarx], max, min);
}
}
}
......
......@@ -19,58 +19,48 @@
* contact@openairinterface.org
*/
#include <simde/x86/avx512/lzcnt.h>
unsigned char log2_approx(unsigned int x)
{
const unsigned int round_val = 3037000499U; // 2^31.5
if (!x)
return 0;
int i;
unsigned char l2;
l2=0;
for (i=0; i<31; i++)
if ((x&(1<<i)) != 0)
l2 = i+1;
int l2 = simde_x_clz32(x);
if (x > (round_val >> l2))
l2 = 32 - l2;
else
l2 = 31 - l2;
//l2 = i;
// printf("log2_approx = %d\n",l2);
return(l2);
return l2;
}
unsigned char factor2(unsigned int x)
{
unsigned char l2 = 0;
int i;
unsigned char l2;
l2=0;
for (i=0; i<31; i++)
if ((x&(1<<i)) != 0)
for (i = 0; i < 31; i++)
if ((x & (1 << i)) != 0)
break;
l2 = i;
//printf("factor2(%d) = %d\n",x,l2);
return(l2);
return l2;
}
unsigned char log2_approx64(unsigned long long int x)
{
const unsigned long long round_val = 13043817825332782212ULL; // 2^63.5
if (!x)
return 0;
int i;
unsigned char l2;
l2=0;
for (i=0; i<63; i++)
if ((x&(((long long int) 1)<<i)) != 0)
// l2 = i+1;
l2 = i;
int l2 = simde_x_clz64(x);
if (x > (round_val >> l2))
l2 = 64 - l2;
else
l2 = 63 - l2;
// printf("log2_approx = %d\n",l2);
return(l2);
return l2;
}
......@@ -9,3 +9,9 @@ target_link_libraries(benchmark_rotate_vector PRIVATE benchmark::benchmark UTIL
add_dependencies(tests benchmark_rotate_vector)
add_test(NAME benchmark_rotate_vector
COMMAND ./benchmark_rotate_vector)
add_executable(test_log2_approx test_log2_approx.cpp ../log2_approx.c)
target_link_libraries(test_log2_approx PRIVATE GTest::gtest LOG minimal_lib)
add_dependencies(tests test_log2_approx)
add_test(NAME test_log2_approx
COMMAND ./test_log2_approx)
#include <gtest/gtest.h>
extern "C" {
#include "openair1/PHY/TOOLS/tools_defs.h"
#include "common/utils/LOG/log.h"
}
#include <cmath>
uint8_t log2_approx_ref(uint32_t x)
{
return std::round(std::log2(x));
}
uint8_t log2_approx64_ref(unsigned long long int x)
{
return std::round(std::log2(static_cast<long double>(x)));
}
TEST(log2_approx, complete)
{
for (uint32_t i = 0; i < UINT32_MAX; i++)
EXPECT_EQ(log2_approx(i), log2_approx_ref(i));
}
TEST(log2_approx64, boundaries)
{
for (long double i = 0; i < 64; i++) {
unsigned long long i2 = std::pow(2.0L, i + 0.5L);
for (unsigned long long j = -10; j <= 10; j++) {
unsigned long long x = i2 + j;
EXPECT_EQ(log2_approx64(x), log2_approx64_ref(x));
}
}
}
int main(int argc, char **argv)
{
logInit();
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -46,8 +46,8 @@ void nr_qpsk_llr(int32_t *rxdataF_comp, int16_t *llr, uint32_t nb_re)
c16_t *rxF = (c16_t *)rxdataF_comp;
c16_t *llr32 = (c16_t *)llr;
for (int i = 0; i < nb_re; i++) {
llr32[i].r = rxF[i].r >> 3;
llr32[i].i = rxF[i].i >> 3;
llr32[i].r = rxF[i].r >> 4;
llr32[i].i = rxF[i].i >> 4;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment