Re: Can a C function return TWO integers in registers on MIPS?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux