asr

SVE Arithmetic Shift Right (Predicated)

ASR <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, <Zm>.<T>

Shifts elements right arithmetically under predicate.

Pseudocode Operation

for i = 0 to VL/esize-1 do
  if Pg[i] then
    shift_amount ← Zm[i*esize +: esize] AND (esize*8-1)
    Zdn[i*esize +: esize] ← Zdn[i*esize +: esize] >>> shift_amount
  else
    // element unchanged
endfor

Example

ASR z0.s.T, p0/m/M, z0.s.T, z2.s.T

Encoding

Binary Layout
00000100
31:24
size
23:22
010
21:19
0
18
0
17
0
16
100
15:13
Pg
12:10
Zm
9:5
Zdn
4:0
 
Format SVE Shift
Opcode 0x04108000
Extension SVE

Operands

  • Zdn
    Dest/Src
  • Pg
    Mask
  • Zm
    Second source scalable vector register (SVE)

Related

Other forms of asr

  • asr Arithmetic Shift Right (Immediate)
  • asr Arithmetic Shift Right (Immediate 64-bit)
  • asr Arithmetic Shift Right (Register)
  • asr Arithmetic Shift Right (Register 64-bit)
  • asr Arithmetic Shift Right (A32)

More in SVE

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0x1AC02800 ASR <Wd>, <Wn>, <Wm> A64 0 | 0 | 0 | 11010110 | Rm | 0010 | 10 | Rn | Rd
0x9AC02800 ASR <Xd>, <Xn>, <Xm> A64 1 | 0 | 0 | 11010110 | Rm | 0010 | 10 | Rn | Rd
0x13007C00 ASR <Wd>, <Wn>, #<shift> A64 0 | 00 | 100110 | 0 | immr | 011111 | Rn | Rd
0x9340FC00 ASR <Xd>, <Xn>, #<shift> A64 1 | 00 | 100110 | 1 | immr | 111111 | Rn | Rd
0x04008000 ASR <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, #<const> A64 00000100 | tszh | 00 | 0 | 0 | 0 | 0 | 100 | Pg | tszl | imm3 | Zdn
0x04188000 ASR <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, <Zm>.D A64 00000100 | size | 011 | 0 | 0 | 0 | 100 | Pg | Zm | Zdn
0x04108000 ASR <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, <Zm>.<T> A64 00000100 | size | 010 | 0 | 0 | 0 | 100 | Pg | Zm | Zdn
0x04209000 ASR <Zd>.<T>, <Zn>.<T>, #<const> A64 00000100 | tszh | 1 | tszl | imm3 | 1001 | 0 | 0 | Zn | Zd
0x04208000 ASR <Zd>.<T>, <Zn>.<T>, <Zm>.D A64 00000100 | size | 1 | Zm | 1000 | 0 | 0 | Zn | Zd

Description

Shift right, preserving the sign bit, active elements of the first source vector by corresponding elements of the second source vector and destructively place the results in the corresponding elements of the first source vector. The shift amount operand is a vector of unsigned elements in which all bits are significant, and not used modulo the element size. Inactive elements in the destination vector register remain unmodified.

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(VL) operand1 = Z[dn, VL];
bits(VL) operand2 = if AnyActiveElement(mask, esize) then Z[m, VL] else Zeros(VL);
bits(VL) result;

for e = 0 to elements-1
    if ActivePredicateElement(mask, e, esize) then
        bits(esize) element1 = Elem[operand1, e, esize];
        bits(esize) element2 = Elem[operand2, e, esize];
        integer shift = Min(UInt(element2), esize);
        Elem[result, e, esize] = ASR(element1, shift);
    else
        Elem[result, e, esize] = Elem[operand1, e, esize];

Z[dn, VL] = result;