public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* a small C (naive) program faster with clang than with gcc
@ 2023-04-24 15:33 Basile Starynkevitch
  2023-04-25 16:01 ` Andy
  0 siblings, 1 reply; 4+ messages in thread
From: Basile Starynkevitch @ 2023-04-24 15:33 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 676 bytes --]

Hello all,


Consider the naive program (GPLv3+) to solve the cryptaddition

`NEUF` + `DEUX` = `ONZE`

onhttps://github.com/bstarynk/misc-basile/blob/master/CryptArithm/neuf%2Bdeux%3Donze/naive0.c  (commit0d1bd0e 
<https://github.com/bstarynk/misc-basile/commit/0d1bd0ea8e2708036fcf126cc1f096be888360ab>)


On Linux/x86-64 that source code compiled with gcc-12 -O3 is twice as 
slower as with clang -O3

(Debian/Sid or Ubuntu/22/10)

Feel free to add it to some testsuite!


Thanks


-- 
Basile Starynkevitch<basile@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/ & refpersys.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a small C (naive) program faster with clang than with gcc
  2023-04-24 15:33 a small C (naive) program faster with clang than with gcc Basile Starynkevitch
@ 2023-04-25 16:01 ` Andy
  2023-04-26  2:45   ` LIU Hao
  2023-04-26  6:45   ` Gabriel Paubert
  0 siblings, 2 replies; 4+ messages in thread
From: Andy @ 2023-04-25 16:01 UTC (permalink / raw)
  To: Basile Starynkevitch; +Cc: gcc

I see it in godbolt
GCC compiles to:
movsx eax, BYTE PTR [rdi+2]
cmp al, 9
ja .L42
Clang:
movzx edx, byte ptr [rdi + 2]
cmp edx, 9
ja .LBB0_40


GCC extend with sign, Clang with zero.
cmp with 32 bit register is apparently faster than 8bit

pon., 24 kwi 2023 o 17:34 Basile Starynkevitch
<basile@starynkevitch.net> napisał(a):
>
> Hello all,
>
>
> Consider the naive program (GPLv3+) to solve the cryptaddition
>
> `NEUF` + `DEUX` = `ONZE`
>
> onhttps://github.com/bstarynk/misc-basile/blob/master/CryptArithm/neuf%2Bdeux%3Donze/naive0.c  (commit0d1bd0e
> <https://github.com/bstarynk/misc-basile/commit/0d1bd0ea8e2708036fcf126cc1f096be888360ab>)
>
>
> On Linux/x86-64 that source code compiled with gcc-12 -O3 is twice as
> slower as with clang -O3
>
> (Debian/Sid or Ubuntu/22/10)
>
> Feel free to add it to some testsuite!
>
>
> Thanks
>
>
> --
> Basile Starynkevitch<basile@starynkevitch.net>
> (only mine opinions / les opinions sont miennes uniquement)
> 92340 Bourg-la-Reine, France
> web page: starynkevitch.net/Basile/ & refpersys.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a small C (naive) program faster with clang than with gcc
  2023-04-25 16:01 ` Andy
@ 2023-04-26  2:45   ` LIU Hao
  2023-04-26  6:45   ` Gabriel Paubert
  1 sibling, 0 replies; 4+ messages in thread
From: LIU Hao @ 2023-04-26  2:45 UTC (permalink / raw)
  To: Andy, Basile Starynkevitch; +Cc: gcc


[-- Attachment #1.1: Type: text/plain, Size: 648 bytes --]

在 2023/4/26 00:01, Andy via Gcc 写道:
> I see it in godbolt
> GCC compiles to:
> movsx eax, BYTE PTR [rdi+2]
> cmp al, 9
> ja .L42
> Clang:
> movzx edx, byte ptr [rdi + 2]
> cmp edx, 9
> ja .LBB0_40
> 
> 
> GCC extend with sign, Clang with zero.
> cmp with 32 bit register is apparently faster than 8bit

As for extension, it seems to make a difference only if the result is ever written back to memory. 
And for comparison, it makes completely no difference whether the operand is 32-bit or 8-bit, except 
when the operand is an 8-bit ?H register. [1]


[1] https://uops.info/table.html


-- 
Best regards,
LIU Hao


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: a small C (naive) program faster with clang than with gcc
  2023-04-25 16:01 ` Andy
  2023-04-26  2:45   ` LIU Hao
@ 2023-04-26  6:45   ` Gabriel Paubert
  1 sibling, 0 replies; 4+ messages in thread
From: Gabriel Paubert @ 2023-04-26  6:45 UTC (permalink / raw)
  To: Andy; +Cc: Basile Starynkevitch, gcc

On Tue, Apr 25, 2023 at 06:01:22PM +0200, Andy via Gcc wrote:
> I see it in godbolt
> GCC compiles to:
> movsx eax, BYTE PTR [rdi+2]
> cmp al, 9
> ja .L42
> Clang:
> movzx edx, byte ptr [rdi + 2]
> cmp edx, 9
> ja .LBB0_40
> 
> 
> GCC extend with sign, Clang with zero.
> cmp with 32 bit register is apparently faster than 8bit

What happens if you compile with -funsigned-char?

There may be also some alignment issue, after all cmp al,9 is 2 bytes
while cmp edx,9 is 6.

	Gabriel

> 
> pon., 24 kwi 2023 o 17:34 Basile Starynkevitch
> <basile@starynkevitch.net> napisał(a):
> >
> > Hello all,
> >
> >
> > Consider the naive program (GPLv3+) to solve the cryptaddition
> >
> > `NEUF` + `DEUX` = `ONZE`
> >
> > onhttps://github.com/bstarynk/misc-basile/blob/master/CryptArithm/neuf%2Bdeux%3Donze/naive0.c  (commit0d1bd0e
> > <https://urldefense.com/v3/__https://github.com/bstarynk/misc-basile/commit/0d1bd0ea8e2708036fcf126cc1f096be888360ab__;!!D9dNQwwGXtA!TTyEodY6pBOA7p844eEtBYxzayqn8ZjEYjc-4GVTZaYJTYVSspXkfjZTE1oDYSJzVhSTOYPQbo8$ >)
> >
> >
> > On Linux/x86-64 that source code compiled with gcc-12 -O3 is twice as
> > slower as with clang -O3
> >
> > (Debian/Sid or Ubuntu/22/10)
> >
> > Feel free to add it to some testsuite!
> >
> >
> > Thanks
> >
> >
> > --
> > Basile Starynkevitch<basile@starynkevitch.net>
> > (only mine opinions / les opinions sont miennes uniquement)
> > 92340 Bourg-la-Reine, France
> > web page: starynkevitch.net/Basile/ & refpersys.org



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-26  6:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 15:33 a small C (naive) program faster with clang than with gcc Basile Starynkevitch
2023-04-25 16:01 ` Andy
2023-04-26  2:45   ` LIU Hao
2023-04-26  6:45   ` Gabriel Paubert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).