Count Leading Zeros Bit Manipulation

Count the number of consecutive zero bits starting from the most-significant bit.

Vendor-Neutral Definition

d = number of leading zero bits in a, counted from bit width-1 down to 0.
⚠️ Cross-vendor mappings describe semantic relationships and are not guaranteed one-to-one compiler translations.
equivalent with restrictions Both count leading zero bits from the most-significant bit, but disagree on the all-zero-input result.
Property NVIDIA PTX AMDGPU
Instruction clz s_flbit_i32, v_ffbh_u32
ISA Layer Virtual Native
Data Types b32, b64 i32, u32
Version / Target Introduced PTX ISA 2.0 gfx1100

Important Differences

  • On an all-zero input, PTX's clz returns the full operand width (32 for .b32, 64 for .b64) per its own spec. AMDGPU's s_flbit_i32 instead returns -1 (0xffffffff) for that same case, per its official documented functional example - this is a real, verified behavioral difference, not an approximation of one.

Source Evidence

Verification method: documentation