forked from shenki/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/math: move int_pow() from pwm_bl.c for wider use
The integer exponentiation is used in few places and might be used in the future by other call sites. Move it to wider use. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Andy Shevchenko <[email protected]> Cc: Daniel Thompson <[email protected]> Cc: Lee Jones <[email protected]> Cc: Ray Jui <[email protected]> Cc: Thierry Reding <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
4 changed files
with
34 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* An integer based power function | ||
* | ||
* Derived from drivers/video/backlight/pwm_bl.c | ||
*/ | ||
|
||
#include <linux/export.h> | ||
#include <linux/kernel.h> | ||
#include <linux/types.h> | ||
|
||
/** | ||
* int_pow - computes the exponentiation of the given base and exponent | ||
* @base: base which will be raised to the given power | ||
* @exp: power to be raised to | ||
* | ||
* Computes: pow(base, exp), i.e. @base raised to the @exp power | ||
*/ | ||
u64 int_pow(u64 base, unsigned int exp) | ||
{ | ||
u64 result = 1; | ||
|
||
while (exp) { | ||
if (exp & 1) | ||
result *= base; | ||
exp >>= 1; | ||
base *= base; | ||
} | ||
|
||
return result; | ||
} | ||
EXPORT_SYMBOL_GPL(int_pow); |