mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 16:24:13 +08:00
aa6159ab99
kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out mathematical helpers. At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users. [sfr@canb.auug.org.au: fix powerpc build] Link: https://lkml.kernel.org/r/20201029150809.13059608@canb.auug.org.au Link: https://lkml.kernel.org/r/20201028173212.41768-1-andriy.shevchenko@linux.intel.com Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: "Paul E. McKenney" <paulmck@kernel.org> Cc: Trond Myklebust <trond.myklebust@hammerspace.com> Cc: Jeff Layton <jlayton@kernel.org> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
33 lines
629 B
C
33 lines
629 B
C
// 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/math.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);
|