New calling convention gotham_call

2024-08-20 Thread Frederick Virchanza Gotham via Gcc
I want to write a new calling convention into the GNU g++ compiler,
specifically for the x86_64 instruction set.

On MS-Windows, the x64 calling convention puts the first argument in RCX,
and puts the return value in RAX. I wish to write a new calling convention
which uses RAX for both the first argument and the return value, to be used
as follows:

unsigned Func(unsigned const a) __attribute__((gotham_call))
{
return a * a;
}

Use of this new calling convention would shave a few CPU cycles off some
function invocations, as the above function which previously was compiled
to:

imul rcx, rcx
mov rax, rcx
ret

 would now be compiled to:

imul rax, rax
ret

Could someone please point me to the GNU compiler source files in which I
would add a new calling convention? I would appreciate a few pointers on
how to add a new calling convention to the GNU g++ compiler.


Re: New calling convention gotham_call

2024-08-20 Thread LIU Hao via Gcc

在 2024-08-20 16:13, Frederick Virchanza Gotham via Gcc 写道:

I want to write a new calling convention into the GNU g++ compiler,
specifically for the x86_64 instruction set.


The x64 calling convention is much more complex than x86. Each of the first four parameter is not 
only assigned an integer register, but also an SSE register (XMM0 - XMM3) and a shadow slot on the 
stack. The four shadow slots (32 bytes) must always be reserved by any caller, and are free for use 
as temporary storage like red zones on ARM64 or on Linux.


So by assigning a parameter to RAX you have to sacrifice another register. I don't see a point in 
doing that.


Not to mention that MOV can be implemented by register renaming which has a 
latency of zero.

--
Best regards,
LIU Hao


OpenPGP_signature.asc
Description: OpenPGP digital signature


Fwd: GCC arm target does not generate the correct code for adc patterns

2024-08-20 Thread coshvji cujmlqef via Gcc
It looks like GCC arm has not yet supported adc sbb for arm while clang
does.
https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html

clang:
https://godbolt.org/z/8q9djE7fr

gcc with aarch64 target:
https://godbolt.org/z/Wxcf6r7sP

gcc x86_64 correctly supports it while gcc arm does not:
https://godbolt.org/z/caYMTxMba

Can you fix it? Ty