diff mbox series

[v1,2/4] lib/math/int_log: Use ARRAY_SIZE(logtable) where makes sense

Message ID 20230619172019.21457-3-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series ASoC: remove copy of intlog10() | expand

Commit Message

Andy Shevchenko June 19, 2023, 5:20 p.m. UTC
Use ARRAY_SIZE(logtable) where makes sense.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/math/int_log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mauro Carvalho Chehab July 3, 2023, 6:15 a.m. UTC | #1
Em Mon, 19 Jun 2023 20:20:17 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> escreveu:

> Use ARRAY_SIZE(logtable) where makes sense.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>

> ---
>  lib/math/int_log.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/math/int_log.c b/lib/math/int_log.c
> index 322df25a22d6..ea98fc0b3fe2 100644
> --- a/lib/math/int_log.c
> +++ b/lib/math/int_log.c
> @@ -91,7 +91,7 @@ unsigned int intlog2(u32 value)
>  	 *	so we would use the entry 0x18
>  	 */
>  	significand = value << (31 - msb);
> -	logentry = (significand >> 23) & 0xff;
> +	logentry = (significand >> 23) % ARRAY_SIZE(logtable);
>  
>  	/**
>  	 *	last step we do is interpolation because of the
> @@ -109,7 +109,7 @@ unsigned int intlog2(u32 value)
>  	 *	logtable_next is 256
>  	 */
>  	interpolation = ((significand & 0x7fffff) *
> -			((logtable[(logentry + 1) & 0xff] -
> +			((logtable[(logentry + 1) % ARRAY_SIZE(logtable)] -
>  			  logtable[logentry]) & 0xffff)) >> 15;
>  
>  	/* now we return the result */
diff mbox series

Patch

diff --git a/lib/math/int_log.c b/lib/math/int_log.c
index 322df25a22d6..ea98fc0b3fe2 100644
--- a/lib/math/int_log.c
+++ b/lib/math/int_log.c
@@ -91,7 +91,7 @@  unsigned int intlog2(u32 value)
 	 *	so we would use the entry 0x18
 	 */
 	significand = value << (31 - msb);
-	logentry = (significand >> 23) & 0xff;
+	logentry = (significand >> 23) % ARRAY_SIZE(logtable);
 
 	/**
 	 *	last step we do is interpolation because of the
@@ -109,7 +109,7 @@  unsigned int intlog2(u32 value)
 	 *	logtable_next is 256
 	 */
 	interpolation = ((significand & 0x7fffff) *
-			((logtable[(logentry + 1) & 0xff] -
+			((logtable[(logentry + 1) % ARRAY_SIZE(logtable)] -
 			  logtable[logentry]) & 0xffff)) >> 15;
 
 	/* now we return the result */