Does AVX support BMI1 support?
I have some code that depends on AVX.
In the same codebase, I also use TZCNT
.
The latter is part of BMI1. I know I can test this instruction using CPUID, but I'm lazy, so I haven't actually implemented it.
To check for support, I just follow the AVX instruction. If I get an #UD
undefined back instruction exception , I know the processor does not support AVX.
However, TZCNT
backward compatibility (kind) with bsf
(or bsr
- I always forget which is), so this won't throw an exception.
If I have support AVX
, does that mean BMI1
support?
For recording, I do not have AVX2 on the processor which I am testing right now.
source to share
No, AVX support does not imply BMI1 support.
For details, see the following table:
Intel AMD Year
---------------------------------------------------
AVX Sandy Bridge Bulldozer 2011
---------------------------------------------------
BMI1 Haswell Piledriver/Jaguar 2013
---------------------------------------------------
ABM Barcelona 2007
Haswell 2013
---------------------------------------------------
AVX2 Haswell 2013
Carrizo 2015
Ryzen 2017
---------------------------------------------------
BMI2 Haswell 2013
Excavator 2015
Ryzen 2017
Most processors support both, but AVX predates BMI1 by two years.
Add to that the fact that tzcnt
both bsf
have different semantics regarding flags. If you want to force exclusion #UD
, you can use andn
.
If you want to use CPUID:
BMI1 -> CPUID.(EAX=07H, ECX=0H):EBX.BMI1[bit 3]
(ANDN, BEXTR, BLSI, BLSMSK, BLSR, TZCNT)
BMI2 -> CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]
(BZHI, MULX, PDEP, PEXT, RORX, SARX, SHLX, SHRX)
LZCNT -> CPUID.(EAX=80000001H) ECX.LZCNT[bit 5]
POPCNT -> CPUID.(EAX=01H) :ECX.POPCNT [Bit 23]
Note that even though the CPUID indicates that the Intel processor does not support popcnt
, it often does.
source to share