[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFULd4Y-gr+UAvi4m1-p4MnJyMv3NRcyH=TFLZfFfNngnE_Kpw@mail.gmail.com>
Date: Tue, 29 Apr 2025 18:31:33 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: X86 ML <x86@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
Andy Lutomirski <luto@...nel.org>, Ingo Molnar <mingo@...nel.org>, Nadav Amit <namit@...are.com>,
Brian Gerst <brgerst@...il.com>, Denys Vlasenko <dvlasenk@...hat.com>,
"H . Peter Anvin" <hpa@...or.com>, Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>, Borislav Petkov <bp@...en8.de>, Josh Poimboeuf <jpoimboe@...hat.com>
Subject: Re: [RFC PATCH 0/4] x86/percpu: Use segment qualifiers
[Dead thread resurrection]
On Sun, Oct 1, 2023 at 10:21 PM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
> And indeed, the *very* first thing I tried shows that this is all very
> very buggy in gcc.
>
> What did I try? A simple memory copy with a structure assignment.
>
> Try to compile this:
>
> #include <string.h>
> struct a { long arr[30]; };
>
> __seg_fs struct a m;
> void foo(struct a *dst) { *dst = m; }
>
> using the kernel compiler options (it's the "don't use sse/avx" ones
> that matter):
>
> gcc -mno-avx -mno-sse -O2 -S t.c
>
> and look at the end result. It's complete and utter sh*t:
>
> foo:
> xorl %eax, %eax
> cmpq $240, %rax
> jnb .L5
> .L2:
> movzbl %fs:m(%rax), %edx
> movb %dl, (%rdi,%rax)
> addq $1, %rax
> cmpq $240, %rax
> jb .L2
> .L5:
> ret
>
> to the point that I can only go "WTF"?
>
> I mean, it's not just that it does the copy one byte at a time. It
> literally compares %rax to $240 just after it has cleared it. I look
> at that code, and I go "a five-year old with a crayon could have done
> better".
>
> In other words, no, we're not using this thing that generates that
> kind of garbage.
>
> Somebody needs to open a bugzilla entry for this kind of code generation.
FYI, after GCC PR 111657 [1] was fixed, gcc-16 will generate the following code:
foo:
movl $m, %esi
movl $30, %ecx
rep movsq %fs:(%rsi), (%rdi)
ret
And adding -mtune=skylake:
foo:
movl $m, %esi
movl $240, %ecx
rep movsb %fs:(%rsi), (%rdi)
ret
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111657
Uros.
Powered by blists - more mailing lists