Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Finds the first bit set in a number, either from LSB or MSB.
firstbit{_hi|_lo|_shi} dest[.mask], src0[.swizzle] |
---|
Item | Description |
---|---|
dest |
[in] The integer position of the first bit set in src0 starting from the LSB for firstbit_lo or MSB for firstbit_hi. |
src0 |
[in] The input integer. |
Remarks
This operation returns the integer position of the first bit set in the 32-bit input starting from the LSB for firstbit_lo or MSB for firstbit_hi. For example firstbit_lo on 0x00000001 returns 0. firstbit_hi on 0x10000000 returns 3.
firstbit_shi (s for signed) returns the first 0 from the MSB if the number is negative; otherwise it returns the first 1 from the MSB.
All variants of the instruction return ~0 (0xffffffff in 32-bit register) if no match is found.
Use this instruction to quickly enumerate set bits in a bitfield, or find the largest power of 2 in a number.
This instruction applies to the following shader stages:
Vertex | Hull | Domain | Geometry | Pixel | Compute |
---|---|---|---|---|---|
X | X | X | X | X | X |
Minimum Shader Model
This instruction is supported in the following shader models:
Shader Model | Supported |
---|---|
Shader Model 5 | yes |
Shader Model 4.1 | no |
Shader Model 4 | no |
Shader Model 3 (DirectX HLSL) | no |
Shader Model 2 (DirectX HLSL) | no |
Shader Model 1 (DirectX HLSL) | no |