Article View: gnu.gcc.help
Article #49533small unions as parameters
From: Paul Jones
Date: Mon, 03 Jan 1994 12:14
Date: Mon, 03 Jan 1994 12:14
38 lines
1953 bytes
1953 bytes
Looking at some of the assembly generated by gcc (on a SPARC) I noticed
that unions and structs are passed from function to function by reference
and not thru registers. However when compiling with -freg-struct-return
small unions and structs *are* returned in a register, but still not passed
in registers.
Try something like this to see what happens:
-------------------------------8<-----------------------------
#include <stdio.h>
typedef union value
{
long n;
char *s;
union value *v;
} Value;
Value AddNumbers(Value O1,Value O2)
{
return O1.n+O2.n;
}
int main(int argc,char *argv[])
{
Value L1,L2,L3;
L1.n = 1;
L2.n = 2;
L3 = AddNumbers(L1,L2);
printf("%ld %ld %ld\n",L1.n,L2.n,L3.n);
}
--------------------------------8<----------------------------
The above example is the way I would like to do things in a compiler that
generates ANSI C code. On a SPARC with gcc 2.4.5 you'll see that the result
of AddNumbers goes to a register (%o0) but the parameters O1 and O2 are
both pointers. Therefore passing small unions and structs introduces a
rather large overhead. Is there any reason why small unions and structs
can't be passed directly (in registers).
Paul.
Technical Details
Message-ID:
<CJ1zC5.A36@sci.kun.nl>Path:
arc1-ca.pugleaf.net!gmd.de!xlink.net!zib-berlin.de!netmbx.de!Germany.EU.net!EU.net!sun4nl!sci.kun.nl!cs.kun.nl!pauljShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,48bf18a904bb8e6,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1994-01-03 04:45:14 PST Newsgroups: gnu.gcc.help Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!zib-berlin.de!netmbx.de!Germany.EU.net!EU.net!sun4nl!sci.kun.nl!cs.kun.nl!paulj From: paulj@cs.kun.nl (Paul Jones) Subject: small unions as parameters Message-ID: <CJ1zC5.A36@sci.kun.nl> Sender: news@sci.kun.nl (News owner) Nntp-Posting-Host: zeus.cs.kun.nl Organization: University of Nijmegen, The Netherlands X-Newsreader: NN version 6.4.19 Date: Mon, 3 Jan 1994 12:14:28 GMT Lines: 38