Skip to content

Commit d8d144a

Browse files
authored
[LLVM][AArch64] Add assembly/disassembly of SVE BFSCALE instruction (llvm#113168)
This patch add assembly/disassembly and tests for sve bfscale instruction according to https://developer.arm.com/documentation/ddi0602 .
1 parent c5ea7b8 commit d8d144a

10 files changed

+131
-1
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4163,7 +4163,9 @@ defm BFMIN_ZPZZ : sve_fp_2op_p_zds_zeroing_bfloat<int_aarch64_sve_fmin>;
41634163
defm BFMAX_ZPZZ : sve_fp_2op_p_zds_zeroing_bfloat<int_aarch64_sve_fmax>;
41644164
} // HasSVEB16B16, UseExperimentalZeroingPseudos
41654165

4166-
4166+
let Predicates = [HasSVEBFSCALE] in {
4167+
def BFSCALE_ZPZZ : sve_fp_2op_p_zds_bfscale<0b1001, "bfscale", DestructiveBinary>;
4168+
} // HasSVEBFSCALE
41674169
//===----------------------------------------------------------------------===//
41684170
// SME2.1 or SVE2.1 instructions
41694171
//===----------------------------------------------------------------------===//

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,11 @@ multiclass sve_fp_2op_p_zds_bfloat<bits<4> opc, string asm, string Ps,
21742174
def : SVE_3_Op_Pat<nxv8bf16, op, nxv8i1, nxv8bf16, nxv8bf16, !cast<Instruction>(NAME)>;
21752175
}
21762176

2177+
class sve_fp_2op_p_zds_bfscale<bits<4> opc, string asm, DestructiveInstTypeEnum flags>
2178+
: sve_fp_2op_p_zds<0b00, opc, asm, ZPR16>{
2179+
let DestructiveInstType = flags;
2180+
}
2181+
21772182
multiclass sve_fp_2op_p_zds_zeroing_hsd<SDPatternOperator op> {
21782183
def _H_ZERO : PredTwoOpPseudo<NAME # _H, ZPR16, FalseLanesZero>;
21792184
def _S_ZERO : PredTwoOpPseudo<NAME # _S, ZPR32, FalseLanesZero>;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve-bfscale 2>&1 < %s| FileCheck %s
2+
3+
4+
// ------------------------------------------------------------------------- //
5+
// Invalid element width
6+
7+
bfscale z31.h, p7/m, z31.h, z31.s
8+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
9+
// CHECK-NEXT: bfscale z31.h, p7/m, z31.h, z31.s
10+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
11+
12+
bfscale z31.h, p7/m, z31.b, z31.h
13+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
14+
// CHECK-NEXT: bfscale z31.h, p7/m, z31.b, z31.h
15+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
16+
17+
bfscale z31.d, p7/m, z31.h, z31.h
18+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid element width
19+
// CHECK-NEXT: bfscale z31.d, p7/m, z31.h, z31.h
20+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
21+
22+
// ------------------------------------------------------------------------- //
23+
// Predicate register out of range
24+
25+
bfscale z31.h, p8/m, z31.h, z31.h
26+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid restricted predicate register, expected p0..p7 (without element suffix)
27+
// CHECK-NEXT: bfscale z31.h, p8/m, z31.h, z31.h
28+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
29+
30+
// ------------------------------------------------------------------------- //
31+
// Destination and source register don't match
32+
33+
bfscale z31.h, p7/m, z20.h, z31.h
34+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: operand must match destination register
35+
// CHECK-NEXT: bfscale z31.h, p7/m, z20.h, z31.h
36+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
37+
38+
// ------------------------------------------------------------------------- //
39+
// Using zeroing predicate
40+
bfscale z0.h, p0/z, z0.h, z0.h
41+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
42+
// CHECK-NEXT: bfscale z0.h, p0/z, z0.h, z0.h
43+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

llvm/test/MC/AArch64/SVE2/bfscale.s

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve,+sve-bfscale < %s \
2+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
4+
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
5+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve,+sve-bfscale < %s \
6+
// RUN: | llvm-objdump -d --mattr=+sve,+sve-bfscale - | FileCheck %s --check-prefix=CHECK-INST
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve,+sve-bfscale < %s \
8+
// RUN: | llvm-objdump -d --mattr=-sve-bfscale - | FileCheck %s --check-prefix=CHECK-UNKNOWN
9+
// Disassemble encoding and check the re-encoding (-show-encoding) matches.
10+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve,+sve-bfscale < %s \
11+
// RUN: | sed '/.text/d' | sed 's/.*encoding: //g' \
12+
// RUN: | llvm-mc -triple=aarch64 -mattr=+sve,+sve-bfscale -disassemble -show-encoding \
13+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
14+
15+
bfscale z0.h, p0/m, z0.h, z0.h // 01100101-00001001-10000000-00000000
16+
// CHECK-INST: bfscale z0.h, p0/m, z0.h, z0.h
17+
// CHECK-ENCODING: [0x00,0x80,0x09,0x65]
18+
// CHECK-ERROR: instruction requires: sve-bfscale
19+
// CHECK-UNKNOWN: 65098000 <unknown>
20+
21+
bfscale z21.h, p5/m, z21.h, z10.h // 01100101-00001001-10010101-01010101
22+
// CHECK-INST: bfscale z21.h, p5/m, z21.h, z10.h
23+
// CHECK-ENCODING: [0x55,0x95,0x09,0x65]
24+
// CHECK-ERROR: instruction requires: sve-bfscale
25+
// CHECK-UNKNOWN: 65099555 <unknown>
26+
27+
bfscale z31.h, p7/m, z31.h, z31.h // 01100101-00001001-10011111-11111111
28+
// CHECK-INST: bfscale z31.h, p7/m, z31.h, z31.h
29+
// CHECK-ENCODING: [0xff,0x9f,0x09,0x65]
30+
// CHECK-ERROR: instruction requires: sve-bfscale
31+
// CHECK-UNKNOWN: 65099fff <unknown>
32+
33+
// --------------------------------------------------------------------------//
34+
// Test compatibility with MOVPRFX instruction.
35+
36+
movprfx z23.h, p3/m, z31.h
37+
bfscale z23.h, p3/m, z23.h, z13.h // 01100101-00001001-10001101-10110111
38+
// CHECK-INST: movprfx z23.h, p3/m, z31.h
39+
// CHECK-INST: bfscale z23.h, p3/m, z23.h, z13.h
40+
// CHECK-ENCODING: [0xb7,0x8d,0x09,0x65]
41+
// CHECK-ERROR: instruction requires: sve-bfscale
42+
// CHECK-UNKNOWN: 65098db7 <unknown>
43+
44+
movprfx z23, z31
45+
bfscale z23.h, p3/m, z23.h, z13.h // 01100101-00001001-10001101-10110111
46+
// CHECK-INST: movprfx z23, z31
47+
// CHECK-INST: bfscale z23.h, p3/m, z23.h, z13.h
48+
// CHECK-ENCODING: [0xb7,0x8d,0x09,0x65]
49+
// CHECK-ERROR: instruction requires: sve-bfscale
50+
// CHECK-UNKNOWN: 65098db7 <unknown>

llvm/test/MC/AArch64/SVE2/directive-arch-negative.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ rax1 z0.d, z0.d, z0.d
2929
bgrp z21.s, z10.s, z21.s
3030
// CHECK: error: instruction requires: sve2-bitperm
3131
// CHECK-NEXT: bgrp z21.s, z10.s, z21.s
32+
33+
.arch armv9-a+sve-bfscale
34+
.arch armv9-a+nosve-bfscale
35+
bfscale z0.h, p0/m, z0.h, z0.h
36+
// CHECK: error: instruction requires: sve-bfscale
37+
// CHECK-NEXT: bfscale z0.h, p0/m, z0.h, z0.h

llvm/test/MC/AArch64/SVE2/directive-arch.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ rax1 z0.d, z0.d, z0.d
1919
.arch armv9-a+sve2-bitperm
2020
bgrp z21.s, z10.s, z21.s
2121
// CHECK: bgrp z21.s, z10.s, z21.s
22+
23+
.arch armv9-a+sve-bfscale
24+
bfscale z0.h, p0/m, z0.h, z0.h
25+
// CHECK: bfscale z0.h, p0/m, z0.h, z0.h

llvm/test/MC/AArch64/SVE2/directive-arch_extension-negative.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ rax1 z0.d, z0.d, z0.d
2929
bgrp z21.s, z10.s, z21.s
3030
// CHECK: error: instruction requires: sve2-bitperm
3131
// CHECK-NEXT: bgrp z21.s, z10.s, z21.s
32+
33+
.arch_extension sve-bfscale
34+
.arch_extension nosve-bfscale
35+
bfscale z0.h, p0/m, z0.h, z0.h
36+
// CHECK: error: instruction requires: sve-bfscale
37+
// CHECK-NEXT: bfscale z0.h, p0/m, z0.h, z0.h

llvm/test/MC/AArch64/SVE2/directive-arch_extension.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ rax1 z0.d, z0.d, z0.d
1919
.arch_extension sve2-bitperm
2020
bgrp z21.s, z10.s, z21.s
2121
// CHECK: bgrp z21.s, z10.s, z21.s
22+
23+
.arch_extension sve-bfscale
24+
bfscale z0.h, p0/m, z0.h, z0.h
25+
// CHECK: bfscale z0.h, p0/m, z0.h, z0.h

llvm/test/MC/AArch64/SVE2/directive-cpu-negative.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ rax1 z0.d, z0.d, z0.d
2929
bgrp z21.s, z10.s, z21.s
3030
// CHECK: error: instruction requires: sve2-bitperm
3131
// CHECK-NEXT: bgrp z21.s, z10.s, z21.s
32+
33+
.cpu generic+sve-bfscale
34+
.cpu generic+nosve-bfscale
35+
bfscale z0.h, p0/m, z0.h, z0.h
36+
// CHECK: error: instruction requires: sve-bfscale
37+
// CHECK-NEXT: bfscale z0.h, p0/m, z0.h, z0.h

llvm/test/MC/AArch64/SVE2/directive-cpu.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ rax1 z0.d, z0.d, z0.d
1919
.cpu generic+sve2-bitperm
2020
bgrp z21.s, z10.s, z21.s
2121
// CHECK: bgrp z21.s, z10.s, z21.s
22+
23+
.cpu generic+sve-bfscale
24+
bfscale z0.h, p0/m, z0.h, z0.h
25+
// CHECK: bfscale z0.h, p0/m, z0.h, z0.h

0 commit comments

Comments
 (0)