title: How to use the __bzhi_uxx intrinsic without letting gcc to insert other BMI2 instructions everywhere?
body: <p>I would like to use the <code>_bzhi_u32</code> intrinsic but I don't want to use the <code>-mbmi2</code> flag since that makes <code>gcc</code> to use other BMI2 instruction (notably <code>SHLX</code> in many <code>&lt;&lt;</code> shifts) which will produce <code>SIGILL</code> (Illegal instruction) if the host where the executable runs doesn't not support BMI2. </p>
  
  <p>I only use <code>_bzhi_u32</code> in one function and I guard  it's use by checking at runtime that is supported via <code>_builtin_cpu_is("corei7")</code> defaulting to another implementation if not supported. But I cannot guard the other BMI2 instruction that gcc inserts when <code>-mbmi2</code> is used. </p>
  
  <p>The problem is that the <code>_bzhi_u32</code> intrinsic won't be defined in <code>x86intrin.h</code> unless <code>-mbmi2</code> is specified (with the undesired effect of gcc sprinkling <code>SHLX</code> all over the place). </p>