[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=whVvD05T0yD5DQj803uETLD6qDq-Vx-SiLPcrL=eO77LQ@mail.gmail.com>
Date: Fri, 25 Aug 2023 13:43:15 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Helge Deller <deller@....de>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>
Cc: linux-kernel@...r.kernel.org, linux-parisc@...r.kernel.org,
Andrew Morton <akpm@...ux-foundation.org>,
Chanho Min <chanho.min@....com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH] lib/clz_ctz.c: Fix __clzdi2() and __ctzdi2() for 32-bit kernels
[ Unrelated to this patch, except it made me look, adding clang build
people to cc ]
On Fri, 25 Aug 2023 at 13:25, Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Fri, 25 Aug 2023 at 12:50, Helge Deller <deller@....de> wrote:
> >
> > This patch fixes the in-kernel functions __clzdi2() and __ctzdi2() [..]
>
> Applied,
Bah. Still applied, but actually building this (on 64-bit, so kind of
pointless) I note that clang completely messes up this function on
x86.
Clang turns this:
return __ffs64(val);
into this horror:
pushq %rax
movq %rdi, (%rsp)
#APP
rep
bsfq (%rsp), %rax
#NO_APP
popq %rcx
which is just incredibly broken on so many levels. It *should* be a
single instruction, like gcc does:
rep; bsf %rdi,%rax # tmp87, word
but clang decides that it really wants to put the argument on the
stack, and apparently also wants to do that nonsensical stack
alignment thing to make things even worse.
We use this:
static __always_inline unsigned long variable__ffs(unsigned long word)
{
asm("rep; bsf %1,%0"
: "=r" (word)
: "rm" (word));
return word;
}
for the definition, and it looks like clang royally just screws up
here. Yes, "m" is _allowed_ in that input set, but it damn well
shouldn't be used for something that is already in a register, since
"r" is also allowed, and is the first choice.
I think it's this clang bug:
https://github.com/llvm/llvm-project/issues/20571
https://github.com/llvm/llvm-project/issues/30873
https://github.com/llvm/llvm-project/issues/34837
and it doesn't matter for *this* case (since I don't think this
library function is ever used on x86), but it looks like a generic
clang issue.
Linus
Powered by blists - more mailing lists