编译器宏以检测BMI2指令集 [英] Compiler macro to detect BMI2 instruction set

查看:266
本文介绍了编译器宏以检测BMI2指令集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索以找到合适的解决方案,但没有成功. 因此,我希望你们中的一些人对此有所了解:有没有办法检测到"英特尔位操作指令集2 "(BMI2)的编译时间?我想根据它的可用性来做一些有条件的事情.

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.

推荐答案

使用GCC,您可以检查__BMI2__宏.如果目标支持BMI2(例如-mbmi2-march=haswell),则将定义此宏.这是内在的标头(x86intrin.hbmi2intrin.h)用于在编译时检查BMI2的宏.

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.

对于运行时检查,__builtin_cpu_init()__builtin_cpu_supports("bmi2")可以在现代GCC中使用(在GCC 5.1、4.9和更低版本中进行了测试).

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).

这篇关于编译器宏以检测BMI2指令集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆