pnext

SVE Find Next Active Predicate

PNEXT <Pdn>.<T>, <Pg>, <Pdn>.<T>

Finds the next active predicate bit.

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
31:24
size
23:22
011001110001
21:10
0
9
Pv
8:5
0
4
Pdn
3:0
 
Format SVE Predicate
Opcode 0x2519C400
Extension SVE

Operands

  • Pdn
    Dest/Src
  • Pg
    Governing Pred

Related

More in SVE

Reference

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;