clasta

SVE Conditional Last Element After

CLASTA <Rdn>, <Pg>, <Rdn>, <Zm>.<T>

Extracts element after the last active element.

Pseudocode Operation

activecount ← CountActiveLanes(Pg, esize)
if activecount == VL/esize then
  Rdn ← Zm[0]
else if activecount > 0 then
  Rdn ← Zm[activecount]
else
  Rdn ← Rdn

Example

CLASTA r0, p0/m, r0, z2.s.T

Encoding

Binary Layout
00000101
31:24
size
23:22
11000
21:17
0
16
101
15:13
Pg
12:10
Zm
9:5
Rdn
4:0
 
Format SVE Extract
Opcode 0x0530A000
Extension SVE

Operands

  • Rdn
    Dest/Fallback
  • Pg
    Predicate
  • Zm
    Vector

Related

More in SVE

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0x0530A000 CLASTA <R><dn>, <Pg>, <R><dn>, <Zm>.<T> A64 00000101 | size | 11000 | 0 | 101 | Pg | Zm | Rdn
0x052A8000 CLASTA <V><dn>, <Pg>, <V><dn>, <Zm>.<T> A64 00000101 | size | 10101 | 0 | 100 | Pg | Zm | Vdn
0x05288000 CLASTA <Zdn>.<T>, <Pg>, <Zdn>.<T>, <Zm>.<T> A64 00000101 | size | 10100 | 0 | 100 | Pg | Zm | Zdn

Description

From the source vector register extract the element after the last active element, or if the last active element is the final element extract element zero, and then zero-extend that element to destructively place in the destination and first source general-purpose register. If there are no active elements then destructively zero-extend the least significant element-size bits of the destination and first source general-purpose register.

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(esize) operand1 = X[dn, esize];
bits(VL) operand2 = Z[m, VL];
bits(csize) result;
integer last = LastActiveElement(mask, esize);

if last < 0 then
    result = ZeroExtend(operand1, csize);
else
    if !isBefore then
        last = last + 1;
        if last >= elements then last = 0;
    result = ZeroExtend(Elem[operand2, last, esize], csize);

X[dn, csize] = result;