Find Most-Significant Set Bit Bit Manipulation

Locate the highest-order bit that differs from the sign (or, for unsigned, from zero) in an operand.

Vendor-Neutral Definition

d = the bit position (or, on some ISAs, the count of leading identical bits) of the most-significant bit that differs from the operand's sign/leading-zero pattern.
⚠️ Cross-vendor mappings describe semantic relationships and are not guaranteed one-to-one compiler translations.
equivalent with restrictions Both locate the most-significant bit that differs from the operand's sign/leading pattern - but PTX returns it as a bit POSITION where AMDGPU returns a leading-bit COUNT.
Property NVIDIA PTX AMDGPU
Instruction bfind v_ffbh_i32, v_ffbh_u32
ISA Layer Virtual Native
Data Types - i32, u32
Version / Target Introduced PTX ISA 2.0 -

Important Differences

  • PTX's bfind returns the bit position (0-indexed from the LSB) of the most-significant differing bit, or 0xffffffff if all bits equal the sign; AMDGPU's v_ffbh_i32/v_ffbh_u32 instead return a COUNT of leading bits matching the sign/zero pattern (also -1 for the all-matching case) - converting between the two requires a 'width - 1 - count' transformation, not a direct value match, even though both instructions answer the same underlying question.

Source Evidence

Verification method: documentation