Skip to content

Commit

Permalink
[AArch64] Add assembly/disassembly for PMLAL/PMULL instructions (llvm…
Browse files Browse the repository at this point in the history
…#113564)

This patch adds assembly/disassembly for the following SVE_AES2
instructions

    -  PMLAL
    -  PMULL
- In accordance with:
https://developer.arm.com/documentation/ddi0602/latest/
  • Loading branch information
SpencerAbson authored and NoumanAmir657 committed Nov 4, 2024
1 parent a2f8fba commit 21a3df7
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -3928,6 +3928,10 @@ let Predicates = [HasSVEAES2, HasSVE2p1orSSVE_AES] in {
def AESD_4ZZI_B : sve_crypto_binary_multi4<0b0100, "aesd">;
def AESEMC_4ZZI_B : sve_crypto_binary_multi4<0b1000, "aesemc">;
def AESDMIC_4ZZI_B : sve_crypto_binary_multi4<0b1100, "aesdimc">;

// SVE_AES2 multi-vector polynomial multiply
def PMLAL_2ZZZ_Q : sve_crypto_pmlal_multi<"pmlal">;
def PMULL_2ZZZ_Q : sve_crypto_pmull_multi<"pmull">;
} // End HasSVEAES2, HasSVE2p1orSSVE_AES

//===----------------------------------------------------------------------===//
Expand Down
40 changes: 40 additions & 0 deletions llvm/lib/Target/AArch64/SVEInstrFormats.td
Original file line number Diff line number Diff line change
Expand Up @@ -8879,6 +8879,46 @@ class sve_crypto_binary_multi4<bits<4> opc, string asm>
let hasSideEffects = 0;
}

class sve_crypto_pmlal_multi<string asm>
: I<(outs ZZ_q_mul_r:$Zda),
(ins ZZ_q_mul_r:$_Zda, ZPR64:$Zn, ZPR64:$Zm),
asm,
"\t$Zda, $Zn, $Zm",
"",
[]>, Sched<[]> {
bits<5> Zm;
bits<5> Zn;
bits<4> Zda;
let Inst{31-21} = 0b01000101001;
let Inst{20-16} = Zm;
let Inst{15-10} = 0b111111;
let Inst{9-5} = Zn;
let Inst{4-1} = Zda;
let Inst{0} = 0b0;

let Constraints = "$Zda = $_Zda";
let hasSideEffects = 0;
}

class sve_crypto_pmull_multi<string asm>
: I<(outs ZZ_q_mul_r:$Zd),
(ins ZPR64:$Zn, ZPR64:$Zm),
asm,
"\t$Zd, $Zn, $Zm",
"",
[]>, Sched<[]> {
bits<5> Zm;
bits<5> Zn;
bits<4> Zd;
let Inst{31-21} = 0b01000101001;
let Inst{20-16} = Zm;
let Inst{15-10} = 0b111110;
let Inst{9-5} = Zn;
let Inst{4-1} = Zd;
let Inst{0} = 0b0;
let hasSideEffects = 0;
}

//===----------------------------------------------------------------------===//
// SVE BFloat16 Group
//===----------------------------------------------------------------------===//
Expand Down
37 changes: 37 additions & 0 deletions llvm/test/MC/AArch64/SVE2p1/pmlal-diagnostics.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p1,+sve-aes2 2>&1 < %s | FileCheck %s

// --------------------------------------------------------------------------//
// Invalid vector list

pmlal {z0.q-z2.q}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
// CHECK-NEXT: pmlal {z0.q-z2.q}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmlal {z0.q-z0.q}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid number of vectors
// CHECK-NEXT: pmlal {z0.q-z0.q}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmlal {z1.q-z2.q}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: Invalid vector list, expected list with 2 consecutive SVE vectors, where the first vector is a multiple of 2 and with matching element types
// CHECK-NEXT: pmlal {z1.q-z2.q}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmlal {z0.d-z1.d}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
// CHECK-NEXT: pmlal {z0.d-z1.d}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

// --------------------------------------------------------------------------//
// Invalid single source vectors

pmlal {z0.q-z1.q}, z0.s, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
// CHECK-NEXT: pmlal {z0.q-z1.q}, z0.s, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmlal {z0.q-z1.q}, z0.d, z0.s
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
// CHECK-NEXT: pmlal {z0.q-z1.q}, z0.d, z0.s
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
33 changes: 33 additions & 0 deletions llvm/test/MC/AArch64/SVE2p1/pmlal.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-aes2,+ssve-aes < %s \
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | llvm-objdump -d --mattr=+sve-aes2,+sve2p1 - | FileCheck %s --check-prefix=CHECK-INST
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | llvm-objdump -d --mattr=-sve-aes2 - | FileCheck %s --check-prefix=CHECK-UNKNOWN
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve-aes2,+sve2p1 -disassemble -show-encoding \
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST

pmlal {z0.q-z1.q}, z0.d, z0.d // 01000101-00100000-11111100-00000000
// CHECK-INST: pmlal { z0.q, z1.q }, z0.d, z0.d
// CHECK-ENCODING: [0x00,0xfc,0x20,0x45]
// CHECK-ERROR: instruction requires: sve2p1 or ssve-aes sve-aes2
// CHECK-UNKNOWN: 4520fc00 <unknown>

pmlal {z22.q-z23.q}, z13.d, z8.d // 01000101-00101000-11111101-10110110
// CHECK-INST: pmlal { z22.q, z23.q }, z13.d, z8.d
// CHECK-ENCODING: [0xb6,0xfd,0x28,0x45]
// CHECK-ERROR: instruction requires: sve2p1 or ssve-aes sve-aes2
// CHECK-UNKNOWN: 4528fdb6 <unknown>

pmlal {z30.q-z31.q}, z31.d, z31.d // 01000101-00111111-11111111-11111110
// CHECK-INST: pmlal { z30.q, z31.q }, z31.d, z31.d
// CHECK-ENCODING: [0xfe,0xff,0x3f,0x45]
// CHECK-ERROR: instruction requires: sve2p1 or ssve-aes sve-aes2
// CHECK-UNKNOWN: 453ffffe <unknown>
37 changes: 37 additions & 0 deletions llvm/test/MC/AArch64/SVE2p1/pmull-diagnostics.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p1,+sve-aes2 2>&1 < %s | FileCheck %s

// --------------------------------------------------------------------------//
// Invalid vector list

pmull {z0.q-z2.q}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
// CHECK-NEXT: pmull {z0.q-z2.q}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmull {z0.q-z0.q}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid number of vectors
// CHECK-NEXT: pmull {z0.q-z0.q}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmull {z1.q-z2.q}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: Invalid vector list, expected list with 2 consecutive SVE vectors, where the first vector is a multiple of 2 and with matching element types
// CHECK-NEXT: pmull {z1.q-z2.q}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmull {z0.d-z1.d}, z0.d, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
// CHECK-NEXT: pmull {z0.d-z1.d}, z0.d, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

// --------------------------------------------------------------------------//
// Invalid single source vectors

pmull {z0.q-z1.q}, z0.s, z0.d
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
// CHECK-NEXT: pmull {z0.q-z1.q}, z0.s, z0.d
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

pmull {z0.q-z1.q}, z0.d, z0.s
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
// CHECK-NEXT: pmull {z0.q-z1.q}, z0.d, z0.s
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
33 changes: 33 additions & 0 deletions llvm/test/MC/AArch64/SVE2p1/pmull.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-aes2,+ssve-aes < %s \
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | llvm-objdump -d --mattr=+sve-aes2,+sve2p1 - | FileCheck %s --check-prefix=CHECK-INST
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | llvm-objdump -d --mattr=-sve-aes2 - | FileCheck %s --check-prefix=CHECK-UNKNOWN
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-aes2,+sve2p1 < %s \
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve-aes2,+sve2p1 -disassemble -show-encoding \
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST

pmull {z0.q-z1.q}, z0.d, z0.d // 01000101-00100000-11111000-00000000
// CHECK-INST: pmull { z0.q, z1.q }, z0.d, z0.d
// CHECK-ENCODING: [0x00,0xf8,0x20,0x45]
// CHECK-ERROR: instruction requires: sve2p1 or ssve-aes sve-aes2
// CHECK-UNKNOWN: 4520f800 <unknown>

pmull {z22.q-z23.q}, z13.d, z8.d // 01000101-00101000-11111001-10110110
// CHECK-INST: pmull { z22.q, z23.q }, z13.d, z8.d
// CHECK-ENCODING: [0xb6,0xf9,0x28,0x45]
// CHECK-ERROR: instruction requires: sve2p1 or ssve-aes sve-aes2
// CHECK-UNKNOWN: 4528f9b6 <unknown>

pmull {z30.q-z31.q}, z31.d, z31.d // 01000101-00111111-11111011-11111110
// CHECK-INST: pmull { z30.q, z31.q }, z31.d, z31.d
// CHECK-ENCODING: [0xfe,0xfb,0x3f,0x45]
// CHECK-ERROR: instruction requires: sve2p1 or ssve-aes sve-aes2
// CHECK-UNKNOWN: 453ffbfe <unknown>

0 comments on commit 21a3df7

Please sign in to comment.