cntlzd

Count Leading Zeros Doubleword

cntlzd RT,RA

Counts the number of consecutive 0 bits starting from bit 0 (MSB of 64-bit reg).

Encoding

Binary Layout
31
0:5
RS
6:10
RA
11:15
00000
16:20
000111010
21:30
Rc
31
 
Format X-form
Opcode 0x7C000074
Extension Base

Operands

  • RA
    Target Register
  • RS
    Source Register
  • RT
    Target General Purpose Register

Example

cntlzd r3, r4

// r3 = Leading Zeros in 64-bit r4.

Registers Altered

CR0

Related

Across architectures

Count Leading Zeros : how x86, ARM, RISC-V, and PowerISA each do this.

More in Base

Reference

Description

Counts the number of consecutive zero bits from the MSB (bit 0) of the 64-bit doubleword in RS and stores the result in RT. The count ranges from 0 to 64. If Rc=1, CR0 is updated based on the result.

Operation

n ← 0
while n < 64 and RS[n] = 0 do n ← n + 1
RT ← n
if Rc = 1 then CR0 ← (RT = 0, RT < 0, RT > 0, SO)

Programming Note

When Rc=1 (dot form), CR0 is updated with the signed comparison of the result against zero (LT, GT, EQ) and the current SO bit from XER.