cnttzw
Count Trailing Zeros Word
Counts the number of trailing zeros in the low 32-bits.
Details
The cnttzw instruction counts the number of consecutive zero bits starting at bit 0 of register RS and places this count into register RA. The result ranges from 0 to 32, inclusive. If Rc is equal to 1, CR field 0 is set to reflect the result.
Pseudocode Operation
n ← 0
do while n < 32
if (RS)n = 0 then leave
n ← n + 1
RA ← n
if Rc = 1 then
if RA = 0 then CR0 ← 4
else CR0 ← 0
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.
Example
Encoding
Operands
-
RA
Target -
RS
Source