Skip to content

Commit d3f1009

Browse files
authored
Merge pull request #75 from asb/fp-structs
FP calling convention: document treatment of packed or explicitly aligned structs as well as bitfields
2 parents f809b84 + 4032d0a commit d3f1009

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

riscv-elf.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,16 @@ floating-point register in the ABI. The ISA might have wider
172172
floating-point registers than the ABI.
173173

174174
For the purposes of this section, "struct" refers to a C struct with its
175-
hierarchy flattened, including any array fields. That is, struct `{ struct
175+
hierarchy flattened, including any array fields. That is, `struct { struct
176176
{ float f[1]; } g[2]; }` and `struct { float f; float g; }` are
177177
treated the same. Fields containing empty structs or unions are ignored while
178178
flattening, even in C++, unless they have nontrivial copy constructors or
179-
destructors.
179+
destructors. Attributes such as `aligned` or `packed` do not interfere with a
180+
struct's eligibility for being passed in registers according to the rules
181+
below. i.e. `struct { int i; double d; }` and `struct
182+
__attribute__((__packed__)) { int i; double d }` are treated the same, as are
183+
`struct { float f; float g; }` and `struct { float f; float g __attribute__
184+
((aligned (8))); }`.
180185

181186
A real floating-point argument is passed in a floating-point argument
182187
register if it is no more than FLEN bits wide and at least one floating-point
@@ -195,13 +200,13 @@ A complex floating-point number, or a struct containing just one complex
195200
floating-point number, is passed as though it were a struct containing two
196201
floating-point reals.
197202

198-
A struct containing one floating-point real and one integer, in either
199-
order, is passed in a floating-point register and an integer register,
200-
with the integer zero- or sign-extended as though it were a scalar,
201-
provided the floating-point real is no more than FLEN bits wide and the
202-
integer is no more than XLEN bits wide, and at least one floating-point
203-
argument register and at least one integer argument register is available.
204-
Otherwise, it is passed according to the integer calling convention.
203+
A struct containing one floating-point real and one integer (or bitfield), in
204+
either order, is passed in a floating-point register and an integer register,
205+
with the integer zero- or sign-extended as though it were a scalar, provided
206+
the floating-point real is no more than FLEN bits wide and the integer is no
207+
more than XLEN bits wide, and at least one floating-point argument register
208+
and at least one integer argument register is available. Otherwise, it is
209+
passed according to the integer calling convention.
205210

206211
Unions are never flattened and are always passed according to the integer
207212
calling convention.

0 commit comments

Comments
 (0)