0

I have next problem:
I have some tests related to xop check with using some Bulldozer (xop) instructions.
And I must run this tests only on Bulldozer processors.
How can I check that my processor supports xop instruction at compile-time?

Language: C, Os: Linux;

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
Laser
  • 6,652
  • 8
  • 54
  • 85

3 Answers3

0

You cannot test at compile time, but you can compile for AMD Bulldozer using:

$ gcc -march=bdver1 -mtune=bdver1 ...

See: http://gcc.gnu.org/gcc-4.6/changes.html

If your build machine is your target machine, look into /proc/cpuinfo.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

You can write a program that checks CPUID and use the output of that program while compiling:
gcc $(cpuid_test) my_prog.c

where cpuid_test returns '-march=bdver1' or -DXOP_SUPPORT=1

Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57
0

If a source is compiled with -march=bdver1 (which enables XOP support among other things), the preprocessor macro __XOP__ will be defined to 1.

You can test at compile time for XOP with

#ifdef __XOP__
     ...XOP code path here...
#else
     ...non XOP code here...
#endif 
Gunther Piez
  • 29,760
  • 6
  • 71
  • 103