cmacroscompiler-optionsarmv6armcc

Macro for optimization level (ARMCC V6)


There are predefined macros such as __OPTIMIZE__ (defined in all optimizing compilations) and __OPTIMIZE_SIZE__ (defined if the compiler is optimizing for size).

I use these macros to check if the correct optimization level is set for the release target, if not I print out a warning.

Is there a possibility to check whether the optimization level -Ofast is set or not? Possibly something like __OPTIMIZE_FAST__ or __OPTIMIZE_SPEED__.


Solution

  • I checked the ARMCC command line options and it seems there's no -Ofast like in many other compilers. However if the behavior is the same as in GCC/Clang/ICC... then -Ofast is essentially just -O3 with --fpmode=fast so you can check it with __FP_FAST, probably in conjunction with __OPTIMISE_LEVEL

    In GCC you can use __FAST_MATH__. __NO_MATH_ERRNO__ may also be used although it may not be an exact match because that'll also be defined if -fno-math-errno is specified

    #ifdef __OPTIMIZE__
        printf("Optimized\n");
    
        #ifdef __ARMCC_VERSION
            #if defined(__FP_FAST) && __OPTIMISE_LEVEL >= 3
                printf("-Ofast ARMCC\n");
            #endif
        #elif defined(__GNUC__)
            #if defined(__FAST_MATH__)
    //      #if defined(__NO_MATH_ERRNO__)
                printf("-Ofast GNUC\n");
            #endif
        #endif
    #endif