I’ve used this:
function has_bmi2() CPUInfo = zeros(Int32, 4) ccall(:jl_cpuidex, Cvoid, (Ptr{Cint}, Cint, Cint), CPUInfo, 7, 0) CPUInfo[2] & 0x100 != 0 end
Cf. this post. There’s also CpuId.jl.