I'm writing a project in C++ using GCC. Is there a macro, preferably a standard one, that can tell me whether or not the architecture I am compiling to has an FPU?
Asked
Active
Viewed 186 times
-1
-
3I'm curious as to why you want to know this. Is it a performance thing? You can always time some floating point operations to get some idea of that. – Paul Sanders Oct 02 '22 at 19:47
-
2What's the use case? Any architecture without FPU would need a cross-compiler today anyway, so you will know the architecture because you need to explicitly state which target you compile to. So just add a define yourself? – hyde Oct 02 '22 at 20:07
-
4Most architectures provides their own set of macros, for example RISC-V define `__riscv_flen` when there is a FPU available, and the value of the macro is the number of bits the FPU can handle, e.g. 64 for the D extension. – Lindydancer Oct 02 '22 at 20:08
-
How would your code use this information? – Steve Friedl Oct 02 '22 at 20:10
-
@Adel There are various degrees of hardware support - maybe just +,-,*,/ but not sqrt, log, sin,... Or maybe `sin()` supported for only the primary angle range and needs an extensive SW wrapper to handle a `double`. FPU is not a simply true/false issue. – chux - Reinstate Monica Oct 03 '22 at 03:04
-
Do not tag C for C++ questions. – Eric Postpischil Oct 03 '22 at 04:58
-
Unfortunately the (P)C and (P)C++ committees don't seem able to fathom that there exist systems without FPU and that the artificial requirements = "must support float.h" on a freestanding system forces every compiler vendor to quite needlessly come up with a whole software floating point lib for each such system, where using floating point doesn't make sense to begin with. There should have been a `__STDC_NO_FLOAT__` macro. – Lundin Oct 03 '22 at 08:19
1 Answers
1
This is not specified in the C++ standard. In general, the C++ standard does not cover hardware-specific attributes of (std::thread::hardware_concurrency
would be a notable exception).

Sam Varshavchik
- 114,536
- 5
- 94
- 148