Skip to content

Commit 87f3f8c

Browse files
committed
[RISCV][MC] Implement MC for Base P extension
This proposed extension adds Packed-SIMD instructions for RV32 and RV64. Documentation: https://jhauser.us/RISCV/ext-P/RVP-baseInstrs-012.pdf https://jhauser.us/RISCV/ext-P/RVP-instrEncodings-012.pdf This patch is MC-only.
1 parent 1fa02b9 commit 87f3f8c

File tree

15 files changed

+3522
-15
lines changed

15 files changed

+3522
-15
lines changed

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ The primary goal of experimental support is to assist in the process of ratifica
335335
``experimental-svukte``
336336
LLVM implements the `0.3 draft specification <https://github.com/riscv/riscv-isa-manual/pull/1564>`__.
337337

338+
``experimental-p``, ``experimental-p``
339+
LLVM implements the `012 specification <https://jhauser.us/RISCV/ext-P/RVP-baseInstrs-012.pdf>`__.
340+
338341
To use an experimental extension from `clang`, you must add `-menable-experimental-extensions` to the command line, and specify the exact version of the experimental extension you are using. To use an experimental extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, `llvm-mc`), you must prefix the extension name with `experimental-`. Note that you don't need to specify the version with internal tools, and shouldn't include the `experimental-` prefix with `clang`.
339342

340343
Vendor Extensions

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,16 @@ struct RISCVOperand final : public MCParsedAsmOperand {
961961

962962
bool isSImm13Lsb0() const { return isBareSimmNLsb0<13>(); }
963963

964+
bool isSImm10() const {
965+
if (!isImm())
966+
return false;
967+
int64_t Imm;
968+
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
969+
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
970+
return IsConstantImm && isInt<10>(fixImmediateForRV32(Imm, isRV64Imm())) &&
971+
VK == RISCVMCExpr::VK_RISCV_None;
972+
}
973+
964974
bool isSImm10Lsb0000NonZero() const {
965975
if (!isImm())
966976
return false;
@@ -1587,6 +1597,9 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15871597
return generateImmOutOfRangeError(
15881598
Operands, ErrorInfo, 4, (1 << 10) - 4,
15891599
"immediate must be a multiple of 4 bytes in the range");
1600+
case Match_InvalidSImm10:
1601+
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 9),
1602+
(1 << 9) - 1);
15901603
case Match_InvalidSImm10Lsb0000NonZero:
15911604
return generateImmOutOfRangeError(
15921605
Operands, ErrorInfo, -(1 << 9), (1 << 9) - 16,

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ enum OperandType : unsigned {
314314
OPERAND_UIMM8_GE32,
315315
OPERAND_UIMM9_LSB000,
316316
OPERAND_UIMM10,
317+
OPERAND_SIMM10,
317318
OPERAND_UIMM10_LSB00_NONZERO,
318319
OPERAND_UIMM11,
319320
OPERAND_UIMM12,

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,38 @@ def HasStdExtSmctrOrSsctr : Predicate<"Subtarget->hasStdExtSmctrOrSsctr()">,
10161016
"'Smctr' (Control Transfer Records Machine Level) or "
10171017
"'Ssctr' (Control Transfer Records Supervisor Level)">;
10181018

1019+
def FeatureStdExtP
1020+
: RISCVExperimentalExtension<1, 0,
1021+
"'Base P' (Packed SIMD)">;
1022+
def HasStdExtP : Predicate<"Subtarget->hasStdExtP()">,
1023+
AssemblerPredicate<(all_of FeatureStdExtP),
1024+
"'Base P' (Packed SIMD)">;
1025+
1026+
def HasStdExtZbaOrP
1027+
: Predicate<"Subtarget->hasStdExtZba() || Subtarget->hasStdExtP()">,
1028+
AssemblerPredicate<(any_of FeatureStdExtZba, FeatureStdExtP),
1029+
"'Zba' (Address Generation Instructions) or "
1030+
"'Base P' (Packed-SIMD)">;
1031+
1032+
def HasStdExtZbbOrP
1033+
: Predicate<"Subtarget->hasStdExtZbb() || Subtarget->hasStdExtP()">,
1034+
AssemblerPredicate<(any_of FeatureStdExtZbb, FeatureStdExtP),
1035+
"'Zbb' (Basic Bit-Manipulation) or "
1036+
"'Base P' (Packed-SIMD)">;
1037+
1038+
def HasStdExtZbkbOrP
1039+
: Predicate<"Subtarget->hasStdExtZbkb() || Subtarget->hasStdExtP()">,
1040+
AssemblerPredicate<(any_of FeatureStdExtZbkb, FeatureStdExtP),
1041+
"'Zbkb' (Bitmanip instructions for Cryptography) or "
1042+
"'Base P' (Packed-SIMD)">;
1043+
1044+
def HasStdExtZbbOrZbkbOrP
1045+
: Predicate<"Subtarget->HasStdExtZbbOrZbkb()|| Subtarget->hasStdExtP()">,
1046+
AssemblerPredicate<(any_of FeatureStdExtZbb, FeatureStdExtZbkb, FeatureStdExtP),
1047+
"'Zbb' (Basic Bit-Manipulation) or "
1048+
"'Zbkb' (Bitmanip instructions for Cryptography) or "
1049+
"'Base P' (Packed-SIMD)">;
1050+
10191051
//===----------------------------------------------------------------------===//
10201052
// Vendor extensions
10211053
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,9 @@ include "RISCVInstrInfoZicbo.td"
21222122
include "RISCVInstrInfoZicond.td"
21232123
include "RISCVInstrInfoZicfiss.td"
21242124

2125+
// Packed SIMD
2126+
include "RISCVInstrInfoP.td"
2127+
21252128
//===----------------------------------------------------------------------===//
21262129
// Vendor extensions
21272130
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)