Skip to content

Commit 8039f8e

Browse files
authored
[RISCV][MC] Add assembler support for XRivosVisni (llvm#128773)
This implements assembler support for the XRivosVisni custom/vendor extension from Rivos Inc. which is defined in: https://github.com/rivosinc/rivos-custom-extensions (See src/xrivosvisni.adoc) Codegen support will follow in separate changes.
1 parent dfda75f commit 8039f8e

File tree

7 files changed

+120
-3
lines changed

7 files changed

+120
-3
lines changed

clang/test/Driver/print-supported-extensions-riscv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
// CHECK-NEXT: xqcilo 0.2 'Xqcilo' (Qualcomm uC Large Offset Load Store Extension)
205205
// CHECK-NEXT: xqcilsm 0.2 'Xqcilsm' (Qualcomm uC Load Store Multiple Extension)
206206
// CHECK-NEXT: xqcisls 0.2 'Xqcisls' (Qualcomm uC Scaled Load Store Extension)
207+
// CHECK-NEXT: xrivosvisni 0.1 'XRivosVisni' (Rivos Vector Integer Small New)
207208
// CHECK-NEXT: xrivosvizip 0.1 'XRivosVizip' (Rivos Vector Register Zips)
208209
// CHECK-EMPTY:
209210
// CHECK-NEXT: Supported Profiles

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ The current vendor extensions supported are:
468468
``Xmipslsp``
469469
LLVM implements load/store pair instructions for the `p8700 processor <https://mips.com/products/hardware/p8700/>` by MIPS.
470470

471+
``experimental-XRivosVisni``
472+
LLVM implements `version 0.1 of the Rivos Vector Integer Small New Instructions extension specification <https://github.com/rivosinc/rivos-custom-extensions>`__.
473+
471474
``experimental-XRivosVizip``
472475
LLVM implements `version 0.1 of the Rivos Vector Register Zips extension specification <https://github.com/rivosinc/rivos-custom-extensions>`__.
473476

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@ void RISCVDisassembler::addSPOperands(MCInst &MI) const {
622622
#define TRY_TO_DECODE_FEATURE_ANY(FEATURES, DECODER_TABLE, DESC) \
623623
TRY_TO_DECODE((STI.getFeatureBits() & (FEATURES)).any(), DECODER_TABLE, DESC)
624624

625+
static constexpr FeatureBitset XRivosFeatureGroup = {
626+
RISCV::FeatureVendorXRivosVisni,
627+
RISCV::FeatureVendorXRivosVizip,
628+
};
629+
625630
static constexpr FeatureBitset XqciFeatureGroup = {
626631
RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
627632
RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
@@ -710,12 +715,10 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
710715
"CORE-V SIMD extensions");
711716
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
712717
"CORE-V Immediate Branching");
713-
714718
TRY_TO_DECODE_FEATURE_ANY(XqciFeatureGroup, DecoderTableXqci32,
715719
"Qualcomm uC Extensions");
716720

717-
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXRivosVizip, DecoderTableXRivos32,
718-
"Rivos");
721+
TRY_TO_DECODE_FEATURE_ANY(XRivosFeatureGroup, DecoderTableXRivos32, "Rivos");
719722

720723
TRY_TO_DECODE(true, DecoderTable32, "RISCV32");
721724

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,13 @@ def HasVendorXqcilo
13761376

13771377
// Rivos Extension(s)
13781378

1379+
def FeatureVendorXRivosVisni
1380+
: RISCVExperimentalExtension<0, 1, "Rivos Vector Integer Small New">;
1381+
def HasVendorXRivosVisni
1382+
: Predicate<"Subtarget->hasVendorXRivosVisni()">,
1383+
AssemblerPredicate<(all_of FeatureVendorXRivosVisni),
1384+
"'XRivosVisni' (Rivos Vector Integer Small New)">;
1385+
13791386
def FeatureVendorXRivosVizip
13801387
: RISCVExperimentalExtension<0, 1, "Rivos Vector Register Zips">;
13811388
def HasVendorXRivosVizip

llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,47 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
class CustomRivosVXI<bits<6> funct6, RISCVVFormat opv, dag outs, dag ins,
14+
string opcodestr, string argstr>
15+
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
16+
bits<5> imm;
17+
bits<5> rs1;
18+
bits<5> vd;
19+
bit vm = 0;
20+
21+
let Inst{31-26} = funct6;
22+
let Inst{25} = vm;
23+
let Inst{24-20} = imm;
24+
let Inst{19-15} = rs1;
25+
let Inst{14-12} = opv.Value;
26+
let Inst{11-7} = vd;
27+
let Inst{6-0} = OPC_CUSTOM_2.Value;
28+
29+
let Uses = [VTYPE, VL];
30+
let RVVConstraint = NoConstraint;
31+
let Constraints = "$vd = $vd_wb";
32+
}
33+
34+
class CustomRivosXVI<bits<6> funct6, RISCVVFormat opv, dag outs, dag ins,
35+
string opcodestr, string argstr>
36+
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
37+
bits<5> imm;
38+
bits<5> vs2;
39+
bits<5> rd;
40+
bit vm = 1;
41+
42+
let Inst{31-26} = funct6;
43+
let Inst{25} = vm;
44+
let Inst{24-20} = vs2;
45+
let Inst{19-15} = imm;
46+
let Inst{14-12} = opv.Value;
47+
let Inst{11-7} = rd;
48+
let Inst{6-0} = OPC_CUSTOM_2.Value;
49+
50+
let Uses = [VTYPE, VL];
51+
let RVVConstraint = NoConstraint;
52+
}
53+
1354
//===----------------------------------------------------------------------===//
1455
// XRivosVizip
1556
//===----------------------------------------------------------------------===//
@@ -25,3 +66,24 @@ defm RI_VZIP2B_V : VALU_IV_V<"ri.vzip2b", 0b010100>;
2566
defm RI_VUNZIP2A_V : VALU_IV_V<"ri.vunzip2a", 0b001000>;
2667
defm RI_VUNZIP2B_V : VALU_IV_V<"ri.vunzip2b", 0b011000>;
2768
}
69+
70+
//===----------------------------------------------------------------------===//
71+
// XRivosVisni
72+
//===----------------------------------------------------------------------===//
73+
74+
let Predicates = [HasVendorXRivosVisni], DecoderNamespace = "XRivos",
75+
mayLoad = false, mayStore = false, hasSideEffects = false in {
76+
77+
let vm = 0, vs2=0, Inst<6-0> = OPC_CUSTOM_2.Value,
78+
isReMaterializable = 1, isAsCheapAsAMove = 1 in
79+
def RI_VZERO : RVInstV<0b000000, 0b00000, OPCFG, (outs VR:$vd),
80+
(ins), "ri.vzero.v", "$vd">;
81+
82+
def RI_VINSERT : CustomRivosVXI<0b010000, OPMVX, (outs VR:$vd_wb),
83+
(ins VR:$vd, GPR:$rs1, uimm5:$imm),
84+
"ri.vinsert.v.x", "$vd, $rs1, $imm">;
85+
86+
def RI_VEXTRACT : CustomRivosXVI<0b010111, OPMVV, (outs GPR:$rd),
87+
(ins VR:$vs2, uimm5:$imm),
88+
"ri.vextract.x.v", "$rd, $vs2, $imm">;
89+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xrivosvisni -riscv-no-aliases -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-xrivosvisni < %s \
4+
# RUN: | llvm-objdump --mattr=+experimental-xrivosvisni -M no-aliases --no-print-imm-hex -d -r - \
5+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
6+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-xrivosvisni -riscv-no-aliases -show-encoding \
7+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
8+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-xrivosvisni < %s \
9+
# RUN: | llvm-objdump --mattr=+experimental-xrivosvisni -M no-aliases --no-print-imm-hex -d -r - \
10+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
11+
12+
# CHECK-ASM-AND-OBJ: ri.vzero.v v1
13+
# CHECK-ASM: encoding: [0xdb,0x70,0x00,0x00]
14+
ri.vzero.v v1
15+
# CHECK-ASM-AND-OBJ: ri.vzero.v v2
16+
# CHECK-ASM: encoding: [0x5b,0x71,0x00,0x00]
17+
ri.vzero.v v2
18+
# CHECK-ASM-AND-OBJ: ri.vzero.v v3
19+
# CHECK-ASM: encoding: [0xdb,0x71,0x00,0x00]
20+
ri.vzero.v v3
21+
22+
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v0, zero, 0
23+
# CHECK-ASM: encoding: [0x5b,0x60,0x00,0x40]
24+
ri.vinsert.v.x v0, x0, 0
25+
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v1, s4, 13
26+
# CHECK-ASM: encoding: [0xdb,0x60,0xda,0x40]
27+
ri.vinsert.v.x v1, x20, 13
28+
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v1, zero, 1
29+
# CHECK-ASM: encoding: [0xdb,0x60,0x10,0x40]
30+
ri.vinsert.v.x v1, x0, 1
31+
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v23, ra, 1
32+
# CHECK-ASM: encoding: [0xdb,0xeb,0x10,0x40]
33+
ri.vinsert.v.x v23, x1, 1
34+
35+
# CHECK-ASM-AND-OBJ: ri.vextract.x.v s4, v1, 13
36+
# CHECK-ASM: encoding: [0x5b,0xaa,0x16,0x5e]
37+
ri.vextract.x.v x20, v1, 13
38+
# CHECK-ASM-AND-OBJ: ri.vextract.x.v s5, v2, 31
39+
# CHECK-ASM: encoding: [0xdb,0xaa,0x2f,0x5e]
40+
ri.vextract.x.v x21, v2, 31

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ Experimental extensions
11301130
xqcilo 0.2
11311131
xqcilsm 0.2
11321132
xqcisls 0.2
1133+
xrivosvisni 0.1
11331134
xrivosvizip 0.1
11341135
11351136
Supported Profiles

0 commit comments

Comments
 (0)