lkml.org 
[lkml]   [2019]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: fix int_sqrt() for very large numbers
On Sun, Jan 20, 2019 at 4:15 AM Florian La Roche
<florian.laroche@googlemail.com> wrote:
>
> @@ -52,7 +52,7 @@ u32 int_sqrt64(u64 x)
> if (x <= ULONG_MAX)
> return int_sqrt((unsigned long) x);
>
> - m = 1ULL << (fls64(x) & ~1ULL);
> + m = 1ULL << ((fls64(x) - 1) & ~1ULL);

I've applied this part of the patch as commit fbfaf851902c ("fix
int_sqrt64() for very large numbers") with slightly edited commit
log.

I still think there are some oddities in here in the types. I
mentioned the caller that unnecessarily does the int_sqrt64() twice,
even though the outer one doesn't actually take a 64-bit value.

But in the very line above, there's another type oddity: the "& ~1ULL"
is entirely the wrong type. The shift *count* shouldn't be an unsigned
long long, so that type doesn't make much sense. It should be just a
~1, or even just "62".

But I didn't actually start micro-editing the patch, and just did that
one-liner off-by-one fix.

Linus

\
 
 \ /
  Last update: 2019-01-21 08:25    [W:0.079 / U:0.760 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site