Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit da17564

Browse files
committed
[AArch64][SVE] Asm: Support for CNT(B|H|W|D) and CNTP instructions.
This patch adds support for the following instructions: CNTB CNTH - Determine the number of active elements implied by CNTW CNTD the named predicate constant, multiplied by an immediate, e.g. cnth x0, vl8, #16 CNTP - Count active predicate elements, e.g. cntp x0, p0, p1.b counts the number of active elements in p1, predicated by p0, and stores the result in x0. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336552 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 955b8d4 commit da17564

12 files changed

+519
-13
lines changed

lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,19 +555,6 @@ let Predicates = [HasSVE] in {
555555
defm TRN1_PPP : sve_int_perm_bin_perm_pp<0b100, "trn1">;
556556
defm TRN2_PPP : sve_int_perm_bin_perm_pp<0b101, "trn2">;
557557

558-
def RDVLI_XI : sve_int_read_vl_a<0b0, 0b11111, "rdvl">;
559-
def ADDVL_XXI : sve_int_arith_vl<0b0, "addvl">;
560-
def ADDPL_XXI : sve_int_arith_vl<0b1, "addpl">;
561-
562-
defm INCB_XPiI : sve_int_pred_pattern_a<0b000, "incb">;
563-
defm DECB_XPiI : sve_int_pred_pattern_a<0b001, "decb">;
564-
defm INCH_XPiI : sve_int_pred_pattern_a<0b010, "inch">;
565-
defm DECH_XPiI : sve_int_pred_pattern_a<0b011, "dech">;
566-
defm INCW_XPiI : sve_int_pred_pattern_a<0b100, "incw">;
567-
defm DECW_XPiI : sve_int_pred_pattern_a<0b101, "decw">;
568-
defm INCD_XPiI : sve_int_pred_pattern_a<0b110, "incd">;
569-
defm DECD_XPiI : sve_int_pred_pattern_a<0b111, "decd">;
570-
571558
defm CMPHS_PPzZZ : sve_int_cmp_0<0b000, "cmphs">;
572559
defm CMPHI_PPzZZ : sve_int_cmp_0<0b001, "cmphi">;
573560
defm CMPGE_PPzZZ : sve_int_cmp_0<0b100, "cmpge">;
@@ -612,6 +599,25 @@ let Predicates = [HasSVE] in {
612599
defm FCMEQ_PPzZ0 : sve_fp_2op_p_pd<0b100, "fcmeq">;
613600
defm FCMNE_PPzZ0 : sve_fp_2op_p_pd<0b110, "fcmne">;
614601

602+
def RDVLI_XI : sve_int_read_vl_a<0b0, 0b11111, "rdvl">;
603+
def ADDVL_XXI : sve_int_arith_vl<0b0, "addvl">;
604+
def ADDPL_XXI : sve_int_arith_vl<0b1, "addpl">;
605+
606+
defm CNTB_XPiI : sve_int_count<0b000, "cntb">;
607+
defm CNTH_XPiI : sve_int_count<0b010, "cnth">;
608+
defm CNTW_XPiI : sve_int_count<0b100, "cntw">;
609+
defm CNTD_XPiI : sve_int_count<0b110, "cntd">;
610+
defm CNTP_XPP : sve_int_pcount_pred<0b0000, "cntp">;
611+
612+
defm INCB_XPiI : sve_int_pred_pattern_a<0b000, "incb">;
613+
defm DECB_XPiI : sve_int_pred_pattern_a<0b001, "decb">;
614+
defm INCH_XPiI : sve_int_pred_pattern_a<0b010, "inch">;
615+
defm DECH_XPiI : sve_int_pred_pattern_a<0b011, "dech">;
616+
defm INCW_XPiI : sve_int_pred_pattern_a<0b100, "incw">;
617+
defm DECW_XPiI : sve_int_pred_pattern_a<0b101, "decw">;
618+
defm INCD_XPiI : sve_int_pred_pattern_a<0b110, "incd">;
619+
defm DECD_XPiI : sve_int_pred_pattern_a<0b111, "decd">;
620+
615621
defm SQINCB_XPiWdI : sve_int_pred_pattern_b_s32<0b00000, "sqincb">;
616622
defm UQINCB_WPiI : sve_int_pred_pattern_b_u32<0b00001, "uqincb">;
617623
defm SQDECB_XPiWdI : sve_int_pred_pattern_b_s32<0b00010, "sqdecb">;

lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,64 @@ multiclass sve_int_count_v<bits<5> opc, string asm> {
356356
def _D : sve_int_count_v<0b11, opc, asm, ZPR64>;
357357
}
358358

359+
class sve_int_pcount_pred<bits<2> sz8_64, bits<4> opc, string asm,
360+
PPRRegOp pprty>
361+
: I<(outs GPR64:$Rd), (ins PPRAny:$Pg, pprty:$Pn),
362+
asm, "\t$Rd, $Pg, $Pn",
363+
"",
364+
[]>, Sched<[]> {
365+
bits<4> Pg;
366+
bits<4> Pn;
367+
bits<5> Rd;
368+
let Inst{31-24} = 0b00100101;
369+
let Inst{23-22} = sz8_64;
370+
let Inst{21-19} = 0b100;
371+
let Inst{18-16} = opc{3-1};
372+
let Inst{15-14} = 0b10;
373+
let Inst{13-10} = Pg;
374+
let Inst{9} = opc{0};
375+
let Inst{8-5} = Pn;
376+
let Inst{4-0} = Rd;
377+
}
378+
379+
multiclass sve_int_pcount_pred<bits<4> opc, string asm> {
380+
def _B : sve_int_pcount_pred<0b00, opc, asm, PPR8>;
381+
def _H : sve_int_pcount_pred<0b01, opc, asm, PPR16>;
382+
def _S : sve_int_pcount_pred<0b10, opc, asm, PPR32>;
383+
def _D : sve_int_pcount_pred<0b11, opc, asm, PPR64>;
384+
}
359385

360386
//===----------------------------------------------------------------------===//
361387
// SVE Element Count Group
362388
//===----------------------------------------------------------------------===//
363389

390+
class sve_int_count<bits<3> opc, string asm>
391+
: I<(outs GPR64:$Rd), (ins sve_pred_enum:$pattern, sve_incdec_imm:$imm4),
392+
asm, "\t$Rd, $pattern, mul $imm4",
393+
"",
394+
[]>, Sched<[]> {
395+
bits<5> Rd;
396+
bits<4> imm4;
397+
bits<5> pattern;
398+
let Inst{31-24} = 0b00000100;
399+
let Inst{23-22} = opc{2-1};
400+
let Inst{21-20} = 0b10;
401+
let Inst{19-16} = imm4;
402+
let Inst{15-11} = 0b11100;
403+
let Inst{10} = opc{0};
404+
let Inst{9-5} = pattern;
405+
let Inst{4-0} = Rd;
406+
}
407+
408+
multiclass sve_int_count<bits<3> opc, string asm> {
409+
def NAME : sve_int_count<opc, asm>;
410+
411+
def : InstAlias<asm # "\t$Rd, $pattern",
412+
(!cast<Instruction>(NAME) GPR64:$Rd, sve_pred_enum:$pattern, 1), 1>;
413+
def : InstAlias<asm # "\t$Rd",
414+
(!cast<Instruction>(NAME) GPR64:$Rd, 0b11111, 1), 2>;
415+
}
416+
364417
class sve_int_countvlv<bits<5> opc, string asm, ZPRRegOp zprty>
365418
: I<(outs zprty:$Zdn), (ins zprty:$_Zdn, sve_pred_enum:$pattern, sve_incdec_imm:$imm4),
366419
asm, "\t$Zdn, $pattern, mul $imm4",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid result register
5+
6+
cntb w0
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
8+
// CHECK-NEXT: cntb w0
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
cntb sp
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
13+
// CHECK-NEXT: cntb sp
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
cntb z0.b
17+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
18+
// CHECK-NEXT: cntb z0.b
19+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
20+
21+
22+
// ------------------------------------------------------------------------- //
23+
// Immediate not compatible with encode/decode function.
24+
25+
cntb x0, all, mul #-1
26+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
27+
// CHECK-NEXT: cntb x0, all, mul #-1
28+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
29+
30+
cntb x0, all, mul #0
31+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
32+
// CHECK-NEXT: cntb x0, all, mul #0
33+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
34+
35+
cntb x0, all, mul #17
36+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
37+
// CHECK-NEXT: cntb x0, all, mul #17
38+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
39+
40+
41+
// ------------------------------------------------------------------------- //
42+
// Invalid predicate patterns
43+
44+
cntb x0, #-1
45+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
46+
// CHECK-NEXT: cntb x0, #-1
47+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
48+
49+
cntb x0, #32
50+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
51+
// CHECK-NEXT: cntb x0, #32
52+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
53+
54+
cntb x0, vl512
55+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
56+
// CHECK-NEXT: cntb x0, vl512
57+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

test/MC/AArch64/SVE/cntb.s

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve < %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 < %s \
6+
// RUN: | llvm-objdump -d -mattr=+sve - | FileCheck %s --check-prefix=CHECK-INST
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve < %s \
8+
// RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
9+
10+
cntb x0
11+
// CHECK-INST: cntb x0
12+
// CHECK-ENCODING: [0xe0,0xe3,0x20,0x04]
13+
// CHECK-ERROR: instruction requires: sve
14+
// CHECK-UNKNOWN: e0 e3 20 04 <unknown>
15+
16+
cntb x0, all
17+
// CHECK-INST: cntb x0
18+
// CHECK-ENCODING: [0xe0,0xe3,0x20,0x04]
19+
// CHECK-ERROR: instruction requires: sve
20+
// CHECK-UNKNOWN: e0 e3 20 04 <unknown>
21+
22+
cntb x0, all, mul #1
23+
// CHECK-INST: cntb x0
24+
// CHECK-ENCODING: [0xe0,0xe3,0x20,0x04]
25+
// CHECK-ERROR: instruction requires: sve
26+
// CHECK-UNKNOWN: e0 e3 20 04 <unknown>
27+
28+
cntb x0, all, mul #16
29+
// CHECK-INST: cntb x0, all, mul #16
30+
// CHECK-ENCODING: [0xe0,0xe3,0x2f,0x04]
31+
// CHECK-ERROR: instruction requires: sve
32+
// CHECK-UNKNOWN: e0 e3 2f 04 <unknown>
33+
34+
cntb x0, pow2
35+
// CHECK-INST: cntb x0, pow2
36+
// CHECK-ENCODING: [0x00,0xe0,0x20,0x04]
37+
// CHECK-ERROR: instruction requires: sve
38+
// CHECK-UNKNOWN: 00 e0 20 04 <unknown>
39+
40+
cntb x0, #28
41+
// CHECK-INST: cntb x0, #28
42+
// CHECK-ENCODING: [0x80,0xe3,0x20,0x04]
43+
// CHECK-ERROR: instruction requires: sve
44+
// CHECK-UNKNOWN: 80 e3 20 04 <unknown>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid result register
5+
6+
cntd w0
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
8+
// CHECK-NEXT: cntd w0
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
cntd sp
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
13+
// CHECK-NEXT: cntd sp
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
cntd z0.b
17+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
18+
// CHECK-NEXT: cntd z0.b
19+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
20+
21+
22+
// ------------------------------------------------------------------------- //
23+
// Immediate not compatible with encode/decode function.
24+
25+
cntd x0, all, mul #-1
26+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
27+
// CHECK-NEXT: cntd x0, all, mul #-1
28+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
29+
30+
cntd x0, all, mul #0
31+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
32+
// CHECK-NEXT: cntd x0, all, mul #0
33+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
34+
35+
cntd x0, all, mul #17
36+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
37+
// CHECK-NEXT: cntd x0, all, mul #17
38+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
39+
40+
41+
// ------------------------------------------------------------------------- //
42+
// Invalid predicate patterns
43+
44+
cntd x0, #-1
45+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
46+
// CHECK-NEXT: cntd x0, #-1
47+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
48+
49+
cntd x0, #32
50+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
51+
// CHECK-NEXT: cntd x0, #32
52+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
53+
54+
cntd x0, vl512
55+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
56+
// CHECK-NEXT: cntd x0, vl512
57+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

test/MC/AArch64/SVE/cntd.s

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve < %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 < %s \
6+
// RUN: | llvm-objdump -d -mattr=+sve - | FileCheck %s --check-prefix=CHECK-INST
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve < %s \
8+
// RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
9+
10+
cntd x0
11+
// CHECK-INST: cntd x0
12+
// CHECK-ENCODING: [0xe0,0xe3,0xe0,0x04]
13+
// CHECK-ERROR: instruction requires: sve
14+
// CHECK-UNKNOWN: e0 e3 e0 04 <unknown>
15+
16+
cntd x0, all
17+
// CHECK-INST: cntd x0
18+
// CHECK-ENCODING: [0xe0,0xe3,0xe0,0x04]
19+
// CHECK-ERROR: instruction requires: sve
20+
// CHECK-UNKNOWN: e0 e3 e0 04 <unknown>
21+
22+
cntd x0, all, mul #1
23+
// CHECK-INST: cntd x0
24+
// CHECK-ENCODING: [0xe0,0xe3,0xe0,0x04]
25+
// CHECK-ERROR: instruction requires: sve
26+
// CHECK-UNKNOWN: e0 e3 e0 04 <unknown>
27+
28+
cntd x0, all, mul #16
29+
// CHECK-INST: cntd x0, all, mul #16
30+
// CHECK-ENCODING: [0xe0,0xe3,0xef,0x04]
31+
// CHECK-ERROR: instruction requires: sve
32+
// CHECK-UNKNOWN: e0 e3 ef 04 <unknown>
33+
34+
cntd x0, pow2
35+
// CHECK-INST: cntd x0, pow2
36+
// CHECK-ENCODING: [0x00,0xe0,0xe0,0x04]
37+
// CHECK-ERROR: instruction requires: sve
38+
// CHECK-UNKNOWN: 00 e0 e0 04 <unknown>
39+
40+
cntd x0, #28
41+
// CHECK-INST: cntd x0, #28
42+
// CHECK-ENCODING: [0x80,0xe3,0xe0,0x04]
43+
// CHECK-ERROR: instruction requires: sve
44+
// CHECK-UNKNOWN: 80 e3 e0 04 <unknown>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve 2>&1 < %s| FileCheck %s
2+
3+
// ------------------------------------------------------------------------- //
4+
// Invalid result register
5+
6+
cnth w0
7+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
8+
// CHECK-NEXT: cnth w0
9+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
10+
11+
cnth sp
12+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
13+
// CHECK-NEXT: cnth sp
14+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
15+
16+
cnth z0.b
17+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
18+
// CHECK-NEXT: cnth z0.b
19+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
20+
21+
22+
// ------------------------------------------------------------------------- //
23+
// Immediate not compatible with encode/decode function.
24+
25+
cnth x0, all, mul #-1
26+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
27+
// CHECK-NEXT: cnth x0, all, mul #-1
28+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
29+
30+
cnth x0, all, mul #0
31+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
32+
// CHECK-NEXT: cnth x0, all, mul #0
33+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
34+
35+
cnth x0, all, mul #17
36+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [1, 16]
37+
// CHECK-NEXT: cnth x0, all, mul #17
38+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
39+
40+
41+
// ------------------------------------------------------------------------- //
42+
// Invalid predicate patterns
43+
44+
cnth x0, #-1
45+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
46+
// CHECK-NEXT: cnth x0, #-1
47+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
48+
49+
cnth x0, #32
50+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
51+
// CHECK-NEXT: cnth x0, #32
52+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
53+
54+
cnth x0, vl512
55+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid operand
56+
// CHECK-NEXT: cnth x0, vl512
57+
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:

0 commit comments

Comments
 (0)