[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YwYmpK40ju5WUlVZ@zn.tnic>
Date: Wed, 24 Aug 2022 15:24:52 +0200
From: Borislav Petkov <bp@...en8.de>
To: Vincent MAILHOL <mailhol.vincent@...adoo.fr>
Cc: Nick Desaulniers <ndesaulniers@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, x86@...nel.org,
Peter Zijlstra <peterz@...radead.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H . Peter Anvin" <hpa@...or.com>,
Nathan Chancellor <nathan@...nel.org>,
Tom Rix <trix@...hat.com>, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev, David Howells <dhowells@...hat.com>,
Jan Beulich <JBeulich@...e.com>,
Christophe Jaillet <christophe.jaillet@...adoo.fr>,
Joe Perches <joe@...ches.com>,
Josh Poimboeuf <jpoimboe@...nel.org>
Subject: Re: [PATCH v5 2/2] x86/asm/bitops: __ffs,ffz: use __builtin_ctzl to
evaluate constant expressions
On Wed, Aug 24, 2022 at 09:10:59PM +0900, Vincent MAILHOL wrote:
> Not exactly, this is TZCNT for x86_64 but for x86, it will be BSF…
Not x86 - some old models which do not understand TZCNT, I'm being told.
And I'm being also told, "Intel and AMD disagree on what BSF does when
passed 0". So this is more mess.
> It means that __ffs() is not a x86_64 specific function. Each
No, not that. The comment "Undefined if no bit exists".
On my machine, __ffs(0) - the way it is implemented:
rep; bsf %1,%0
is well-defined:
"If the input operand is zero, CF is set to 1 and the size (in bits) of
the input operand is written to the destination register. Otherwise, CF
is cleared."
Leading to
__ffs(0): 0x40
i.e., input operand of 64 bits.
So on this particular x86 implementation, TZCNT(0) is well defined.
So I'd like for that "undefined" thing to be expanded upon and
explained. Something along the lines of "the libc/compiler primitives'
*ffs(0) is undefined. Our inline asm helpers adhere to that behavior
even if the result they return for input operand of 0 is very well
defined."
Now, if there are some machines which do not adhere to the current hw
behavior, then they should be ALTERNATIVEd.
Better?
> > Back to your patch: I think the text should be fixed to say that both
> > ffs() and __ffs()'s kernel implementation doesn't have undefined results
>
> NACK. __ffs(0) is an undefined behaviour (c.f. TZCNT instruction for
NACK, SCHMACK. Read my mail again: "I think the text should be fixed".
The *text* - not __ffs(0) itself. The *text* should be fixed to explain
what undefined means. See above too.
IOW, to start explaining this humongous mess I've scratched the surface
of.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Powered by blists - more mailing lists