RISC-V GCC通过-mabi
选项指定数据模型和浮点参数传递规则。有效的选项值包括ilp32、ilp32f、ilp32d、lp64、lp64f 和 lp64d。前半部分指定数据模型,后半部分指定浮点参数传递规则。
mingdu.zheng at gmail dot com
http://blog.csdn.net/zoomdy/article/details/79353313
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.