This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Avoid stack references in inline assembly


On Tue, Jun 18, 2019 at 12:19:51PM +0200, Florian Weimer wrote:
> For example, on POWER, the condition register is used to indicate
> errors.  Instead of using that directly, we need to store that in a
> register, via mfcr:

Hrm, that example shows that my suggestion in
https://gcc.gnu.org/ml/gcc/2019-06/msg00170.html needs to be extended a
bit, for multiple return values.  We usually do extra return values for
builtins via an extra pointer; here, that cannot come as last argument
though, the call args are varargs.

So I suggested a generic builtin

  retval = __builtin_syscall (STYLE, syscall_nr, arg0, arg1, ...);

but that should for PowerPC syscalls be

  retval = __builtin_syscall (STYLE, &err, syscall_nr, arg0, arg1, ...);

Generically it it just

  retval = __builtin_syscall (STYLE, args...);

(or without retval, if the target decides this style call has no retval?)


> 0000000000000000 <__GI___getdents64>:
>    0:   addis   r2,r12,0
>                         0: R_PPC64_REL16_HA     .TOC.
>    4:   addi    r2,r2,0
>                         4: R_PPC64_REL16_LO     .TOC.+0x4
>    8:   li      r0,202
>    c:   sc      
>   10:   mfcr    r0

You also get this mfcr if the error code isn't used currently, even.  And
it uses mfcr always it seems, not mfocrf, or directly use the bit like in
a conditional branch insn or an isel or whatnot.

> Ideally, the mfcr, andis, beqlr instructions would just be a bclr
> instruction.

Yup.


Segher


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]