From: Peter Meerwald <pmeerw@pmeerw.net>
To: Barry Song <21cnbao@gmail.com>
Cc: dmitry.torokhov@gmail.com, dtor@mail.ru,
akpm@linux-foundation.org, linux-input@vger.kernel.org,
workgroup.linux@csr.com, Yibo Cai <yibo.cai@csr.com>,
Barry Song <Baohua.Song@csr.com>
Subject: Re: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine
Date: Mon, 23 Jun 2014 11:52:56 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.01.1406231150000.22151@pmeerw.net> (raw)
In-Reply-To: <1403516581-12560-2-git-send-email-21cnbao@gmail.com>
> Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC
> touchscreen driver needs it.
maybe the code could be #MACRO()'d to avoid duplication
see comment below
> 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;
initialization for b, m not needed
the original int_sqrt() code correctly skips initialization
> +
> + 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);
>
--
Peter Meerwald
+43-664-2444418 (mobile)
next prev parent reply other threads:[~2014-06-23 9:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-23 9:42 [PATCH 0/2] input: Add CSR SiRFSoC internal touchscreen driver Barry Song
2014-06-23 9:43 ` [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine Barry Song
2014-06-23 9:52 ` Peter Meerwald [this message]
2014-06-24 4:51 ` Yibo Cai
2014-06-24 6:15 ` Peter Meerwald
2014-06-24 20:25 ` Andrew Morton
2014-06-24 13:43 ` Elias Vanderstuyft
2014-06-23 9:43 ` [PATCH 2/2] input: sirfsoc_rs - add sirfsoc internal ADC-based touchscreen driver Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.01.1406231150000.22151@pmeerw.net \
--to=pmeerw@pmeerw.net \
--cc=21cnbao@gmail.com \
--cc=Baohua.Song@csr.com \
--cc=akpm@linux-foundation.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dtor@mail.ru \
--cc=linux-input@vger.kernel.org \
--cc=workgroup.linux@csr.com \
--cc=yibo.cai@csr.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).