pnext
SVE Find Next Active Predicate
PNEXT <Pdn>.<T>, <Pg>, <Pdn>.<T>
Finds the next active predicate bit.
Details
SVE predicate find-next instruction that scans the source predicate register for the next active bit after the position currently set in the predicate, under control of the governing predicate. The destination predicate is updated to indicate the position of the next active element. Sets the Z flag if no further active element is found. This instruction is useful for iterating through active predicate elements.
Pseudocode Operation
next_pos ← -1
for i = 0 to VL-1:
if Pg[i] ∧ Pdn[i] then
for j = i+1 to VL-1:
if Pg[j] ∧ Pdn[j] then
next_pos ← j
break
break
if next_pos ≥ 0 then
Pdn ← (1 << next_pos)
Z ← 0
else
Pdn ← 0
Z ← 1
Example
PNEXT p0.T, p0/m, p0.T
Encoding
Binary Layout
00100101
size
011001110001
0
Pv
0
Pdn
Operands
-
Pdn
Dest/Src -
Pg
Governing Pred
Reference (Arm A64 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x2519C400 | PNEXT <Pdn>.<T>, <Pv>, <Pdn>.<T> | A64 | 00100101 | size | 011001110001 | 0 | Pv | 0 | Pdn |
Description
An instruction used to construct a loop which iterates over all true elements in the vector select predicate register. If all elements in the first source predicate register are false it determines the first true element in the vector select predicate register, otherwise it determines the next true element in the vector select predicate register that follows the last true element in the first source predicate register. All elements of the destination predicate register are set to false, except the element corresponding to the determined vector select element, if any, which is set to true. Sets the First (N), None (Z), !Last (C) condition flags based on the predicate result, and the V flag to zero.
Operation
CheckSVEEnabled();
constant integer VL = CurrentVL;
constant integer PL = VL DIV 8;
constant integer elements = VL DIV esize;
bits(PL) mask = P[v, PL];
bits(PL) operand = P[dn, PL];
bits(PL) result;
constant integer psize = esize DIV 8;
integer next = LastActiveElement(operand, esize) + 1;
while next < elements && (!ActivePredicateElement(mask, next, esize)) do
next = next + 1;
result = Zeros(PL);
if next < elements then
Elem[result, next, psize] = ZeroExtend('1', psize);
PSTATE.<N,Z,C,V> = PredTest(mask, result, esize);
P[dn, PL] = result;