在 ARM 平台上正确检测混合端浮点格式 [英] Correctly detect mixed-endian floating point format on ARM platform
问题描述
我最近遇到了一个第三方库的问题,该库使用以下代码在 ARM 平台上测试混合端浮点格式:
I recently ran into an issue with a third party library that was using the following code to test for mixed-endian floating-point format on ARM platforms:
#if defined(__arm__) && !(__ARM_EABI__)
此检查在 Android 平台上错误地检测到混合端格式,但在 iOS 平台上正常工作.经过一番研究,我发现了 debian ArmEabiPort 文档,其中在 GCC 预处理器宏中包含以下内容,用于浮动点部分说(强调我的):
This check was incorrectly detecting mixed-endian format on Android platforms but worked correctly on iOS platforms. After some research I found the debian ArmEabiPort document which contains the following in the GCC preprocessor macros for floating point section which says(emphasis mine):
将代码移植到armel"时,以下预处理器宏是有趣:
When porting code to "armel", the following preprocessor macros are interesting:
__VFP_FP__ 表示使用的浮点格式是 ARM VFP 单元的格式,即本机端 IEEE-754.
__VFP_FP__ means that the floating point format in use is that of the ARM VFP unit, which is native-endian IEEE-754.
__MAVERICK__ 表示浮点格式是 Cirrus Logic MaverickCrunch 的格式,它也是 IEEE-754 并且总是小端.
__MAVERICK__ means that the floating point format is that of the Cirrus Logic MaverickCrunch, which is also IEEE-754 and is always little-endian.
__SOFTFP__ 意味着不是浮点指令,而是为浮点数学运算生成库调用,以便代码可以在没有 FPU 的处理器上运行.
__SOFTFP__ means that instead of floating point instructions, library calls are being generated for floating point math operations so that the code will run on a processor without an FPU.
__VFP_FP__ 和 __MAVERICK__ 是互斥的.如果两者都没有设置,则表示使用的浮点格式是 FPA 单元的旧混合端 45670123 格式.
__VFP_FP__ and __MAVERICK__ are mutually exclusive. If neither is set, that means the floating point format in use is the old mixed-endian 45670123 format of the FPA unit.
对于我们的特定情况,将检查更新为以下解决了问题:
For our specific case updating the check to the following fixed the problem:
#if defined(__arm__) && !(__VFP_FP__)
并且适用于 Android 和 iOS 平台.虽然从文档中更正确的检查是:
and works on both Android and iOS platforms. Although from the document the more correct check would be:
#if defined(__arm__) && !(__VFP_FP__) && !(__MAVERICK__)
我们想将补丁提交回第三方,但考虑到旧支票对提交它的人确实有效,而且查找文档有多么困难,我觉得我没有足够的信息来获取此信息正确的.
We would like to submit a patch back to the third-party but considering the old check did work for the person who submitted it and how difficult it is to find documentation I don't feel like I have enough information to get this correct.
是否有最后一次检查未命中的情况?debian文档专门介绍了gcc
,这些宏的可移植性如何?
Are there cases the last check misses? The debian document specifically covers gcc
, how portable are these macros?
更新
根据来自天真的噪音的有用评论,问题归结为:
Based on the helpful comments from artless noise the question boils down to:
__ARM_EABI__
宏检查是由另一个用户作为补丁引入的,用于检查混合端浮点格式.很明显,这个宏适用于某些系统,那些系统是什么?__VFP_FP__
宏是否涵盖这些系统,或者我是否需要考虑该宏以防止在我提交补丁时破坏现有用户.
The __ARM_EABI__
macro check was introduced as a patch by another user to check for mixed-endian floating point format. So apparently there are systems that this macro works for, what systems are those? Would the __VFP_FP__
macro cover those systems or do I need to take that macro into account as well to prevent breaking existing users when I submit a patch.
推荐答案
您还需要检查以确保您不在软浮动工具链上,因为软浮动库没有混合-endian 问题:
You'll also want to check to make sure you aren't on a soft-float toolchain, as the soft-float libraries don't have the mixed-endian issue:
#if defined(arm) && !defined(__SOFTFP__) && !defined(__VFP_FP__) && !defined(__MAVERICK__)
至于编译器支持——这些应该可以在 clang 中工作,但很明显,商业 ARM 编译器将完全做其他事情.
As to compiler support -- these should work in clang, but obviously, the commercial ARM compilers will do something else entirely.
这篇关于在 ARM 平台上正确检测混合端浮点格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!