Skip to content

Commit 15f63ec

Browse files
[AARCH64] Add assembly/disassmbly for FIRST,LASTP instr. (#114049)
This patch adds assembly/disassembly and tests for new FIRSTP and LASTP instructions introduced in https://developer.arm.com/documentation/ddi0602/2024-09 --------- Co-authored-by: SpencerAbson <[email protected]>
1 parent 85f3d5c commit 15f63ec

File tree

6 files changed

+252
-5
lines changed

6 files changed

+252
-5
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ let Predicates = [HasSVEorSME] in {
21292129
defm CNTH_XPiI : sve_int_count<0b010, "cnth", int_aarch64_sve_cnth>;
21302130
defm CNTW_XPiI : sve_int_count<0b100, "cntw", int_aarch64_sve_cntw>;
21312131
defm CNTD_XPiI : sve_int_count<0b110, "cntd", int_aarch64_sve_cntd>;
2132-
defm CNTP_XPP : sve_int_pcount_pred<0b0000, "cntp", int_aarch64_sve_cntp>;
2132+
defm CNTP_XPP : sve_int_pcount_pred<0b000, "cntp", int_aarch64_sve_cntp>;
21332133

21342134
def : Pat<(i64 (AArch64CttzElts nxv16i1:$Op1)),
21352135
(CNTP_XPP_B (BRKB_PPzP (PTRUE_B 31), PPR:$Op1),
@@ -4304,6 +4304,9 @@ let Predicates = [HasSVE2p2orSME2p2] in {
43044304
def SXTW_ZPzZ_D : sve_int_un_pred_arit_z<0b11, 0b1000, "sxtw", ZPR64>;
43054305
def UXTW_ZPzZ_D : sve_int_un_pred_arit_z<0b11, 0b1010, "uxtw", ZPR64>;
43064306

4307+
// SVE predicate count
4308+
defm FIRSTP_XPP : sve_int_pcount_pred_tmp<0b001, "firstp">;
4309+
defm LASTP_XPP : sve_int_pcount_pred_tmp<0b010, "lastp">;
43074310
} // End HasSME2p2orSVE2p2
43084311

43094312
//===----------------------------------------------------------------------===//

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ multiclass sve_int_count_v<bits<5> opc, string asm,
10461046
(!cast<Instruction>(NAME # "_D") ZPR64:$Zdn, PPRAny:$Pm), 0>;
10471047
}
10481048

1049-
class sve_int_pcount_pred<bits<2> sz8_64, bits<4> opc, string asm,
1049+
class sve_int_pcount_pred<bits<2> sz8_64, bits<3> opc, string asm,
10501050
PPRRegOp pprty>
10511051
: I<(outs GPR64:$Rd), (ins PPRAny:$Pg, pprty:$Pn),
10521052
asm, "\t$Rd, $Pg, $Pn",
@@ -1058,17 +1058,17 @@ class sve_int_pcount_pred<bits<2> sz8_64, bits<4> opc, string asm,
10581058
let Inst{31-24} = 0b00100101;
10591059
let Inst{23-22} = sz8_64;
10601060
let Inst{21-19} = 0b100;
1061-
let Inst{18-16} = opc{3-1};
1061+
let Inst{18-16} = opc{2-0};
10621062
let Inst{15-14} = 0b10;
10631063
let Inst{13-10} = Pg;
1064-
let Inst{9} = opc{0};
1064+
let Inst{9} = 0b0;
10651065
let Inst{8-5} = Pn;
10661066
let Inst{4-0} = Rd;
10671067

10681068
let hasSideEffects = 0;
10691069
}
10701070

1071-
multiclass sve_int_pcount_pred<bits<4> opc, string asm,
1071+
multiclass sve_int_pcount_pred<bits<3> opc, string asm,
10721072
SDPatternOperator int_op> {
10731073
def _B : sve_int_pcount_pred<0b00, opc, asm, PPR8>;
10741074
def _H : sve_int_pcount_pred<0b01, opc, asm, PPR16>;
@@ -1081,6 +1081,12 @@ multiclass sve_int_pcount_pred<bits<4> opc, string asm,
10811081
def : SVE_2_Op_Pat<i64, int_op, nxv2i1, nxv2i1, !cast<Instruction>(NAME # _D)>;
10821082
}
10831083

1084+
multiclass sve_int_pcount_pred_tmp<bits<3> opc, string asm> {
1085+
def _B : sve_int_pcount_pred<0b00, opc, asm, PPR8>;
1086+
def _H : sve_int_pcount_pred<0b01, opc, asm, PPR16>;
1087+
def _S : sve_int_pcount_pred<0b10, opc, asm, PPR32>;
1088+
def _D : sve_int_pcount_pred<0b11, opc, asm, PPR64>;
1089+
}
10841090
//===----------------------------------------------------------------------===//
10851091
// SVE Element Count Group
10861092
//===----------------------------------------------------------------------===//
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid predicate operand
5+
6+
firstp x0, p15, p0
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate register.
8+
// CHECK-NEXT: firstp x0, p15, p0
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
firstp x0, p15.b, p0.b
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate register.
13+
// CHECK-NEXT: firstp x0, p15.b, p0.b
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
firstp x0, p15.q, p0.h
17+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate register.
18+
// CHECK-NEXT: firstp x0, p15.q, p0.h
19+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
20+
21+
// ------------------------------------------------------------------------- //
22+
// Invalid register types
23+
24+
firstp sp, p15, p0.h
25+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
26+
// CHECK-NEXT: firstp sp, p15, p0.h
27+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
28+
29+
firstp w0, p15, p0.h
30+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
31+
// CHECK-NEXT: firstp w0, p15, p0.h
32+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SVE2p2/firstp.s

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
2+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme2p2 < %s \
4+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
5+
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
6+
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
8+
// RUN: | llvm-objdump -d --mattr=+sve2p2 - | FileCheck %s --check-prefix=CHECK-INST
9+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
10+
// RUN: | llvm-objdump -d --mattr=-sme2 - | FileCheck %s --check-prefix=CHECK-UNKNOWN
11+
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
12+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
13+
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
14+
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve2p2 -disassemble -show-encoding \
15+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
16+
17+
firstp x0, p0, p0.b // 00100101-00100001-10000000-00000000
18+
// CHECK-INST: firstp x0, p0, p0.b
19+
// CHECK-ENCODING: [0x00,0x80,0x21,0x25]
20+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
21+
// CHECK-UNKNOWN: 25218000 <unknown>
22+
23+
firstp x23, p11, p13.b // 00100101-00100001-10101101-10110111
24+
// CHECK-INST: firstp x23, p11, p13.b
25+
// CHECK-ENCODING: [0xb7,0xad,0x21,0x25]
26+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
27+
// CHECK-UNKNOWN: 2521adb7 <unknown>
28+
29+
firstp xzr, p15, p15.b // 00100101-00100001-10111101-11111111
30+
// CHECK-INST: firstp xzr, p15, p15.b
31+
// CHECK-ENCODING: [0xff,0xbd,0x21,0x25]
32+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
33+
// CHECK-UNKNOWN: 2521bdff <unknown>
34+
35+
firstp x0, p0, p0.h // 00100101-01100001-10000000-00000000
36+
// CHECK-INST: firstp x0, p0, p0.h
37+
// CHECK-ENCODING: [0x00,0x80,0x61,0x25]
38+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
39+
// CHECK-UNKNOWN: 25618000 <unknown>
40+
41+
firstp x23, p11, p13.h // 00100101-01100001-10101101-10110111
42+
// CHECK-INST: firstp x23, p11, p13.h
43+
// CHECK-ENCODING: [0xb7,0xad,0x61,0x25]
44+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
45+
// CHECK-UNKNOWN: 2561adb7 <unknown>
46+
47+
firstp xzr, p15, p15.h // 00100101-01100001-10111101-11111111
48+
// CHECK-INST: firstp xzr, p15, p15.h
49+
// CHECK-ENCODING: [0xff,0xbd,0x61,0x25]
50+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
51+
// CHECK-UNKNOWN: 2561bdff <unknown>
52+
53+
firstp x0, p0, p0.s // 00100101-10100001-10000000-00000000
54+
// CHECK-INST: firstp x0, p0, p0.s
55+
// CHECK-ENCODING: [0x00,0x80,0xa1,0x25]
56+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
57+
// CHECK-UNKNOWN: 25a18000 <unknown>
58+
59+
firstp x23, p11, p13.s // 00100101-10100001-10101101-10110111
60+
// CHECK-INST: firstp x23, p11, p13.s
61+
// CHECK-ENCODING: [0xb7,0xad,0xa1,0x25]
62+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
63+
// CHECK-UNKNOWN: 25a1adb7 <unknown>
64+
65+
firstp xzr, p15, p15.s // 00100101-10100001-10111101-11111111
66+
// CHECK-INST: firstp xzr, p15, p15.s
67+
// CHECK-ENCODING: [0xff,0xbd,0xa1,0x25]
68+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
69+
// CHECK-UNKNOWN: 25a1bdff <unknown>
70+
71+
firstp x0, p0, p0.d // 00100101-11100001-10000000-00000000
72+
// CHECK-INST: firstp x0, p0, p0.d
73+
// CHECK-ENCODING: [0x00,0x80,0xe1,0x25]
74+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
75+
// CHECK-UNKNOWN: 25e18000 <unknown>
76+
77+
firstp x23, p11, p13.d // 00100101-11100001-10101101-10110111
78+
// CHECK-INST: firstp x23, p11, p13.d
79+
// CHECK-ENCODING: [0xb7,0xad,0xe1,0x25]
80+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
81+
// CHECK-UNKNOWN: 25e1adb7 <unknown>
82+
83+
firstp xzr, p15, p15.d // 00100101-11100001-10111101-11111111
84+
// CHECK-INST: firstp xzr, p15, p15.d
85+
// CHECK-ENCODING: [0xff,0xbd,0xe1,0x25]
86+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
87+
// CHECK-UNKNOWN: 25e1bdff <unknown>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid predicate operand
5+
6+
lastp x0, p15, p0
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate register.
8+
// CHECK-NEXT: lastp x0, p15, p0
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
lastp x0, p15.b, p0.b
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate register.
13+
// CHECK-NEXT: lastp x0, p15.b, p0.b
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
lastp x0, p15.q, p0.h
17+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate register.
18+
// CHECK-NEXT: lastp x0, p15.q, p0.h
19+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
20+
21+
// ------------------------------------------------------------------------- //
22+
// Invalid register types
23+
24+
lastp sp, p15, p0.h
25+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
26+
// CHECK-NEXT: lastp sp, p15, p0.h
27+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
28+
29+
lastp w0, p15, p0.h
30+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
31+
// CHECK-NEXT: lastp w0, p15, p0.h
32+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SVE2p2/lastp.s

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
2+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme2p2 < %s \
4+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
5+
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
6+
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
8+
// RUN: | llvm-objdump -d --mattr=+sve2p2 - | FileCheck %s --check-prefix=CHECK-INST
9+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve2p2 < %s \
10+
// RUN: | llvm-objdump -d --mattr=-sme2 - | FileCheck %s --check-prefix=CHECK-UNKNOWN
11+
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
12+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve2p2 < %s \
13+
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
14+
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve2p2 -disassemble -show-encoding \
15+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
16+
17+
lastp x0, p0, p0.b // 00100101-00100010-10000000-00000000
18+
// CHECK-INST: lastp x0, p0, p0.b
19+
// CHECK-ENCODING: [0x00,0x80,0x22,0x25]
20+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
21+
// CHECK-UNKNOWN: 25228000 <unknown>
22+
23+
lastp x23, p11, p13.b // 00100101-00100010-10101101-10110111
24+
// CHECK-INST: lastp x23, p11, p13.b
25+
// CHECK-ENCODING: [0xb7,0xad,0x22,0x25]
26+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
27+
// CHECK-UNKNOWN: 2522adb7 <unknown>
28+
29+
lastp xzr, p15, p15.b // 00100101-00100010-10111101-11111111
30+
// CHECK-INST: lastp xzr, p15, p15.b
31+
// CHECK-ENCODING: [0xff,0xbd,0x22,0x25]
32+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
33+
// CHECK-UNKNOWN: 2522bdff <unknown>
34+
35+
lastp x0, p0, p0.h // 00100101-01100010-10000000-00000000
36+
// CHECK-INST: lastp x0, p0, p0.h
37+
// CHECK-ENCODING: [0x00,0x80,0x62,0x25]
38+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
39+
// CHECK-UNKNOWN: 25628000 <unknown>
40+
41+
lastp x23, p11, p13.h // 00100101-01100010-10101101-10110111
42+
// CHECK-INST: lastp x23, p11, p13.h
43+
// CHECK-ENCODING: [0xb7,0xad,0x62,0x25]
44+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
45+
// CHECK-UNKNOWN: 2562adb7 <unknown>
46+
47+
lastp xzr, p15, p15.h // 00100101-01100010-10111101-11111111
48+
// CHECK-INST: lastp xzr, p15, p15.h
49+
// CHECK-ENCODING: [0xff,0xbd,0x62,0x25]
50+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
51+
// CHECK-UNKNOWN: 2562bdff <unknown>
52+
53+
lastp x0, p0, p0.s // 00100101-10100010-10000000-00000000
54+
// CHECK-INST: lastp x0, p0, p0.s
55+
// CHECK-ENCODING: [0x00,0x80,0xa2,0x25]
56+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
57+
// CHECK-UNKNOWN: 25a28000 <unknown>
58+
59+
lastp x23, p11, p13.s // 00100101-10100010-10101101-10110111
60+
// CHECK-INST: lastp x23, p11, p13.s
61+
// CHECK-ENCODING: [0xb7,0xad,0xa2,0x25]
62+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
63+
// CHECK-UNKNOWN: 25a2adb7 <unknown>
64+
65+
lastp xzr, p15, p15.s // 00100101-10100010-10111101-11111111
66+
// CHECK-INST: lastp xzr, p15, p15.s
67+
// CHECK-ENCODING: [0xff,0xbd,0xa2,0x25]
68+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
69+
// CHECK-UNKNOWN: 25a2bdff <unknown>
70+
71+
lastp x0, p0, p0.d // 00100101-11100010-10000000-00000000
72+
// CHECK-INST: lastp x0, p0, p0.d
73+
// CHECK-ENCODING: [0x00,0x80,0xe2,0x25]
74+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
75+
// CHECK-UNKNOWN: 25e28000 <unknown>
76+
77+
lastp x23, p11, p13.d // 00100101-11100010-10101101-10110111
78+
// CHECK-INST: lastp x23, p11, p13.d
79+
// CHECK-ENCODING: [0xb7,0xad,0xe2,0x25]
80+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
81+
// CHECK-UNKNOWN: 25e2adb7 <unknown>
82+
83+
lastp xzr, p15, p15.d // 00100101-11100010-10111101-11111111
84+
// CHECK-INST: lastp xzr, p15, p15.d
85+
// CHECK-ENCODING: [0xff,0xbd,0xe2,0x25]
86+
// CHECK-ERROR: instruction requires: sme2p2 or sve2p2
87+
// CHECK-UNKNOWN: 25e2bdff <unknown>

0 commit comments

Comments
 (0)