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__)
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):
When porting code to "armel", the following preprocessor macros are interesting:
__VFP_FP__ means that the floating point format in use is that of the ARM VFP unit, which is native-endian 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__ 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__ 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__)
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.
Are there cases the last check misses? The debian document specifically covers gcc
, how portable are these macros?
Update
Based on the helpful comments from artless noise the question boils down to:
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.
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__)
As to compiler support -- these should work in clang, but obviously, the commercial ARM compilers will do something else entirely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With