Re: Calling conventions (particularly 32-bit ARM)

Liste des GroupesRevenir à c arch 
Sujet : Re: Calling conventions (particularly 32-bit ARM)
De : mitchalsup (at) *nospam* aol.com (MitchAlsup1)
Groupes : comp.arch
Date : 06. Jan 2025, 21:19:15
Autres entêtes
Organisation : Rocksolid Light
Message-ID : <e13143b28c4d607a979c9c2ccf22f047@www.novabbs.org>
References : 1 2
User-Agent : Rocksolid Light
On Mon, 6 Jan 2025 15:32:04 +0000, Anton Ertl wrote:

David Brown <david.brown@hesbynett.no> writes:
But the ABI only allows returning a single 32-bit value in R0, or a
scalar 64-bit value in R0:R1.  If a function returns a non-scalar that
is larger than 32-bit, the caller has to allocate space on the stack for
the return type and pass a pointer to that space in R0.
>
To my mind, this is massively inefficient, especially when using structs
that are made up of two 32-bit parts.
>
Is there any good reason why the ABI is designed with such limited
register usage for returns?
>
Most calling conventions on RISCs are oriented towards C (if you want
calling conventions that try to be more cross-language (and slower),
look at VAX) and its properties and limitations at the time when the
calling convention was designed, in particular, the PCC
implementation, which was the de-facto standard Unix C compiler at the
time.  C compilers in the 1980s did not allocate structs to registers,
so passing structs in registers was foreign to them, so the solution
is that the caller passes the target struct as an additional
parameter.
>
And passing the return value in registers might not have saved
anything on a compiler that does not deal with structs in registers.
E.g., if you have
>
mystruct = myfunc(arg1, arg2);
>
you would see stores to mystruct behind the call.  With the PCC
calling convention, the same stores would happen in the caller
(possibly resulting in smaller code if there are several calls to
myfunc()).
>
I wonder, though, how things look for
>
mystruct = foo(&mystruct);
>
Does PCC perform the return stores to mystruct only after performing
all other memory accesses in foo?  Probably yes, anything else would
complicate the compiler.  In that case the caller could pass &mystruct
for the return value (a slight complication).  But is that restriction
reflected in the calling convention?
For VERY MANY circumstances passing a struct by address is more
efficient than passing it by value, AND especially when the
compiler does not optimize heavily.

Struct returns were (and AFAIK still are, many decades after
they were added to C) a relatively rarely used feature, so Johnson
(PCC's author) probably did not want to waste a lot of effort on
making it more efficient.
In addition, the programmer has the choice of changing into pointer
form (&struct) from value form (struct) which is what we learned
was better style way back then.
--------------------------

I also think code would be a bit more efficient if there more registers
available for parameter passing and as scratch registers - perhaps 6
would make more sense.
>
There is a tendency towards passing more parameters in registers in
more recent calling conventions.  IA-32 (and IIRC VAX) passes none,
MIPS uses 4 integer registers (for either integer or FP parameters),
Alpha uses 6 integer and 6 FP registers, AMD64's System V ABI 6
integer and 8 FP registers, ARM A64 has 8 integer and 8 FP registers,
RISC-V has 8 integer and 8 FP registers.  Not sure why they were so
reluctant to use more registers earlier.
Compiler people were telling us that more callee saved registers would
be higher performing than more argument registers. It did not turn out
to be that way.
Oh and BTW, lack of argument registers leads to an increased
desire for the linker to perform inline folding. ...

>
- anton

Date Sujet#  Auteur
6 Jan 25 * Calling conventions (particularly 32-bit ARM)81David Brown
6 Jan 25 +* Re: Calling conventions (particularly 32-bit ARM)2Theo
7 Jan 25 i`- Re: Calling conventions (particularly 32-bit ARM)1David Brown
6 Jan 25 +* Re: Calling conventions (particularly 32-bit ARM)8Anton Ertl
6 Jan 25 i+* Re: Calling conventions (particularly 32-bit ARM)6MitchAlsup1
7 Jan 25 ii`* Re: Calling conventions (particularly 32-bit ARM)5David Brown
8 Jan 25 ii `* Re: Calling conventions (particularly 32-bit ARM)4MitchAlsup1
8 Jan 25 ii  +* Re: Calling conventions (particularly 32-bit ARM)2Chris M. Thomasson
8 Jan 25 ii  i`- Re: Calling conventions (particularly 32-bit ARM)1Chris M. Thomasson
8 Jan 25 ii  `- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
7 Jan 25 i`- Re: Calling conventions (particularly 32-bit ARM)1David Brown
6 Jan 25 `* Re: Calling conventions (particularly 32-bit ARM)70MitchAlsup1
7 Jan 25  +* Re: Calling conventions (particularly 32-bit ARM)18Waldek Hebisch
7 Jan 25  i+- Re: Calling conventions (particularly 32-bit ARM)1Lawrence D'Oliveiro
12 Jan 25  i`* Re: Calling conventions (particularly 32-bit ARM)16Stephen Fuld
12 Jan 25  i +- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
13 Jan 25  i +* Re: Calling conventions (particularly 32-bit ARM)11Waldek Hebisch
14 Jan 25  i i`* Re: Calling conventions (particularly 32-bit ARM)10Stephen Fuld
14 Jan 25  i i `* Re: Calling conventions (particularly 32-bit ARM)9Terje Mathisen
14 Jan 25  i i  `* Re: Calling conventions (particularly 32-bit ARM)8Michael S
15 Jan 25  i i   `* Re: Calling conventions (particularly 32-bit ARM)7MitchAlsup1
15 Jan 25  i i    +* Re: Calling conventions (particularly 32-bit ARM)3John Levine
15 Jan 25  i i    i`* Re: Calling conventions (particularly 32-bit ARM)2MitchAlsup1
15 Jan 25  i i    i `- Re: Calling conventions (particularly 32-bit ARM)1John Levine
16 Jan 25  i i    `* Re: Calling conventions (particularly 32-bit ARM)3Waldek Hebisch
16 Jan 25  i i     `* Re: Calling conventions (particularly 32-bit ARM)2MitchAlsup1
16 Jan 25  i i      `- Re: Calling conventions (particularly 32-bit ARM)1Waldek Hebisch
13 Jan 25  i `* Re: Calling conventions (particularly 32-bit ARM)3Thomas Koenig
14 Jan 25  i  `* Re: Calling conventions (particularly 32-bit ARM)2Thomas Koenig
14 Jan 25  i   `- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
7 Jan 25  +* Re: Calling conventions (particularly 32-bit ARM)6George Neuner
8 Jan 25  i+* Re: Calling conventions (particularly 32-bit ARM)3Stefan Monnier
9 Jan 25  ii`* Re: Calling conventions (particularly 32-bit ARM)2Anton Ertl
13 Jan 25  ii `- Re: Calling conventions (particularly 32-bit ARM)1Stefan Monnier
28 Jan 25  i`* Re: Calling conventions (particularly 32-bit ARM)2Tim Rentsch
29 Jan 25  i `- Re: Calling conventions (particularly 32-bit ARM)1George Neuner
8 Jan 25  `* Re: Calling conventions (particularly 32-bit ARM)45Stefan Monnier
8 Jan 25   +- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
8 Jan 25   `* Re: Calling conventions (particularly 32-bit ARM)43Anton Ertl
9 Jan 25    `* Re: Calling conventions (particularly 32-bit ARM)42Stefan Monnier
9 Jan 25     +- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
9 Jan 25     `* Re: Calling conventions (particularly 32-bit ARM)40Anton Ertl
9 Jan 25      +* Re: Calling conventions (particularly 32-bit ARM)2Thomas Koenig
10 Jan 25      i`- Re: Calling conventions (particularly 32-bit ARM)1Anton Ertl
9 Jan 25      +* Re: Calling conventions (particularly 32-bit ARM)4MitchAlsup1
9 Jan 25      i`* Re: Calling conventions (particularly 32-bit ARM)3Thomas Koenig
10 Jan 25      i `* Re: Calling conventions (particularly 32-bit ARM)2MitchAlsup1
10 Jan 25      i  `- Re: Calling conventions (particularly 32-bit ARM)1Thomas Koenig
10 Jan 25      +* Re: Calling conventions (particularly 32-bit ARM)29Waldek Hebisch
10 Jan 25      i`* Re: Calling conventions (particularly 32-bit ARM)28Anton Ertl
10 Jan 25      i +- Re: Calling conventions (particularly 32-bit ARM)1John Levine
13 Jan 25      i `* Re: Calling conventions (particularly 32-bit ARM)26MitchAlsup1
13 Jan 25      i  `* Re: Calling conventions (particularly 32-bit ARM)25Thomas Koenig
13 Jan 25      i   `* Re: Calling conventions (particularly 32-bit ARM)24MitchAlsup1
13 Jan 25      i    +* Re: Calling conventions (particularly 32-bit ARM)22MitchAlsup1
14 Jan 25      i    i+* Re: Calling conventions (particularly 32-bit ARM)17MitchAlsup1
14 Jan 25      i    ii+- Re: Calling conventions (particularly 32-bit ARM)1David Brown
14 Jan 25      i    ii+* Re: Calling conventions (particularly 32-bit ARM)2Michael S
14 Jan 25      i    iii`- Re: Calling conventions (particularly 32-bit ARM)1Anton Ertl
14 Jan 25      i    ii+- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
14 Jan 25      i    ii`* Re: Calling conventions (particularly 32-bit ARM)12Thomas Koenig
14 Jan 25      i    ii +* Re: Calling conventions (particularly 32-bit ARM)7Terje Mathisen
14 Jan 25      i    ii i+- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
14 Jan 25      i    ii i+* Re: Calling conventions (particularly 32-bit ARM)4Thomas Koenig
15 Jan 25      i    ii ii`* Re: Calling conventions (particularly 32-bit ARM)3Keith Thompson
15 Jan 25      i    ii ii +- Re: Calling conventions (particularly 32-bit ARM)1Keith Thompson
15 Jan 25      i    ii ii `- Re: Calling conventions (particularly 32-bit ARM)1Keith Thompson
14 Jan 25      i    ii i`- Re: Calling conventions (particularly 32-bit ARM)1Michael S
14 Jan 25      i    ii +- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
14 Jan 25      i    ii `* Re: Calling conventions (particularly 32-bit ARM)3Thomas Koenig
14 Jan 25      i    ii  `* Re: Calling conventions (particularly 32-bit ARM)2Michael S
15 Jan 25      i    ii   `- Re: Calling conventions (particularly 32-bit ARM)1MitchAlsup1
14 Jan 25      i    i+- Re: Calling conventions (particularly 32-bit ARM)1Thomas Koenig
14 Jan 25      i    i`* Re: Calling conventions (particularly 32-bit ARM)3David Brown
14 Jan 25      i    i `* Re: Calling conventions (particularly 32-bit ARM)2David Brown
15 Jan 25      i    i  `- Re: Calling conventions (particularly 32-bit ARM)1Keith Thompson
14 Jan 25      i    `- Re: Calling conventions (particularly 32-bit ARM)1Keith Thompson
10 Jan 25      `* Re: Calling conventions (particularly 32-bit ARM)4David Brown
10 Jan 25       +* Re: Calling conventions (particularly 32-bit ARM)2Thomas Koenig
12 Jan 25       i`- Re: Calling conventions (particularly 32-bit ARM)1David Brown
12 Jan 25       `- Re: Calling conventions (particularly 32-bit ARM)1David Brown

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal