Name

findLSB - return the number of the least significant set bit.

Synopsis

int  findLSB(int  x)
int2 findLSB(int2 x)
int3 findLSB(int3 x)
int4 findLSB(int4 x)

int  findLSB(uint  x)
int2 findLSB(uint2 x)
int3 findLSB(uint3 x)
int4 findLSB(uint4 x)

Parameters

x
Bitfield to find LSB in.

Description

Returns the bit number of the least significant bit (value of 1) in the bitfield x. If no bits have the value 1 then -1 is returned.

Reference Implementation

findLSB for an int bitfield can be implemented like this:

int findLSB(int x)
{
  int i;
  int mask;
  int res = -1;
  for(i = 0; i < 32; i++) {
    mask = 1 << i;
    if (x & mask) {
      res = i;
      break;
    }
  }
  return res;
}

Profile Support

findLSB is supported in gp5 and hlsl11 profiles.

See Also

  http://www.opengl.org/registry/specs/ARB/gpu_shader5.txt

bitfieldExtract, bitfieldInsert, bitfieldReverse, bitCount and findMSB