In addition, each of these target machine types can have its own special options, starting
with ‘-m’, to choose among various hardware models or configurations—for example, 68010
vs 68020, floating coprocessor or none.
-mfloat-abi=name
Specifies which floating-point ABI to use. Permissible values are: ‘soft’,
‘softfp’ and ‘hard’.
Specifying ‘soft’ causes GCC to generate output containing library calls for
floating-point operations. ‘softfp’ allows the generation of code using hardware
floating-point instructions, but still uses the soft-float calling conventions.
‘hard’ allows generation of floating-point instructions and uses FPU-specific
calling conventions.
The default depends on the specific target configuration. Note that the hardfloat
and soft-float ABIs are not link-compatible; you must compile your entire
program with the same ABI, and link with a compatible set of libraries.
-mhard-float
Equivalent to ‘-mfloat-abi=hard’.
-msoft-float
Equivalent to ‘-mfloat-abi=soft’.
一、Linux平台
gnueabi相关的两个交叉编译器: gnueabi和gnueabihf
gcc-arm-Linux-gnueabi – The GNU C compiler for armel architecture
gcc-arm-linux-gnueabihf – The GNU C compiler for armhf architecture
分别使用gcc-arm-Linux-gnueabi和gcc-arm-linux-gnueabihf
//floatadd.c
float add3f(float a,float b,float c)
{
float d;
d=a+b;
d=d*d/c;
return d;
}
1.使用arm-linux-gnueabihf-gcc编译,使用“-v”选项以获取更详细的信息:
$ arm-linux-gnueabihf-gcc -v mfloat.c
COLLECT_GCC_OPTIONS=’-v’ ‘-march=armv7-a’ ‘-mfloat-abi=hard’ ‘-mfpu=vfpv3-d16′ ‘-mthumb’
-mfloat-abi=hard,可看出使用hard硬件浮点模式。
- 使用arm-linux-gnueabi-gcc编译:
$ arm-linux-gnueabi-gcc -v mfloat.c
COLLECT_GCC_OPTIONS=’-v’ ‘-march=armv7-a’ ‘-mfloat-abi=softfp’ ‘-mfpu=vfpv3-d16′ ‘-mthumb’
-mfloat-abi=softfp,可看出使用softfp模式。
可见这两个交叉编译器适用于armel和armhf两个不同的架构, armel和armhf这两种架构在对待浮点运算采取了不同的策略(有fpu的arm才能支持这两种浮点运算策略)。
其实这两个交叉编译器只不过是gcc的选项-mfloat-abi的默认值不同。 gcc的选项-mfloat-abi有三种值soft,softfp,hard(其中后两者都要求arm里有fpu浮点运算单元,soft与后两者是兼容的,但softfp和hard两种模式互不兼容):
soft: 不用fpu进行浮点计算,即使有fpu浮点运算单元也不用,而是使用软件模式。
softfp : armel架构(对应的编译器为gcc-arm-linux-gnueabi)采用的默认值,用fpu计算,但是传参数用普通寄存器传,这样中断的时候,只需要保存普通寄存器,中断负荷小,但是参数需要转换成浮点的再计算。
hard: armhf架构(对应的编译器gcc-arm-linux-gnueabihf)采用的默认值,用fpu计算,传参数也用fpu中的浮点寄存器传,省去了转换, 性能最好,但是中断负荷高。
二、VxWorks平台
ARMARCH7gnu使用的编译选项是CC_ARCH_SPEC=t7 -mfpu=vfp -mfloat-abi=softfp
ARMARCH7sfgnu使用的编译选项是CC_ARCH_SPEC=t7 -msoft_float=softfp
使用ARMARCH7gnu和ARMARCH7sfgnu 编译floatadd.c的命令行输出。
//floatadd.c
float add3f(float a,float b,float c)
{
float d;
d=a+b;
d=d*d/c;
return d;
}
platform: Wind River VxWorks 6.9
Command: make –no-print-directory BUILD_SPEC=ARMARCH7sfgnu DEBUG_MODE=1 TRACE=1
Working Directory: C:/LUA/CSRP2/workSpace/SMP/xxxx/ARMARCH7sfgnu
if [ ! -d “dirname "xxxx_partialImage/Debug/Objects/xxxx/floatadd.o"
” ]; then mkdir -p “dirname "xxxx_partialImage/Debug/Objects/xxxx/floatadd.o"
“; fi;echo “building xxxx_partialImage/Debug/Objects/xxxx/floatadd.o”; ccarm -g -t7 -msoft-float -ansi -fno-zero-initialized-in-bss -Wall -MD -MP -DCPU=_VX_ARMARCH7 -DTOOL_FAMILY=gnu -DTOOL=sfgnu -D_WRS_KERNEL -D_VSB_CONFIG_FILE=\”C:/WindRiver/vxworks-6.9/target/lib/h/config/vsbConfig.h\” -DARMEL -DARMEL -DIP_PORT_VXWORKS=69 -IC:/WindRiver/vxworks-6.9/target/h -IC:/WindRiver/vxworks-6.9/target/h/wrn/coreip -o “xxxx_partialImage/Debug/Objects/xxxx/floatadd.o” -c “C:/LUA/CSRP2/workSpace/SMP/xxxx/floatadd.c”
building xxxx_partialImage/Debug/Objects/xxxx/floatadd.o
if [ ! -d “dirname "xxxx_partialImage/Debug/xxxx_partialImage.o"
” ]; then mkdir -p “dirname "xxxx_partialImage/Debug/xxxx_partialImage.o"
“; fi