cnttzd

Count Trailing Zeros Doubleword

cnttzd RA, RS

Counts the number of trailing zeros in 64-bits.

Details

Counts the number of trailing zero bits in the full 64-bit general-purpose register RS and stores the count in RA. The count ranges from 0 to 64; if all 64 bits are zero, the result is 64. No condition register or status flags are affected.

Pseudocode Operation

count ← 0
for i in 0..63:
  if RS[i] == 0 then count ← count + 1
  else break
RA ← count

Programming Note

The cnttzd instruction is useful for quickly determining the position of the least significant set bit in a 64-bit value. It operates efficiently on any aligned doubleword, but be cautious with unaligned data as it may lead to unexpected results or exceptions. This instruction can be executed at user privilege level without requiring special permissions.

Example

cnttzd r4, r3

Encoding

Binary Layout
31
0
RS
6
RA
11
/
16
570
21
/
31
 
Format X-form
Opcode 0x7C000474
Extension Base

Operands

  • RA
    Target
  • RS
    Source