On Tue, 2012-11-20 at 08:50 +0100, Jonas Bonn wrote: > On Tue, 2012-11-20 at 09:36 +0200, Stefan Kristiansson wrote: > > On Tue, Nov 20, 2012 at 09:23:30AM +0200, Stefan Kristiansson wrote: > > > On Tue, Nov 20, 2012 at 08:08:01AM +0100, Jonas Bonn wrote: > > > > > > > Why did we choose r3 for the struct return location? > > > > > > > > > > It was not so much "us" choosing it. > > > gcc has done it all along, creating a "defacto" standard for it, > > > now we are just documenting it. > > > That said, I don't see using r3 as a bad choice, do you? > > > > > The register that immediately jumps out at me as a natural choice is > r11... that register then becomes an IN/OUT parameter and doesn't > disrupt the regular allocation of parameter registers where r3 usually > is the first parameter. > > But I've given this about 3 minutes of thought; maybe r3 is better. I > would, however, be curious to know why in that case... > > > > > After actually checking what had changed I understand your question, > > that text was supposed to be _added_ to what already was in the > > section "Functions Returning Structures or Unions", not replace it. > > The new text clarifies structures returned by _value_ > > > > Julius, the section should be like this in it's whole: > > > > 16.2.5 Functions Returning Structures or Unions > > > > A function that returns a structure or union places the address of the > > structure or > > union in the general-purpose RV register. > > > > A function that returns a structure by value expects the location > > where that > > structure is to be placed to be supplied in function parameter word 0 (R3). > > This means we put X in r3 going into the function call and get X in r11 > coming out... what's the point?
Hi Jonas, I'm not sure of the rationale, but I observe that all the ABI's I've looked at recently pass the address of a struct to be returned in the first argument location, which suggests there might be a reason for it. I've asked Joern if there is a reason for this. It might be connected with C++ expecting "this" in the first argument register? I have also seen more complex ABI's, which modify this rule for simple structs (e.g. if the struct will fit in 32-bits, it is returned in R11 and if it fits in 64-bits it is returned in R11/R12). You have to be sure the size of the struct is always determined, so that the caller knows it will be coming back in registers, and there is no need to pass an address. HTH, Jeremy -- Tel: +44 (1590) 610184 Cell: +44 (7970) 676050 SkypeID: jeremybennett Email: [email protected] Web: www.embecosm.com _______________________________________________ OpenRISC mailing list [email protected] http://lists.openrisc.net/listinfo/openrisc
