Encoding:

POOL32A

000000

rt

rs

CLZ

0101101100

POOL32AXf

111100

6

5

5

10

6

Format:

CLZ rt, rs

microMIPS

Count Leading Zeros in Word

Purpose:

Count Leading Zeros in Word

Count the number of leading zeros in a word.

Description:

 GPR[rt] = count_leading_zeros GPR[rs]

Bits 31..0 of GPR rs are scanned from most significant to least significant bit. The number of leading zeros is counted and the result is written to GPR rt. If no bits were set in GPR rs, the result written to GPR rt is 32.

Restrictions:

If GPR rs does not contain a sign-extended 32-bit value (bits 63..31 equal), then the results of the operation are

UNPREDICTABLE.

Operation:

if NotWordValue(GPR[rs]) then
   UNPREDICTABLE
endif
temp = 32
for i in 31 .. 0
   if GPR[rs]i = 1 then
      temp = 31 - i
      break
   endif
endfor
GPR[rt] = temp

Exceptions:

None

Programming Notes:

Release 6 sets the 'rt' field to a value of 00000.