cnttzw
Count Trailing Zeros Word
cnttzw RA, RS
Counts the number of trailing zeros in the low 32-bits.
Encoding
Binary Layout
31
0:5
RS
6:10
RA
11:15
/
16:20
538
21:30
/
31
Operands
-
RA
Target -
RS
Source
Example
cnttzw r4, r3
Registers Altered
CR0Related
Across architectures
Count Trailing Zeros : how x86, ARM, RISC-V, and PowerISA each do this.
More in Base
Reference
View in PowerISA v3.1C Specification ↗
OPF Power ISA v3.1C
Description
Counts the number of trailing zero bits in the low 32 bits of general-purpose register RS and stores the count in RA. The count ranges from 0 to 32; if all 32 bits are zero, the result is 32. No condition register or status flags are affected.
Operation
count ← 0
for i in 0..31:
if RS[32+i] == 0 then count ← count + 1
else break
RA ← count
Programming Note
The cnttzw instruction is useful for quickly determining the number of trailing zeros in a word, which can be helpful in bit manipulation tasks. Be cautious with Rc=1 as it modifies CR0 based on the result, affecting subsequent conditional operations. Ensure that the input register (RS) is correctly aligned and contains valid data to avoid unexpected results.