找回密码
 立即注册
搜索
查看: 420|回复: 0

关于 gcc-arm-none-eabi 浮点数

[复制链接]

266

主题

0

回帖

1119

积分

管理员

积分
1119
发表于 2024-1-14 01:24:13 | 显示全部楼层 |阅读模式

Windows (mingw-w64-i686) hosted cross toolchains
AArch32 bare-metal target (arm-none-eabi)
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads

使用 arm-none-eabi-gcc 交叉编译链只能编译 ARM 架构的裸机系统(包括 ARM Linux 的 boot、kernel,不适用编译 Linux 应用 Application)

有关浮点数:
查看 gcc 的默认 define:

$ ./arm-none-eabi-gcc  -x c - -E -dM </dev/null|grep SOFT
#define __SOFTFP__ 1

-mfloat-abi=name
Specifies which floating-point ABI to use. Permissible values are: ‘soft’,‘softfp’ and ‘hard’.
ABI,application binary interface (ABI),应用程序 二进制接口。

softfp 与 hard 都使用硬件 FPU 指令,但使用软件接口。hard 则使用硬件接口。所以 soft 与 softfp 兼容,他们与 hard 不兼容。

-mfloat-abi=soft 时 会定义 #define __SOFTFP__ 1
当为 softfp 或 hard 时,不会定义  __SOFTFP__
__VFP_FP__  总是定义的(#define __VFP_FP__ 1),即使-mfloat-abi=soft  时。

源码头文件有这样的定义:

#elif defined ( __GNUC__ )
  #if defined (__VFP_FP__) && !defined(__SOFTFP__)
    #if (__FPU_PRESENT == 1)
      #define __FPU_USED       1
    #else
      #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
      #define __FPU_USED       0
    #endif
  #else
    #define __FPU_USED         0
  #endif

也就是说,在定义了 softfp 或 hard 时,当 __FPU_PRESENT 为 1 时,会定义 #define __FPU_USED       1,也就是要启用 FPU。__FPU_PRESENT 需要用户自己定义。

当使用 hard 或者 softfp 时,必须同时指定 FPU:

-mfpu= option supports the following FPU types: vfp, vfpv3, vfpv3-fp16, vfpv3-d16, vfpv3-d16-fp16, vfpv3xd, vfpv3xd-fp16, neon, neon-fp16, vfpv4, vfpv4-d16, fpv4-sp-d16, neon-vfpv4, fp-armv8, neon-fp-armv8, and crypto-neon-fp-armv8.

cortex-m4 选择:fpv4-sp-d16


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|棱讯科技 ( 粤ICP备2024228160号-2|粤公网安备44030002003510号 )

GMT+8, 2024-7-27 12:47 , Processed in 0.017400 second(s), 4 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表