Skip to main content
Nikita91
Lead II
November 23, 2020
Question

How do I know at preprocessing time which compiler option was chosen between FPv5-D16 and FPv5-SP-D16?

  • November 23, 2020
  • 2 replies
  • 920 views

The __SIZEOF_FLOAT__ and __SIZEOF_DOUBLE__ macros give the same result in both cases.

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    November 23, 2020

    Try to output all preprocessor symbols (macros), see e.g. https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines (which refers to gcc documentation).

    Maybe there is some specific __TARGET_FPU_xx or alike.

    JW

    Nikita91
    Nikita91Author
    Lead II
    November 24, 2020

    Nice idea. Thank you.

    I found a define quite useful:

    __SOFTFP__ : is defined if soft FP is selected in configuration

    __ARM_FP : is defined and set if hardware FP is selected in configuration

    __ARM_FP Set if hardware floating-point is available.

    Bits 1-3 indicate the supported floating-point precision levels. The other bits are reserved.

    • Bit 1 - half precision (16-bit).
    • Bit 2 - single precision (32-bit).
    • Bit 3 - double precision (64-bit).

    These bits can be bitwise or-ed together. Permitted values include:

    • 0x04  for single-support.
    • 0x0C  for single- and double-support.
    • 0x0E  for half-, single-, and double-support.

    On STM32H743:

    with FPv5_SP_D16 I get 0x04

    with FPv5_D16 I get 0x0E, but the same thing with none...

    with softfp __ARM_FP is not defined

    Same thing for __GCC_IEC_559 :

    0 for FPv5_SP_D16 hard or soft, and soft+none

    2 for FPv5_D16 or none hard or soft

    But this only means that there is an implementation difference (with regard to the standard) between SP and DP.

    waclawek.jan
    Super User
    November 24, 2020

    Well, then the answer to your original question is, "you don't". It *is* an unpleasant but valid answer.

    Another, extreme maybe, answer is: gcc is open source, you can make whatever change you wish to it.

    That much for academic and impractical answers. I'm sure you know the practical ones already.

    JW