diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c index 4df7557495..d0a1dcd5de 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c @@ -129,17 +129,13 @@ void nr_polar_uxG(uint64_t *D, const uint64_t *u, const uint64_t **G_N_tab, uint int n_ones = 0; for (int a = 0; a < N_array; a++) { uint64_t uxG = u[a] & Gn[a]; - for (int m = 0; m < 64; m++) { - if (((uxG >> m) & 1) == 1) { - n_ones++; - } - } + if (uxG != 0) + n_ones += count_bits_set(uxG); } - uint64_t bit = n_ones % 2; int n1 = n >> 6; int n2 = n - (n1 << 6); - D[n1] |= bit << n2; + D[n1] |= ((uint64_t)n_ones & 1) << n2; } } diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h index 4f4af5f7cb..17c738b1fa 100644 --- a/openair1/PHY/TOOLS/tools_defs.h +++ b/openair1/PHY/TOOLS/tools_defs.h @@ -791,6 +791,11 @@ 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