Returning structs that fit into 2 registers like these
typedef struct {
int a, b;
} ret_struct2x32;
ret_struct2x32 return_struct2x32() {
return ret_struct2x32{2, 3};
}
typedef struct {
short a, b, c, d;
} ret_struct4x16;
ret_struct4x16 return_struct4x16() {
return ret_struct4x16{(short)2, (short)0, (short)3, (short)0};
}
or returning tuples that appear in some languages like python
def func(x,y):
# code to compute x and y
return x,y
a, b = 1, 2
u, v = func(a, b)
In C++ we have std::pair
and std::tuple
std::pair<int, int> return_pair()
{
return std::make_pair(2, 3);
}
std::tuple<short, short, short, short> return_tuple()
{
return std::make_tuple((short)2, (short)0, (short)3, (short)0);
}
See the demo on Compiler Explorer. Unfortunately the gcc version for MIPS is too old and can't make use the struct-in-register optimization, so look at the x86 output and you'll see that the whole tuples are returned in only a single instruction