The tzcnt intrinsics are used non non-BMI targets by code (e.g. ffmpeg) that uses it as a potentially faster BSF.
The TZCNT instruction is special in that it's encoded in a backward-compatible way and behaves as BSF on non-BMI targets.
Differential D14748
bmiintrin.h: Allow using the tzcnt intrinsics for non-BMI targets hans on Nov 17 2015, 8:49 AM. Authored by
Details The tzcnt intrinsics are used non non-BMI targets by code (e.g. ffmpeg) that uses it as a potentially faster BSF. The TZCNT instruction is special in that it's encoded in a backward-compatible way and behaves as BSF on non-BMI targets.
Diff Detail
Event TimelineComment Actions Looks good. The reasoning is that without this, projects will put in an #if __clang__ no tzcnt path (e.g. http://ffmpeg.org/pipermail/ffmpeg-devel/2015-November/183408.html), and with this patch they won't and in a few years when people use build flags that allow BMI instructions, we'll magically start doing the fast thing. (This is Eric's thing, but he sounded fine with this approach on IRC yesterday.) Comment Actions The summary of why this is ok is slightly misleading. The backend won't try to encode the TZCNT instruction when the BMI feature is not enabled. Notice this just maps the to the generic non-x86 specific __builtin_ctz. The backend will emit a regular BSF instruction if BMI is not supported. There will be a zero check around it unless the backend can prove that the input is not 0. |