Skip to content

[RISCV][MC] Add assembler support for XRivosVisni #128773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/test/Driver/print-supported-extensions-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
// CHECK-NEXT: xqcilo 0.2 'Xqcilo' (Qualcomm uC Large Offset Load Store Extension)
// CHECK-NEXT: xqcilsm 0.2 'Xqcilsm' (Qualcomm uC Load Store Multiple Extension)
// CHECK-NEXT: xqcisls 0.2 'Xqcisls' (Qualcomm uC Scaled Load Store Extension)
// CHECK-NEXT: xrivosvisni 0.1 'XRivosVisni' (Rivos Vector Integer Small New)
// CHECK-NEXT: xrivosvizip 0.1 'XRivosVizip' (Rivos Vector Register Zips)
// CHECK-EMPTY:
// CHECK-NEXT: Supported Profiles
Expand Down
3 changes: 3 additions & 0 deletions llvm/docs/RISCVUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ The current vendor extensions supported are:
``Xmipslsp``
LLVM implements load/store pair instructions for the `p8700 processor <https://mips.com/products/hardware/p8700/>` by MIPS.

``experimental-XRivosVisni``
LLVM implements `version 0.1 of the Rivos Vector Integer Small New Instructions extension specification <https://github.com/rivosinc/rivos-custom-extensions>`__.

``experimental-XRivosVizip``
LLVM implements `version 0.1 of the Rivos Vector Register Zips extension specification <https://github.com/rivosinc/rivos-custom-extensions>`__.

Expand Down
9 changes: 6 additions & 3 deletions llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ void RISCVDisassembler::addSPOperands(MCInst &MI) const {
#define TRY_TO_DECODE_FEATURE_ANY(FEATURES, DECODER_TABLE, DESC) \
TRY_TO_DECODE((STI.getFeatureBits() & (FEATURES)).any(), DECODER_TABLE, DESC)

static constexpr FeatureBitset XRivosFeatureGroup = {
RISCV::FeatureVendorXRivosVisni,
RISCV::FeatureVendorXRivosVizip,
};

static constexpr FeatureBitset XqciFeatureGroup = {
RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
Expand Down Expand Up @@ -717,12 +722,10 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
"CORE-V SIMD extensions");
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbi, DecoderTableXCVbi32,
"CORE-V Immediate Branching");

TRY_TO_DECODE_FEATURE_ANY(XqciFeatureGroup, DecoderTableXqci32,
"Qualcomm uC Extensions");

TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXRivosVizip, DecoderTableXRivos32,
"Rivos");
TRY_TO_DECODE_FEATURE_ANY(XRivosFeatureGroup, DecoderTableXRivos32, "Rivos");

TRY_TO_DECODE(true, DecoderTable32, "RISCV32");

Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,13 @@ def HasVendorXqcilo

// Rivos Extension(s)

def FeatureVendorXRivosVisni
: RISCVExperimentalExtension<0, 1, "Rivos Vector Integer Small New">;
def HasVendorXRivosVisni
: Predicate<"Subtarget->hasVendorXRivosVisni()">,
AssemblerPredicate<(all_of FeatureVendorXRivosVisni),
"'XRivosVisni' (Rivos Vector Integer Small New)">;

def FeatureVendorXRivosVizip
: RISCVExperimentalExtension<0, 1, "Rivos Vector Register Zips">;
def HasVendorXRivosVizip
Expand Down
62 changes: 62 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,47 @@
//
//===----------------------------------------------------------------------===//

class CustomRivosVXI<bits<6> funct6, RISCVVFormat opv, dag outs, dag ins,
string opcodestr, string argstr>
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
bits<5> imm;
bits<5> rs1;
bits<5> vd;
bit vm = 0;

let Inst{31-26} = funct6;
let Inst{25} = vm;
let Inst{24-20} = imm;
let Inst{19-15} = rs1;
let Inst{14-12} = opv.Value;
let Inst{11-7} = vd;
let Inst{6-0} = OPC_CUSTOM_2.Value;

let Uses = [VTYPE, VL];
let RVVConstraint = NoConstraint;
let Constraints = "$vd = $vd_wb";
}

class CustomRivosXVI<bits<6> funct6, RISCVVFormat opv, dag outs, dag ins,
string opcodestr, string argstr>
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
bits<5> imm;
bits<5> vs2;
bits<5> rd;
bit vm = 1;

let Inst{31-26} = funct6;
let Inst{25} = vm;
let Inst{24-20} = vs2;
let Inst{19-15} = imm;
let Inst{14-12} = opv.Value;
let Inst{11-7} = rd;
let Inst{6-0} = OPC_CUSTOM_2.Value;

let Uses = [VTYPE, VL];
let RVVConstraint = NoConstraint;
}

//===----------------------------------------------------------------------===//
// XRivosVizip
//===----------------------------------------------------------------------===//
Expand All @@ -25,3 +66,24 @@ defm RI_VZIP2B_V : VALU_IV_V<"ri.vzip2b", 0b010100>;
defm RI_VUNZIP2A_V : VALU_IV_V<"ri.vunzip2a", 0b001000>;
defm RI_VUNZIP2B_V : VALU_IV_V<"ri.vunzip2b", 0b011000>;
}

//===----------------------------------------------------------------------===//
// XRivosVisni
//===----------------------------------------------------------------------===//

let Predicates = [HasVendorXRivosVisni], DecoderNamespace = "XRivos",
mayLoad = false, mayStore = false, hasSideEffects = false in {

let vm = 0, vs2=0, Inst<6-0> = OPC_CUSTOM_2.Value,
isReMaterializable = 1, isAsCheapAsAMove = 1 in
def RI_VZERO : RVInstV<0b000000, 0b00000, OPCFG, (outs VR:$vd),
(ins), "ri.vzero.v", "$vd">;

def RI_VINSERT : CustomRivosVXI<0b010000, OPMVX, (outs VR:$vd_wb),
(ins VR:$vd, GPR:$rs1, uimm5:$imm),
"ri.vinsert.v.x", "$vd, $rs1, $imm">;

def RI_VEXTRACT : CustomRivosXVI<0b010111, OPMVV, (outs GPR:$rd),
(ins VR:$vs2, uimm5:$imm),
"ri.vextract.x.v", "$rd, $vs2, $imm">;
}
40 changes: 40 additions & 0 deletions llvm/test/MC/RISCV/xrivosvisni-valid.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xrivosvisni -riscv-no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-xrivosvisni < %s \
# RUN: | llvm-objdump --mattr=+experimental-xrivosvisni -M no-aliases --no-print-imm-hex -d -r - \
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-xrivosvisni -riscv-no-aliases -show-encoding \
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-xrivosvisni < %s \
# RUN: | llvm-objdump --mattr=+experimental-xrivosvisni -M no-aliases --no-print-imm-hex -d -r - \
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s

# CHECK-ASM-AND-OBJ: ri.vzero.v v1
# CHECK-ASM: encoding: [0xdb,0x70,0x00,0x00]
ri.vzero.v v1
# CHECK-ASM-AND-OBJ: ri.vzero.v v2
# CHECK-ASM: encoding: [0x5b,0x71,0x00,0x00]
ri.vzero.v v2
# CHECK-ASM-AND-OBJ: ri.vzero.v v3
# CHECK-ASM: encoding: [0xdb,0x71,0x00,0x00]
ri.vzero.v v3

# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v0, zero, 0
# CHECK-ASM: encoding: [0x5b,0x60,0x00,0x40]
ri.vinsert.v.x v0, x0, 0
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v1, s4, 13
# CHECK-ASM: encoding: [0xdb,0x60,0xda,0x40]
ri.vinsert.v.x v1, x20, 13
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v1, zero, 1
# CHECK-ASM: encoding: [0xdb,0x60,0x10,0x40]
ri.vinsert.v.x v1, x0, 1
# CHECK-ASM-AND-OBJ: ri.vinsert.v.x v23, ra, 1
# CHECK-ASM: encoding: [0xdb,0xeb,0x10,0x40]
ri.vinsert.v.x v23, x1, 1

# CHECK-ASM-AND-OBJ: ri.vextract.x.v s4, v1, 13
# CHECK-ASM: encoding: [0x5b,0xaa,0x16,0x5e]
ri.vextract.x.v x20, v1, 13
# CHECK-ASM-AND-OBJ: ri.vextract.x.v s5, v2, 31
# CHECK-ASM: encoding: [0xdb,0xaa,0x2f,0x5e]
ri.vextract.x.v x21, v2, 31
1 change: 1 addition & 0 deletions llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ Experimental extensions
xqcilo 0.2
xqcilsm 0.2
xqcisls 0.2
xrivosvisni 0.1
xrivosvizip 0.1

Supported Profiles
Expand Down
Loading