* [PATCH 1/2 v2] lib: int_sqrt: add int64_sqrt routine
@ 2014-07-03 12:34 Barry Song
2014-07-08 21:55 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Barry Song @ 2014-07-03 12:34 UTC (permalink / raw)
To: dmitry.torokhov, dtor, akpm
Cc: linux-input, workgroup.linux, Yibo Cai, Peter Meerwald,
Barry Song
From: Yibo Cai <yibo.cai@csr.com>
Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC
touchscreen driver needs it.
Cc: Peter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: Yibo Cai <yibo.cai@csr.com>
Signed-off-by: Barry Song <Baohua.Song@csr.com>
---
-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(+)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4c52907..a536c0c 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -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 */
diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c
index 1ef4cc3..b86cccb 100644
--- a/lib/int_sqrt.c
+++ b/lib/int_sqrt.c
@@ -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
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2 v2] lib: int_sqrt: add int64_sqrt routine
2014-07-03 12:34 [PATCH 1/2 v2] lib: int_sqrt: add int64_sqrt routine Barry Song
@ 2014-07-08 21:55 ` Andrew Morton
2014-07-08 22:12 ` Dmitry Torokhov
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2014-07-08 21:55 UTC (permalink / raw)
To: Barry Song
Cc: dmitry.torokhov, dtor, linux-input, workgroup.linux, Yibo Cai,
Peter Meerwald, Barry Song
On Thu, 3 Jul 2014 20:34:30 +0800 Barry Song <21cnbao@gmail.com> 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"?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2 v2] lib: int_sqrt: add int64_sqrt routine
2014-07-08 21:55 ` Andrew Morton
@ 2014-07-08 22:12 ` Dmitry Torokhov
0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2014-07-08 22:12 UTC (permalink / raw)
To: Andrew Morton
Cc: Barry Song, linux-input, workgroup.linux, Yibo Cai,
Peter Meerwald, Barry Song
On Tue, Jul 08, 2014 at 02:55:01PM -0700, Andrew Morton wrote:
> On Thu, 3 Jul 2014 20:34:30 +0800 Barry Song <21cnbao@gmail.com> 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.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-08 22:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-03 12:34 [PATCH 1/2 v2] lib: int_sqrt: add int64_sqrt routine Barry Song
2014-07-08 21:55 ` Andrew Morton
2014-07-08 22:12 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).