[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKv63usT8GU-51AmMLJb3hD3CHxf1M5KTQvYhK+0UVMT13Nbag@mail.gmail.com>
Date: Thu, 21 Dec 2017 14:17:43 +0100
From: Crt Mori <cmo@...exis.com>
To: David Laight <David.Laight@...lab.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Jonathan Cameron <jic23@...nel.org>,
Ingo Molnar <mingo@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Kees Cook <keescook@...omium.org>,
Rusty Russell <rusty@...tcorp.com.au>,
Ian Abbott <abbotti@....co.uk>,
Larry Finger <Larry.Finger@...inger.net>,
Niklas Soderlund <niklas.soderlund+renesas@...natech.se>,
Thomas Gleixner <tglx@...utronix.de>,
Krzysztof Kozlowski <krzk@...nel.org>,
Masahiro Yamada <yamada.masahiro@...ionext.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
Joe Perches <joe@...ches.com>
Subject: Re: [PATCH v10 1/3] lib: Add strongly typed 64bit int_sqrt
On 21 December 2017 at 12:43, David Laight <David.Laight@...lab.com> wrote:
> From: Crt Mori
>> Sent: 20 December 2017 17:30
>> I did a quick run through unit tests for the sensor and the results
>> are way off
>> ...
>
> Try this version instead:
> unsigned int sqrt64(unsigned long long x_in)
> {
> unsigned int x = x_in >> 32;
>
> unsigned int b = 0;
> unsigned int y = 0;
> unsigned int i;
i can be u8. And I will still use explicit typing.
>
> i = 31;
> if (!x) {
> x = x_in;
> i = 15;
> }
> if (!(x & 0xffff0000)) {
> x <<= 16;
> i -= 8;
> }
> if (!(x & 0xff000000)) {
> x <<= 8;
> i -= 4;
> }
> if (!(x & 0xf0000000)) {
> x <<= 4;
> i -= 2;
> }
>
This part above looks like FLS
> do {
> b <<= 2;
> b |= x >> 30;
> x <<= 2;
> if (i == 16)
> x = x_in;
> y <<= 1;
> if (b > y) {
> b -= ++y;
> y++;
> }
> } while (--i);
>
> /* 'b' becomes 33 bits if the input is greater than 2^62 */
> b <<= 1;
> b |= x >> 31;
> if (b > y || (b == y && x & (1u << 30)))
> y |= 1;
>
> return y;
> }
>
> I've tested that one with more values.
>
> David
>
This one indeed works. I did some more testing this morning and I am
fine with either.
So question is: Do I make change as per David's suggestion with his
sign-off, or leave the version it was before the change?
Powered by blists - more mailing lists