* Can a C function return TWO integers in registers on MIPS?
@ 2008-08-30 23:14 Pan ruochen
2008-08-30 23:50 ` Marco Manfredini
2008-08-31 0:57 ` David Daney
0 siblings, 2 replies; 3+ messages in thread
From: Pan ruochen @ 2008-08-30 23:14 UTC (permalink / raw)
To: gcc-help
Hi All,
I'm writing code in C language for MIPS execption handler.
There is a function which returns two integers. For optimizing
the performance, I want gcc to generate code where these two integers
are returned in registers v0 & v1, instead of in memory.
Can gcc do this?
-------------
Best Regards,
PRC
Aug 28, 2008
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Can a C function return TWO integers in registers on MIPS?
2008-08-30 23:14 Can a C function return TWO integers in registers on MIPS? Pan ruochen
@ 2008-08-30 23:50 ` Marco Manfredini
2008-08-31 0:57 ` David Daney
1 sibling, 0 replies; 3+ messages in thread
From: Marco Manfredini @ 2008-08-30 23:50 UTC (permalink / raw)
To: gcc-help
On Thursday 28 August 2008, Pan ruochen wrote:
> Hi All,
>
> I'm writing code in C language for MIPS execption handler.
> There is a function which returns two integers. For optimizing
> the performance, I want gcc to generate code where these two integers
> are returned in registers v0 & v1, instead of in memory.
> Can gcc do this?
>
> -------------
> Best Regards,
> PRC
> Aug 28, 2008
You can try to return a struct and compile your code with -freg-struct-return.
This should put a struct with two ints into v2&v3. However, it also may
invoke trouble, because MIPS seems to default to memory returns and you might
break binary compatibility:
typedef struct { int x,y; } retval_t;
retval_t fun(int x,int y) { return (retval_t){x,y}; }
You might try the vector extension instead, which enables you to return in
v2&v3 without the above mentioned flag and trouble:
typedef int v2si __attribute__((__vector_size__(2*sizeof(int))));
typedef union {
v2si l;
struct { int x,y; };
} v2si_t;
v2si foo(int x,int y)
{
return (v2si){x,y};
}
int bar()
{
v2si_t r={foo(1,2)};
return r.x+r.y;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Can a C function return TWO integers in registers on MIPS?
2008-08-30 23:14 Can a C function return TWO integers in registers on MIPS? Pan ruochen
2008-08-30 23:50 ` Marco Manfredini
@ 2008-08-31 0:57 ` David Daney
1 sibling, 0 replies; 3+ messages in thread
From: David Daney @ 2008-08-31 0:57 UTC (permalink / raw)
To: Pan ruochen; +Cc: gcc-help
Pan ruochen wrote:
> Hi All,
>
> I'm writing code in C language for MIPS execption handler.
> There is a function which returns two integers. For optimizing
> the performance, I want gcc to generate code where these two integers
> are returned in registers v0 & v1, instead of in memory.
> Can gcc do this?
>
For the n32 and n64 ABIs, structures that fit in 16 bytes or less are
returned in V0 and V1 (or f0 and f2 if the struct contains only two
floating point elements).
For o32 all structs are returned in memory allocated by the caller.
As the other poster mentioned, there are GCC options that change the ABI
that might help you, but you must be careful as the code will not
interact well with ABI conforming code.
David Daney
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-08-28 15:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-30 23:14 Can a C function return TWO integers in registers on MIPS? Pan ruochen
2008-08-30 23:50 ` Marco Manfredini
2008-08-31 0:57 ` David Daney
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).