summaryrefslogtreecommitdiff
path: root/lib/math/int_pow.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2019-05-16 09:04:48 +0200
committerIngo Molnar <mingo@kernel.org>2019-05-16 09:04:48 +0200
commit00f5764dbb040188e5dce2cd9e648360886b045c (patch)
tree2dc969bb165a27a7cebdd1798b7a697243a790de /lib/math/int_pow.c
parent409ca45526a428620d8efb362ccfd4b1e6b80642 (diff)
parent5ac94332248ee017964ba368cdda4ce647e3aba7 (diff)
Merge branch 'linus' into x86/urgent, to pick up dependent changes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'lib/math/int_pow.c')
-rw-r--r--lib/math/int_pow.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/math/int_pow.c b/lib/math/int_pow.c
new file mode 100644
index 000000000000..622fc1ab3c74
--- /dev/null
+++ b/lib/math/int_pow.c
@@ -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);