cnttzdm

Count Trailing Zeros Doubleword under Mask

cnttzdm RA, RS, RB

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

Details

The cntlzdm instruction counts the number of consecutive zero bits starting at bit 0 of register RS, but only considering the bits that are set to 1 in register RB as a mask. The result is placed into register RA.

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 cnttzdm instruction is useful for counting trailing zeros in a doubleword while applying a mask. Ensure that the mask register (RB) has bits set to 1 where you want to consider the corresponding bits in the source register (RS). The result is zero-extended to 64 bits before being stored in the destination register (RA). This instruction operates at user privilege level and does not generate any exceptions under normal conditions. Performance may vary based on the distribution of zeros and ones in the registers.

Example

cnttzdm r4, r3, r5

Encoding

Binary Layout
31
0
RS
6
RA
11
RB
16
571
21
/
31
 
Format X-form
Opcode 0x7C00047B
Extension Base
Registers Altered CR0, XER

Operands

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