For
gcc and
g++ (and
clang), you can use
-march=<cpu-type>
to set the target CPU type.
See here for a list of available options:
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
You'd have to pick one that supports AVX, so that,
at least potentially, the compiler may generate AVX instructions. But the resulting binary will then require AVX support from both, the CPU and the OS.
Probably you want to use
-O3
(or at least
-O2
) too, so that the compiler will extensively optimize your code.
If you want to know if a binary does actually contain AVX instructions, you can do something like this:
objdump -d my_program > disassembled.asm
Then simply check whether the assembly code contains any AVX instructions. A list can be found here:
https://docs.oracle.com/cd/E36784_01/html/E36859/gntbd.html
What code is likely to use AVX instructions, or SIMD instructions in general?
I think your best bet is a
loop that performs the same computation on a long sequence (array) of elements.
(And make sure that those computations cannot be optimized away!)