lib: int_sqrt: add int64_sqrt routine
Subsystems (2)
PATCH v2 1/2 lib: int_sqrt: add int64_sqrt routine
From: Yibo Cai <[email protected]>
Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.
Cc Peter Meerwald <[email protected]>
Signed-off-by Yibo Cai <[email protected]>
Signed-off-by Barry Song <[email protected]>
---
-v2:
use CONFIG_64BIT MARCO
don't init for b, m
include/linux/kernel.h | 8 ++++++++ lib/int_sqrt.c | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/linux/kernel.h +8 -0
@@ -418,6 +418,14 @@ struct pid;extern struct pid *session_of_pgrp (struct pid *pgrp);unsigned long int_sqrt (unsigned long ); +#ifdef CONFIG_64BIT +static inline unsigned long long int64_sqrt (unsigned long long x) +{ +return int_sqrt (x); +} +#else +unsigned long long int64_sqrt (unsigned long long ); +#endif extern void bust_spinlocks (int yes);extern int oops_in_progress;/* If set, an oops, panic(), BUG() or die() is in progress */
lib/int_sqrt.c +25 -0
@@ -36,3 +36,28 @@ unsigned long int_sqrt(unsigned long x)return y; }EXPORT_SYMBOL (int_sqrt); + +#ifndef CONFIG_64BIT +unsigned long long int64_sqrt (unsigned long long x) +{ +unsigned long long b, m, y =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); +#endif
Signature · 1 line
1.9.3
Andrew Morton
maintainerQuoted 2 lines · On Thu, 3 Jul 2014 20:34:30 +0800 Barry Song <[email protected]> wrote:
Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.
Looks OK to me. Can this be carried in whatever tree holds the "CSR SiRFSoC touchscreen driver"?
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Thu, 3 Jul 2014 20:34:30 +0800 Barry Song <[email protected]> wrote:
Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.
Looks OK to me. Can this be carried in whatever tree holds the "CSR SiRFSoC touchscreen driver"?
Yeah, I'll pick it up.
Signature · 1 line
Dmitry