cntlzdm

Count Leading Zeros Doubleword under Mask

cntlzdm RA, RS, RB

Counts leading zeros in RS, but only considering bits set in mask RB.

Details

The cntlzdm instruction counts the number of leading zero bits in a doubleword, but only considers the bits that are set to 1 in a mask specified by another register. The result is placed into the destination register.

Pseudocode Operation

n ←0
count = 0
do while n < 64
    do i = 0 to 63
        if((RB)i=1) then do
            n ←n + 1
            if((RS)i=1) then break
            count ←count + 1
        end
end
RA ←EXTZ64(count)

Programming Note

The cntlzdm instruction is useful for counting leading zeros in a doubleword while considering only the bits that are set to 1 in a mask. Ensure that both the source and mask registers are correctly aligned and that the mask register has at least one bit set to 1 to avoid undefined behavior. This instruction operates at user privilege level and does not generate exceptions under normal conditions, but it may incur performance penalties on processors without hardware support for this operation.

Example

cntlzdm r4, r3, r5

Encoding

Binary Layout
31
0
RS
6
RA
11
RB
16
59
21
/
31
 
Format X-form
Opcode 0x7C00003B
Extension Base

Operands

  • RA
    Target
  • RS
    Source
  • RB
    Mask