[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgnGoj8qZg3SRh1Z1-mU=b3ryydXZykUuarnrAn6LuHBw@mail.gmail.com>
Date: Tue, 2 May 2023 09:00:06 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Dave Hansen <dave.hansen@...el.com>
Cc: "Kirill A. Shutemov" <kirill@...temov.name>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
linux-kernel@...r.kernel.org, kirill.shutemov@...ux.intel.com,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [GIT PULL] x86/mm for 6.4
On Tue, May 2, 2023 at 8:42 AM Dave Hansen <dave.hansen@...el.com> wrote:
>
> Have anyone seen any actual code generation difference between:
>
> return (long)ptr >= 0;
>
> and
>
> return !((unsigned long)ptr & (1UL<<(BITS_PER_LONG-1)));
No, as far as I know, they both generate the same code.
> It's longer, but I'd rather read the explicit "check bit 63" than the
> positive/negative address space thing. I certainly grok both, but have
> to think through the "(long)ptr >= 0" check every time.
I'm very much the other way. I think it's much clearer to say "check
the sign bit".
Doing the explicit bit check means that I have to look at what the bit
number is, and that is a much more complex expression.
In fact, I'd find it easier to read
return !((unsigned long)ptr & (1UL<< 63));
just because then you go "Oh, checking bit 63" without having to parse
the expression.
But even then I find the '!' is easy to miss, so you really have to parse it.
But:
> I guess it also wouldn't matter as much either if we hid it in a helper
> like the attached patch and I didn't have to read it twice. ;)
Yeah, I think that's a good solution.
Linus
Powered by blists - more mailing lists