Skip to content

[RISCV][MC] Implement MC for Base P extension #123271

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
87f3f8c
[RISCV][MC] Implement MC for Base P extension
realqhc Oct 30, 2024
4d59310
add comment for Base P in RISCVFeatures.td
realqhc Jan 17, 2025
0ec3cc1
update ISAInfoTest
realqhc Jan 17, 2025
6e73065
change version to 0.12
realqhc Jan 17, 2025
a406a8d
fix tests
realqhc Jan 20, 2025
a36987a
fix code format, remove unneeded default arguments, fix simm10 leaf d…
realqhc Jan 20, 2025
7061656
update extension to version 014
realqhc Feb 12, 2025
f84ec86
remove extra name
realqhc Feb 14, 2025
70412f8
add RVPGPRPairRV32 to encode GPR pairs correctly with 4-bit fields. F…
realqhc Feb 14, 2025
e8dcf91
Merge branch 'main' into p-mc
realqhc Feb 16, 2025
cba5a90
Update llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
realqhc Feb 27, 2025
7144f9e
Merge branch 'main' into p-mc
realqhc Feb 27, 2025
a7a7448
fix code indentation, move opcodestr after funct3
realqhc Feb 28, 2025
3a10762
fix encoding in RVPUnaryImm8 and RVPUnaryImm9 where rd is RVPGPRPairR…
realqhc Feb 28, 2025
176875a
Merge branch 'main' into p-mc
realqhc Mar 14, 2025
12cb98d
rename decoder namespace to POverlap as it is only overlapping with P…
realqhc Mar 14, 2025
212b5b1
Merge branch 'main' into p-mc
realqhc Mar 16, 2025
95c4177
change POverlap to use RV32GPRPair32 for now.
realqhc Mar 16, 2025
ac380d5
Merge branch 'main' into p-mc
realqhc Mar 24, 2025
ba4c8cb
make p use RV32Only, fix variant kind
realqhc Mar 24, 2025
e12173f
remove RVPUnary and fix test related to it
realqhc Mar 24, 2025
c58b0c9
fix sll that uses immediate shift
realqhc Mar 24, 2025
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
3 changes: 3 additions & 0 deletions llvm/docs/RISCVUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ The primary goal of experimental support is to assist in the process of ratifica
``experimental-zvqdotq``
LLVM implements the `0.0.1 draft specification <https://github.com/riscv/riscv-dot-product/releases/tag/v0.0.1>`__.

``experimental-p``
LLVM implements the `014 draft specification <https://jhauser.us/RISCV/ext-P/RVP-baseInstrs-014.pdf>`__.

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`.

Vendor Extensions
Expand Down
13 changes: 13 additions & 0 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,16 @@ struct RISCVOperand final : public MCParsedAsmOperand {

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

bool isSImm10() const {
if (!isImm())
return false;
int64_t Imm;
RISCVMCExpr::Specifier VK = RISCVMCExpr::VK_None;
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
return IsConstantImm && isInt<10>(fixImmediateForRV32(Imm, isRV64Imm())) &&
VK == RISCVMCExpr::VK_None;
}

bool isSImm10Lsb0000NonZero() const {
if (!isImm())
return false;
Expand Down Expand Up @@ -1730,6 +1740,9 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
return generateImmOutOfRangeError(
Operands, ErrorInfo, 4, (1 << 10) - 4,
"immediate must be a multiple of 4 bytes in the range");
case Match_InvalidSImm10:
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 9),
(1 << 9) - 1);
case Match_InvalidSImm10Lsb0000NonZero:
return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 9), (1 << 9) - 16,
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ static DecodeStatus DecodeGPRPairCRegisterClass(MCInst &Inst, uint32_t RegNo,
return MCDisassembler::Success;
}

static DecodeStatus decodeRVPGPRPair(MCInst &Inst, uint32_t RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
return DecodeGPRPairRegisterClass(Inst, RegNo << 1, Address, Decoder);
}

static DecodeStatus DecodeSR07RegisterClass(MCInst &Inst, uint32_t RegNo,
uint64_t Address,
const void *Decoder) {
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ enum OperandType : unsigned {
OPERAND_UIMM8_GE32,
OPERAND_UIMM9_LSB000,
OPERAND_UIMM10,
OPERAND_SIMM10,
OPERAND_UIMM10_LSB00_NONZERO,
OPERAND_UIMM11,
OPERAND_UIMM12,
Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class RISCVMCCodeEmitter : public MCCodeEmitter {
unsigned getRegReg(const MCInst &MI, unsigned OpNo,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;

unsigned getRVPGPRPair(const MCInst &MI, unsigned OpNo,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
};
} // end anonymous namespace

Expand Down Expand Up @@ -634,4 +638,15 @@ unsigned RISCVMCCodeEmitter::getRegReg(const MCInst &MI, unsigned OpNo,
return Op | Op1 << 5;
}

unsigned RISCVMCCodeEmitter::getRVPGPRPair(const MCInst &MI, unsigned OpNo,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
const MCOperand &MO = MI.getOperand(OpNo);
assert(MO.isReg() && "Expected a register.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCOperand::getReg already asserts if it's not register, so I think you can remove this line.


unsigned Op = Ctx.getRegisterInfo()->getEncodingValue(MO.getReg());

return Op >> 1;
}

#include "RISCVGenMCCodeEmitter.inc"
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,9 @@ include "RISCVInstrInfoV.td"
include "RISCVInstrInfoZvk.td"
include "RISCVInstrInfoZvqdotq.td"

// Packed SIMD
include "RISCVInstrInfoP.td"

// Integer
include "RISCVInstrInfoZimop.td"
include "RISCVInstrInfoZicbo.td"
Expand All @@ -2153,6 +2156,7 @@ include "RISCVInstrInfoZc.td"
include "RISCVInstrInfoZcmop.td"
include "RISCVInstrInfoZclsd.td"


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray change

//===----------------------------------------------------------------------===//
// Vendor extensions
//===----------------------------------------------------------------------===//
Expand Down
Loading