pfirst

SVE Predicate First Active

PFIRST <Pd>.B, <Pg>, <Pn>.B

Sets destination predicate to true only at the first active element.

Pseudocode Operation

for i = 0 to VL/8-1
  if Pg[i] == 1 and Pn[i] == 1 then
    Pd[i] ← 1
    break
  else
    Pd[i] ← 0
  endif
endfor
for j = i+1 to VL/8-1
  Pd[j] ← 0
endfor

Example

PFIRST p0.B, p0/m, p1.B

Encoding

Binary Layout
00100101
31:24
0
23
1
22
011000110000
21:10
0
9
Pg
8:5
0
4
Pdn
3:0
 
Format SVE Predicate
Opcode 0x2558C000
Extension SVE

Operands

  • Pd
    Dest Pred
  • Pg
    Mask
  • Pn
    First source predicate register (SVE)

Related

More in SVE

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0x2558C000 PFIRST <Pdn>.B, <Pg>, <Pdn>.B A64 00100101 | 0 | 1 | 011000110000 | 0 | Pg | 0 | Pdn

Description

Sets the first active element in the destination predicate to true, otherwise elements from the source predicate are passed through unchanged. 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[g, PL];
bits(PL) result = P[dn, PL];
integer first = -1;
constant integer psize = esize DIV 8;

for e = 0 to elements-1
    if ActivePredicateElement(mask, e, esize) && first == -1 then
        first = e;

if first >= 0 then
    Elem[result, first, psize] = ZeroExtend('1', psize);

PSTATE.<N,Z,C,V> = PredTest(mask, result, esize);
P[dn, PL] = result;