-mfloat-abi=softfp的问题,指定fpu为neon
https://blog.csdn.net/soaringlee_fighting/article/details/72493224
2017年05月18日 20:04:39 SoaringLee_fighting 阅读数 2365
arm-linux-androideabi-gcc -S -march=armv7-a -mfloat-abi=softfp -mfpu=neon -o arm-c-disassemble-fp.s arm-c-disassemble.c
fpu成为了我们指定的neon,两个选项都要设置;
测试使用的C语言程序源码如下,程序源码文件是arm-c-disassemble.c:
int sum(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
1、编译但是不汇编,查看产生的汇编源码程序源码:
arm-Linux-androideabi-gcc -S -o arm-c-disassemble-fp.s arm-c-disassemble.c
查看产生的汇编语言程序源码arm-c-disassemble-fp.s:
.arch armv5te
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 6
.eabi_attribute 34, 0
.eabi_attribute 18, 4
.file "arm-c-disassemble.c"
.text
.align 2
.global sum
.type sum, %function
sum:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
@ link register save eliminated.
str fp, [sp, #-4]!
add fp, sp, #0
sub sp, sp, #12
str r0, [fp, #-8]
str r1, [fp, #-12]
ldr r2, [fp, #-8]
ldr r3, [fp, #-12]
add r3, r2, r3
mov r0, r3
sub sp, fp, #0
@ sp needed
ldr fp, [sp], #4
bx lr
.size sum, .-sum
.align 2
.global sub
.type sub, %function
sub:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
@ link register save eliminated.
str fp, [sp, #-4]!
add fp, sp, #0
sub sp, sp, #12
str r0, [fp, #-8]
str r1, [fp, #-12]
ldr r2, [fp, #-8]
ldr r3, [fp, #-12]
rsb r3, r3, r2
mov r0, r3
sub sp, fp, #0
@ sp needed
ldr fp, [sp], #4
bx lr
.size sub, .-sub
.ident "GCC: (GNU) 4.8"
.section .note.GNU-stack,"",%progbits
默认编译的arch是armv5te,默认的fpu是softvfp;
2、Cortex-A9是armv7-a的arch,因此需要在编译时指定arch:
arm-linux-androideabi-gcc -S -march=armv7-a -o arm-c-disassemble-fp.s arm-c-disassemble.c
查看编译后产生的汇编语言程序源码:
.arch armv7-a
.fpu softvfp
.eabi_attribute 20, 1
...
此时arch是armv7-a;
3、在(2)的基础上,此时fpu是softvfp,Cortex-A9中支持neon,在编译时增加-mfpu=neon指定fpu:
arm-linux-androideabi-gcc -S -march=armv7-a -mfpu=neon -o arm-c-disassemble-fp.s arm-c-disassemble.c
查看编译后产生的汇编语言程序源码:
.arch armv7-a
.fpu softvfp
.eabi_attribute 20, 1
...
奇怪的是,此时.fpu依然是softvfp,而不是我们指定的neon,为什么呢?
经过网络搜索,需要指定“-mfloat-abi=name”,mfloat-abi的作用参考gcc文档中的说明,
mfloat-abi取值有三个“soft”,“softfp”,“hard”,此处指定mfloat-abi为“softfp”,然后编译:
arm-linux-androideabi-gcc -S -march=armv7-a -mfloat-abi=softfp -mfpu=neon -o arm-c-disassemble-fp.s arm-c-disassemble.c
查看编译后产生的汇编语言程序源码:
.arch armv7-a
.eabi_attribute 27, 3
.fpu neon
.eabi_attribute 20, 1
...
此时fpu成为了我们指定的neon;
4、在(3)的基础上,还可以继续指定CPU相关的一些更详细的信息,例如-mcpu=name的值,指定具体的CPU型号:
arm-linux-androideabi-gcc -S -mcpu=cortex-a9 -march=armv7-a -mfloat-abi=softfp -mfpu=neon -o arm-c-disassemble-fp.s arm-c-disassemble.c
指定具体的CPU型号为Cortex-A9,查看编译后产生的汇编语言程序源码:
.cpu cortex-a9
.eabi_attribute 27, 3
.fpu neon
.eabi_attribute 20, 1
...
此时.arch变成了.cpu,指定具体的CPU型号;
此时编译的完整的汇编语言程序源码:
.cpu cortex-a9
.eabi_attribute 27, 3
.fpu neon
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 6
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "arm-c-disassemble.c"
.text
.align 2
.global sum
.type sum, %function
sum:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
@ link register save eliminated.
str fp, [sp, #-4]!
add fp, sp, #0
sub sp, sp, #12
str r0, [fp, #-8]
str r1, [fp, #-12]
ldr r2, [fp, #-8]
ldr r3, [fp, #-12]
add r3, r2, r3
mov r0, r3
sub sp, fp, #0
@ sp needed
ldr fp, [sp], #4
bx lr
.size sum, .-sum
.align 2
.global sub
.type sub, %function
sub:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
@ link register save eliminated.
str fp, [sp, #-4]!
add fp, sp, #0
sub sp, sp, #12
str r0, [fp, #-8]
str r1, [fp, #-12]
ldr r2, [fp, #-8]
ldr r3, [fp, #-12]
rsb r3, r3, r2
mov r0, r3
sub sp, fp, #0
@ sp needed
ldr fp, [sp], #4
bx lr
.size sub, .-sub
.ident "GCC: (GNU) 4.8"
.section .note.GNU-stack,"",%progbits