Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler macro to detect BMI2 instruction set

I was searching on the web to find a proper solution, without much success. So I hope one of you know something about it: Is there any way to detect the "Intel Bit Manipulation Instruction Sets 2" (BMI2) compile time? I want to make some conditional thing based on the availability of it.

like image 467
plasmacel Avatar asked Aug 25 '15 22:08

plasmacel


1 Answers

With GCC you can check for the __BMI2__ macro. This macro will be defined if the target supports BMI2 (e.g. -mbmi2,-march=haswell). This is the macro that the instrinsic's headers (x86intrin.h, bmi2intrin.h) uses to check for BMI2 at compile time.

For runtime checks, __builtin_cpu_init() and __builtin_cpu_supports("bmi2") can be used in modern GCC (tested in GCC 5.1, 4.9 and lower doesn't have it).

like image 57
RubenLaguna Avatar answered Oct 05 '22 23:10

RubenLaguna