From b5e9eb6f529b5741322d1981bb176785f115d446 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sun, 28 Apr 2013 11:47:43 -0300 Subject: [PATCH] [media] drxk_hard: don't re-implement log10 X-Patchwork-Delegate: mchehab@redhat.com Log10 routine is already defined at dvb_math.h and provides a good enough approximation for 100 x log10(). So, instead of reinventing the wheel, use the already existing function. While here, don't use CamelCase on the function name. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/drxk_hard.c | 104 ++---------------------- 1 file changed, 8 insertions(+), 96 deletions(-) diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c index ec24d71e153d..41b637534ed4 100644 --- a/drivers/media/dvb-frontends/drxk_hard.c +++ b/drivers/media/dvb-frontends/drxk_hard.c @@ -34,6 +34,7 @@ #include "dvb_frontend.h" #include "drxk.h" #include "drxk_hard.h" +#include "dvb_math.h" static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode); static int PowerDownQAM(struct drxk_state *state); @@ -201,98 +202,9 @@ static inline u32 Frac28a(u32 a, u32 c) return Q1; } -static u32 Log10Times100(u32 x) +static inline u32 log10times100(u32 value) { - static const u8 scale = 15; - static const u8 indexWidth = 5; - u8 i = 0; - u32 y = 0; - u32 d = 0; - u32 k = 0; - u32 r = 0; - /* - log2lut[n] = (1< 0; k--) { - if (x & (((u32) 1) << scale)) - break; - x <<= 1; - } - } else { - for (k = scale; k < 31; k++) { - if ((x & (((u32) (-1)) << (scale + 1))) == 0) - break; - x >>= 1; - } - } - /* - Now x has binary point between bit[scale] and bit[scale-1] - and 1.0 <= x < 2.0 */ - - /* correction for divison: log(x) = log(x/y)+log(y) */ - y = k * ((((u32) 1) << scale) * 200); - - /* remove integer part */ - x &= ((((u32) 1) << scale) - 1); - /* get index */ - i = (u8) (x >> (scale - indexWidth)); - /* compute delta (x - a) */ - d = x & ((((u32) 1) << (scale - indexWidth)) - 1); - /* compute log, multiplication (d* (..)) must be within range ! */ - y += log2lut[i] + - ((d * (log2lut[i + 1] - log2lut[i])) >> (scale - indexWidth)); - /* Conver to log10() */ - y /= 108853; /* (log2(10) << scale) */ - r = (y >> 1); - /* rounding */ - if (y & ((u32) 1)) - r++; - return r; + return (100L * intlog10(value)) >> 24; } /****************************************************************************/ @@ -2530,8 +2442,8 @@ static int GetQAMSignalToNoise(struct drxk_state *state, } if (qamSlErrPower > 0) { - qamSlMer = Log10Times100(qamSlSigPower) - - Log10Times100((u32) qamSlErrPower); + qamSlMer = log10times100(qamSlSigPower) - + log10times100((u32) qamSlErrPower); } *pSignalToNoise = qamSlMer; @@ -2620,12 +2532,12 @@ static int GetDVBTSignalToNoise(struct drxk_state *state, */ /* log(x) x = 9bits * 9bits->18 bits */ - a = Log10Times100(EqRegTdTpsPwrOfs * + a = log10times100(EqRegTdTpsPwrOfs * EqRegTdTpsPwrOfs); /* log(x) x = 16bits * 7bits->23 bits */ - b = Log10Times100(EqRegTdReqSmbCnt * tpsCnt); + b = log10times100(EqRegTdReqSmbCnt * tpsCnt); /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ - c = Log10Times100(SqrErrIQ); + c = log10times100(SqrErrIQ); iMER = a + b - c; } -- 2.30.2