RISC-V資料模型,-mabi=ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d
RISC-V GCC通過-mabi
選項指定資料模型和浮點引數傳遞規則。有效的選項值包括ilp32、ilp32f、ilp32d、lp64、lp64f 和 lp64d。前半部分指定資料模型,後半部分指定浮點引數傳遞規則。
i
指int
,l
指long
,p
指pointer
即指標,32/64
指前面給出的型別是32/64位的;f
指float
,指float型浮點數引數通過浮點數暫存器傳遞;d
指double
,指float型和double型浮點數引數通過浮點數暫存器傳遞。
資料模型:
x | int字長 | long字長 | 指標字長 |
---|---|---|---|
ilp32/ilp32f/ilp32d | 32bits | 32bits | 32bits |
lp64/lp64f/lp64d | 32bits | 64bits | 64bits |
浮點引數傳遞規則:
x | 需要浮點擴充套件指令? | float引數 | double引數 |
---|---|---|---|
ilp32/lp64 | 不需要 | 通過整數暫存器(a0-a1)傳遞 | 通過整數暫存器(a0-a3)傳遞 |
ilp32f/lp64f | 需要F擴充套件 | 通過浮點暫存器(fa0-fa1)傳遞 | 通過整數暫存器(a0-a3)傳遞 |
ilp32d/lp64d | 需要F擴充套件和D擴充套件 | 通過浮點暫存器(fa0-fa1)傳遞 | 通過浮點暫存器(fa0-fa1)傳遞 |
浮點引數傳遞規則只跟-mabi
選項有關,和-march
選項沒有直接關係,但是部分-mabi
-march
選項中指定浮點擴充套件。
RISC-V GCC 使用手冊對-mabi
選項的說明:
-mabi=ABI-string
.
Specify integer and floating-point calling convention. ABI-string contains two parts: the size of integer types and the registers used for floating-point types. For example -march=rv64ifd -mabi=lp64d means that long and pointers are 64-bit (implicitly defining int to be 32-bit), and that floating-point values up to 64 bits wide are passed in F registers. Contrast this with -march=rv64ifd -mabi=lp64f, which still allows the compiler to generate code that uses the F and D extensions but only allows floating-point values up to 32 bits long to be passed in registers; or -march=rv64ifd -mabi=lp64, in which no floating-point arguments will be passed in registers.
.
The default for this argument is system dependent, users who want a specific calling convention should specify one explicitly. The valid calling conventions are: ilp32, ilp32f, ilp32d, lp64, lp64f, and lp64d. Some calling conventions are impossible to implement on some ISAs: for example, -march=rv32if -mabi=ilp32d is invalid because the ABI requires 64-bit values be passed in F registers, but F registers are only 32 bits wide.