From: Yibo Cai <redacted>
Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC
touchscreen driver needs it.
Signed-off-by: Yibo Cai <redacted>
Signed-off-by: Barry Song <redacted>
---
include/linux/kernel.h | 1 +
lib/int_sqrt.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4c52907..6e63081 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -418,6 +418,7 @@ struct pid;
extern struct pid *session_of_pgrp(struct pid *pgrp);
unsigned long int_sqrt(unsigned long);
+unsigned long long int64_sqrt(unsigned long long);
extern void bust_spinlocks(int yes);
extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c
index 1ef4cc3..2aa9fcc 100644
--- a/lib/int_sqrt.c
+++ b/lib/int_sqrt.c
@@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x)
return y;
}
EXPORT_SYMBOL(int_sqrt);
+
+/*
+ * Square root of a 64-bit digit.
+ * Same as int_sqrt on 64-bit platforms where "long" equals "long long"
+ */
+unsigned long long int64_sqrt(unsigned long long x)
+{
+ unsigned long long m = 0, y = 0, b = 0;
+
+ if (x <= 1)
+ return x;
+
+ m = 1ULL << (BITS_PER_LONG_LONG - 2);
+ while (m != 0) {
+ b = y + m;
+ y >>= 1;
+
+ if (x >= b) {
+ x -= b;
+ y += m;
+ }
+ m >>= 2;
+ }
+
+ return y;
+}
+EXPORT_SYMBOL(int64_sqrt);--
1.9.3