From d304865489a4ff2614dda5347325c27fb9695336 Mon Sep 17 00:00:00 2001 From: francescomani Date: Fri, 9 Aug 2024 12:29:13 +0200 Subject: [PATCH] fix for log2_approx to approximate to the nearest neighbor, instead of ceil --- openair1/PHY/TOOLS/log2_approx.c | 56 +++++++++++++------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/openair1/PHY/TOOLS/log2_approx.c b/openair1/PHY/TOOLS/log2_approx.c index acd1534857..5b4d069663 100644 --- a/openair1/PHY/TOOLS/log2_approx.c +++ b/openair1/PHY/TOOLS/log2_approx.c @@ -21,56 +21,46 @@ unsigned char log2_approx(unsigned int x) { + unsigned char l2 = 0; + unsigned int tmp = x >> 1; - int i; - unsigned char l2; + while (tmp) { + l2++; + tmp >>= 1; + } - l2=0; + if (l2) + l2 += (x >> (l2 - 1)) & 1; - for (i=0; i<31; i++) - if ((x&(1<> 1; - int i; - unsigned char l2; + while (tmp) { + l2++; + tmp >>= 1; + } - l2=0; + if (l2) + l2 += (x >> (l2 - 1)) & 1; - for (i=0; i<63; i++) - if ((x&(((long long int) 1)<