Check for command line option in my header file

Jonathan Wakely jwakely.gcc@gmail.com
Sun Jul 17 23:11:00 GMT 2016


On 17 July 2016 at 23:27, greg7mdp wrote:
> I want to use the gcc builtin __builtin_popcount() inside my program if, and
> only if, the program is compiled with the option -mpopcnt.
>
> This is because I see that calling __builtin_popcount() when the program is
> not compiled with option -mpopcnt is actually slower than doing the popcnt()
> computation myself.
>
> So I was hoping that there is a way to test whether a compilation option is
> present in the preprocessor. Anyone know the answer?

You can't test whether the option was given on the command-line, but
that's not the right thing to test anyway. What you can test is
whether use of the instruction is enabled, by checking for the
__POPCNT__ macro being defined.



More information about the Gcc-help mailing list