174 Commits

Author SHA1 Message Date
林克
6842cc5562
[RISCV] Add SpacemiT XSMTVDot (SpacemiT Vector Dot Product) extension. (#151706)
The full spec can be found at spacemit-x60 processor support scope:
Section 2.1.2.2 (Features):

https://developer.spacemit.com/documentation?token=BWbGwbx7liGW21kq9lucSA6Vnpb#2.1

This patch only supports assembler.
2025-08-18 18:03:17 +08:00
Jim Lin
b9ca01b746 [RISCV] Move the decoder table for XCV, Xqci and XRivos from standard section to vendor section. NFC 2025-08-08 11:18:18 +08:00
Craig Topper
5846381133 [RISCV] Move definitions of decodeZcmpRlist/decodeXqccmpRlistS0 to their declarations. NFC
These don't need anything from RISCVDisassemblerTables.inc so we
can define them earlier.
2025-07-28 11:30:39 -07:00
Craig Topper
c2df717aa9
[RISCV] Merge some of the C_*_HINT instruction into the regular C_* instructions. (#150710)
Register classes and immediate predicates in a CompressPat no longer
need to match the compressed instruction. We can now merge most of the
C_*_HINT instructions into their non-HINT equivalents.

I've left c.slli64/srli64/srai6 out to avoid conflict with #150689.
C_NOP_HINT is left out because the spec refers to C_NOP as a separate
instruction from C_ADDI. C_NOP does not allow an immediate operand but
C_NOP_HINT does.
2025-07-25 20:55:15 -07:00
Jim Lin
22707fd4a5
[RISCV] Add Andes XAndesBFHCvt (Andes Scalar BFLOAT16) extension (#148563)
The spec can be found at:

https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

The extension includes only two instructions: one for converting from
f32 to f16, and another for converting from f16 to f32.

This patch only implements MC support for XAndesBFHCvt.
2025-07-15 08:59:00 +08:00
Jim Lin
3f33e7ba5b
[RISCV] Add Andes XAndesVSIntLoad (Andes Vector INT4 Load) extension (#147005)
The spec can be found at:
https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only implements MC support for XAndesVSIntLoad.

---------

Co-authored-by: Lino Hsing-Yu Peng <linopeng@andestech.com>
2025-07-07 13:01:22 +08:00
UmeshKalappa
032966ff56
[RISCV] Added the MIPS prefetch extensions for MIPS RV64 P8700. (#145647)
the extension enabled with xmipscbop.

Please refer "MIPS RV64 P8700/P8700-F Multiprocessing System
Programmer’s Guide" for more info on the extension at
https://mips.com/wp-content/uploads/2025/06/P8700_Programmers_Reference_Manual_Rev1.84_5-31-2025.pdf
2025-07-03 10:59:10 +02:00
Craig Topper
c9bfdae620
[RISCV] Use uint64_t for Insn in getInstruction32 and getInstruction16. NFC (#146619)
Insn is passed to decodeInstruction which is a template function based
on the type of Insn. By using uint64_t we ensure only one version of
decodeInstruction is created. This reduces the file size of
RISCVDisassembler.cpp.o by ~25% in my local build.
2025-07-01 21:45:02 -07:00
Jim Lin
8ddada41df
[RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) extension (#144320)
The spec can be found at:
https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only supports assembler. The instructions are similar to
`Zvfbfmin` and the only difference with `Zvfbfmin` is that
`XAndesVBFHCvt` doesn't have mask variant.
2025-06-18 09:17:46 +08:00
Andrew Rogers
19658d1474
[llvm] annotate interfaces in llvm/Target for DLL export (#143615)
## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm/Target` library.
These annotations currently have no meaningful impact on the LLVM build;
however, they are a prerequisite to support an LLVM Windows DLL (shared
library) build.

## Background

This effort is tracked in #109483. Additional context is provided in
[this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

A sub-set of these changes were generated automatically using the
[Interface Definition Scanner (IDS)](https://github.com/compnerd/ids)
tool, followed formatting with `git clang-format`.

The bulk of this change is manual additions of `LLVM_ABI` to
`LLVMInitializeX` functions defined in .cpp files under llvm/lib/Target.
Adding `LLVM_ABI` to the function implementation is required here
because they do not `#include "llvm/Support/TargetSelect.h"`, which
contains the declarations for this functions and was already updated
with `LLVM_ABI` in a previous patch. I considered patching these files
with `#include "llvm/Support/TargetSelect.h"` instead, but since
TargetSelect.h is a large file with a bunch of preprocessor x-macro
stuff in it I was concerned it would unnecessarily impact compile times.

In addition, a number of unit tests under llvm/unittests/Target required
additional dependencies to make them build correctly against the LLVM
DLL on Windows using MSVC.

## Validation

Local builds and tests to validate cross-platform compatibility. This
included llvm, clang, and lldb on the following configurations:

- Windows with MSVC
- Windows with Clang
- Linux with GCC
- Linux with Clang
- Darwin with Clang
2025-06-17 13:28:45 -07:00
Craig Topper
a0b6cfd975
[RISCV] Add MC layer support for XSfmm*. (#133031)
This adds assembler/disassembler support for XSfmmbase 0.6 and related
SiFive matrix multiplication extensions based on the spec here
https://www.sifive.com/document-file/xsfmm-matrix-extensions-specification

Functionality-wise, this is the same as the Zvma extension proposal that
SiFive shared with the Attached Matrix Extension Task Group. The
extension names and instruction mnemonics have been changed to use
vendor prefixes.

Note this is a non-conforming extension as the opcodes used here are in
the standard opcode space in OP-V or OP-VE.

---------

Co-authored-by: Brandon Wu <brandon.wu@sifive.com>
2025-05-21 08:26:35 -07:00
Iris Shi
1e503d08e1
[RISCV][MC] Add support for Q extension (#139369)
Closes #130217.

https://github.com/riscv/riscv-isa-manual/blob/main/src/q-st-ext.adoc
2025-05-15 10:51:06 +08:00
Jim Lin
2a8960e48b
[RISCV] Add Andes XAndesVDot (Andes Vector Dot Product) extension. (#139849)
The spec can be found at:

https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only supports assembler.

Intrinsics support will be added in a later patch.
2025-05-15 10:14:58 +08:00
Jim Lin
9e27db0a50
[RISCV] Add Andes XAndesVPackFPH (Andes Vector Packed FP16) extension. (#138827)
The spec can be found at:

https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only supports assembler.

Intrinsics support will be added in a later patch.
2025-05-12 16:58:39 +08:00
Jim Lin
6ba1a62a6c
[RISCV] Add Andes XAndesperf (Andes Performance) extension. (#135110)
The spec can be found at:
https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only supports assembler.

Relocation and fixup for the branch and gp-implied instructions will be
added in a later patch.
2025-04-28 17:23:51 +08:00
Djordje Todorovic
d30a5b41fe
[RISCV] Fix xmipscmov extension name (#135647)
The right name was used in riscv-toolchain-conventions docs.
2025-04-15 23:17:03 +02:00
Craig Topper
19e0233eb8 [RISCV] Make decodeXqccmpRlistS0 defer to decodeZcmpRlist after checking for S0 being included. NFC
This reduces code duplication.
2025-04-04 13:59:49 -07:00
Craig Topper
d341b632a1 [RISCV] Remove unused function declaration. NFC 2025-04-04 13:27:38 -07:00
Craig Topper
9069ba183d [RISCV] Rename Spimm to StackAdj in most places. NFC
Spimm in the spec refers to the 2-bit encoded value. All of the code
uses the 0, 16, 32, or 48 adjustment value.

Also remove the decodeZcmpSpimm as its identical to the default
behavior for no custom DecoderMethod.
2025-04-04 12:49:09 -07:00
Sudharsan Veeravalli
536fe74aaa
[RISCV] Modify register type of extd* Xqcibm instructions (#134027)
The v0.8 spec specifies that rs1 cannot be x31 (t6) since these
instructions operate on a pair of registers (rs1 and rs1 + 1) with no wrap
around.

The latest spec can be found here:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.8.0
2025-04-02 12:14:50 +05:30
Craig Topper
e3adf6bbfc
[RISCV] Use decodeCLUIImmOperand when disassembling C_LUI_HINT. (#133789)
This correctly rejects imm==0 and prints 1048575 instead of -1.

I've modified the test to only have each hex pattern once with different
check lines before it. This ensures we don't have more invalid messages
printed than we're checking for.
2025-03-31 21:49:07 -07:00
Craig Topper
386aca4a3c
[RISCV] Correct disassembly of cm.push/pop for RVE. (#133816)
We shouldn't disassemble any encoding that refers to registers x16-x31
with RV32E.
2025-03-31 20:54:19 -07:00
Craig Topper
ea68b22881
[RISCV] Prevent disassembling RVC hint instructions with x16-x31 for RVE. (#133805)
We can't ignore the return value form the GPR decode function, as it
contains the RVE check.
2025-03-31 20:49:51 -07:00
Craig Topper
508a6b2e01
[RISCV] Use decodeUImmLog2XLenNonZeroOperand in decodeRVCInstrRdRs1UImm. NFC (#133759)
decodeUImmLog2XLenNonZeroOperand already contains the uimm5 check for
RV32 so we can reuse it. This makes C_SLLI_HINT code more similar to the
tblgen code for C_SLLI.
2025-03-31 17:59:02 -07:00
Paul Bowen-Huggett
ea06f7f96f
[RISCV] For RV32C, disassembly of c.slli should fail when immediate > 31 (#133713)
Fixes #133712.

The change causes `c.slli` instructions whose immediate has bit 5 set to
be rejected when disassembling RV32C. Added a test to exhaustively cover
c.slli for 32 bit targets. A minor tweak to make the debug output a
little more readable.

The spec. (20240411) says:

> For RV32C, shamt[5] must be zero; the code points with shamt[5]=1 are
designated for custom extensions. For RV32C and RV64C, the shift amount
must be non-zero; the code points with shamt=0 are HINTs. For all base
ISAs, the code points with rd=x0 are HINTs, except those with shamt[5]=1
in RV32C.
2025-03-31 08:51:34 -07:00
quic_hchandel
edef028029
[RISCV] Add Qualcomm uC Xqciio (External Input Output) extension (#132721)
This extension adds two external input output instructions for
non-memory-mapped device.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2025-03-28 19:47:29 -07:00
Craig Topper
973bf4d53b
[RISCV] Remove unnecessary if guard before calling SignExtend64<6> in decodeCLUIImmOperand. NFC (#133514) 2025-03-28 15:46:02 -07:00
Paul Bowen-Huggett
bc37fea107
[RISCV] Fix the disassembler's handling of C.LUI when imm=0 (#133450)
Fix for #133446.

According to the RISC-V spec: "C.LUI is valid only when rd≠{x0,x2}, and
when the immediate is not equal to zero. The code points with imm=0 are
reserved".

This change makes the disassembler consider code points with imm=0 as
illegal. It introduces a test which exercises every C.LUI opcode
including the illegal ones but excluding those assigned to C.ADDI16SP).
Output for +c, +c +Zcmop, and +c +no-rvc-hints is checked.
2025-03-28 11:18:21 -07:00
Sam Elliott
75ca080dab
[RISCV][Xqccmp] Correctly Parse/Disassemble pushfp (#133188)
In the `qc.cm.pushfp` instruction, it is like `cm.pushfp` except in one
important way - `qc.cm.pushfp {ra}, -N*16` is not a valid encoding,
because this would update `s0`/`fp`/`x8` without saving it.

This change now correctly rejects this variant of the instruction, both
during parsing and during disassembly. I also implemented validation for
immediates that represent register lists (both kinds), which may help to
catch bugs in the future.
2025-03-27 17:43:26 -07:00
Craig Topper
d58f57228d
[RISCV] Use named sub-operands to simplify encoding/decoding for CoreV Reg-Reg instructions. (#133181)
We can name the sub-operands using a DAG in the 'ins'. This allows those
names to be matched to the encoding fields. This removes the need for a
custom encoder/decoder that treats the 2 sub-operands as a single 10-bit
value.

While doing this, I noticed the base and offset names in the
MIOperandInfo were swapped relative to how the operands are parsed and
printed. Assuming that I've correctly understood the parsing/print
format as "offset(base)".
2025-03-26 19:58:35 -07:00
Sudharsan Veeravalli
e7107973b8
Recommit "[RISCV] Add Qualcomm uC Xqcisync (Sync Delay) extension (#132184)" (#132520)
With a minor fix for the build failures.

Original message:

This extension adds nine instructions, eight for non-memory-mapped devices synchronization and delay instruction.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli quic_svs@quicinc.com
2025-03-22 11:07:48 +05:30
Kazu Hirata
fe7776eab8 Revert "[RISCV] Add Qualcomm uC Xqcisync (Sync Delay) extension (#132184)"
This reverts commit 3840f787a21a66686f5d8bf61877d41f3a65f205.

Multiple builtbot failures have been reported:
https://github.com/llvm/llvm-project/pull/132184
2025-03-21 20:28:11 -07:00
quic_hchandel
3840f787a2
[RISCV] Add Qualcomm uC Xqcisync (Sync Delay) extension (#132184)
This extension adds nine instructions, eight for non-memory-mapped
devices synchronization and delay instruction.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2025-03-22 07:57:07 +05:30
quic_hchandel
0744d4926a
[RISCV] Add Qualcomm uC Xqcilb (Long Branch) extension (#131996)
This extension adds two long branch instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2025-03-20 11:14:53 +05:30
dong-miao
480202f0d1
[RISCV] Add Zilsd and Zclsd Extensions (#131094)
This commit adds the Load/Store pair instructions (Zilsd) and Compressed
Load/Store pair instructions (Zclsd).

[Specification
link](https://github.com/riscv/riscv-isa-manual/blob/main/src/zilsd.adoc).
2025-03-19 08:53:41 -07:00
Sudharsan Veeravalli
467e5a1d41
[RISCV] Add Qualcomm uC Xqcisim (Simulation Hint) extension (#128833)
This extension adds 10 instructions that provide hints to the interface
simulation environment.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/

This patch adds assembler only support.
2025-03-18 09:05:22 -07:00
quic_hchandel
036c6cb37c
[RISCV] Add Qualcomm uC Xqcibi (Branch Immediate) extension (#130779)
This extension adds twelve conditional branch instructions that use an
immediate operand for the source.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2025-03-18 15:18:43 +05:30
Craig Topper
d2e1e30348
[RISCV] Rename some DecoderNamespaces and cleanup debug messages. NFC (#131409)
Rename RISCV32GPRPair and RISCV32Only_ to RV32Only. This gives a more
natural home for the P extension RV32 conflicts.

While I was there I made some improvements to the debug messages.
2025-03-17 12:49:08 -07:00
u4f3
e61859f14d
[RISCV] Add Qualcomm uC Xqcili (load large immediates) extension (#130012)
The Xqcili extension includes a two instructions that load large
immediates than is available with the base RISC-V ISA.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.
2025-03-13 11:13:02 -07:00
Craig Topper
62e37a8a0a
[RISCV][Disassembler] Use a table to store all the decoder tables and their associated features. NFC (#130883)
Replace the macros with a table that we can iterate over. Use a
different table for each possible instruction bitwidth.
2025-03-12 20:15:17 -07:00
Craig Topper
9b066f0b57 [RISCV] Merge DecoderNamespace for CORE-V extensions. NFC
Similar to Qualcomm, Sifive, T-Head, and Rivos extensions.
2025-03-10 15:38:46 -07:00
Craig Topper
d72f6204fd
[RISCV] Merge DecoderNamespace for T-Head extensions. NFC (#130555)
Consistent with what has been done for Rivos, SiFive, and Qualcomm
extensions.
2025-03-10 10:15:12 -07:00
quic_hchandel
6e7e46cafe
[RISCV] Add Qualcomm uC Xqcibm (Bit Manipulation) extension (#129504)
This extension adds thirty eight  bit manipulation instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.6

This patch adds assembler only support.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2025-03-06 12:01:53 +05:30
Craig Topper
f3b18491e8
[RISCV] Consolidate some DecoderNamespaces for standard extensions. (#128954)
First thing to know is that the subtarget feature checks used to block
accessing a decoder table are only a performance optimization and not
required for functionality. The tables have their own predicate checks.
I've removed them from all the standard extension tables.

-RV32 Zacas decoder namespace has been renamed to RV32GPRPair, I think
Zilsd(rv32 load/store pair) can go in here too.
-The RV32 Zdinx table has been renamed to also use RV32GPRPair.
-The Zfinx table has been renamed to remove superflous "RV" prefix.
-Zcmp and Zcmt tables have been combined into a ZcOverlap table. I think
 Zclsd(rv32 compressed load/store pair) can go in here too.
-All the extra standard extension tables are checked after the main
 standard extension table. This makes the common case of the main table
 matching occur earlier.
-Zicfiss is the exception to this as it needs to be checked before
 the main table since it overrides some encodings from Zcmop. This
can't be handled by a predicate based priority as Zicfiss only overrides
 a subset of Zcmop encodings.
2025-02-27 14:56:54 -08:00
Sam Elliott
5066d7b601
[RISCV] Add Xqccmp 0.1 Assembly Support (#128731)
Xqccmp is a new spec by Qualcomm that makes a vendor-specific effort to
solve the push/pop + frame pointers issue. Broadly, it takes the Zcmp
instructions and reverse the order they push/pop registers in, which
ends up matching the frame pointer convention.

This extension adds a new instruction not present in Zcmp,
`qc.cm.pushfp`, which will set `fp` to the incoming `sp` value after it
has pushed the registers.

This change duplicates the Zcmp implementation, with minor changes to
mnemonics (for the `qc.` prefix), predicates, and the addition of
`qc.cm.pushfp`. There is also new logic to prevent combining Xqccmp and
Zcmp. Xqccmp is kept separate to Xqci for decoding/encoding etc, as the
specs are separate today.

Specification:
https://github.com/quic/riscv-unified-db/releases/tag/Xqccmp_extension-0.1.0
2025-02-26 20:03:02 -08:00
Philip Reames
8039f8e139
[RISCV][MC] Add assembler support for XRivosVisni (#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.
2025-02-26 08:55:35 -08:00
Craig Topper
472ea0b782
[RISCV] Merge some of the Sifive decoder tables. (#128794)
This makes a single table for vector and another table for system. I
left sf.cease out of system because its not in custom encoding space.
The other system instructions are in the custom part of OPC_SYSTEM.
2025-02-25 20:47:52 -08:00
Sam Elliott
f22291c791
[RISCV][NFC] Merge Xqci Decoder Tables (#128140)
RISC-V has multiple decoder tables because there is no guarantee that
non-standard extensions do not overlap with each other.

Qualcomm's Xqci family of extensions are intended to be implemented
together, and therefore we want a single decode table for this group of
extensions. This should be more efficient overall, and allows us to use
tablegen's existing mechanism that finds overlapping encodings within
the group.

To implement this, the key addition is `TRY_TO_DECODE_FEATURE_ANY`,
which will use the provided decoder table if any of the features from
the FeatureBitset (first argument) are enabled, rather than if all are
enabled.
2025-02-25 11:14:04 -08:00
Sam Elliott
c8136da26c
[RISCV] Correctly Decode Unsigned Immediates with Ranges (#128584)
We currently have two operands upstream that are an unsigned immediate
with a range constraint - `uimm8ge32` (for `cm.jalt`) and `uimm5gt3`
(for `qc.shladd`).

Both of these were using `decodeUImmOperand<N>` for decoding. For `Zcmt`
this worked, because the generated decoder automatically checked for
`cm.jt` first because the 8 undefined bits in `cm.jalt` are `000?????`
in `cm.jt` (this is to do with the range lower-bound being a
power-of-two). For Zcmt, this patch is NFC.

We have less luck with `Xqciac` - `qc.shladd` is being decoded where the
`uimm5` field is 3 or lower. This patch fixes this by introducing a
`decodeUImmOperandGE<Width, LowerBound>` helper, which will corretly
return `MCDisassembler::Fail` when the immediate is below the lower
bound.

I have added a test to show the encoding where `uimm5` is equal to 3 is
no longer disassembled as `qc.shladd`.
2025-02-25 11:12:08 -08:00
quic_hchandel
538b898a83
[RISCV] Add Qualcomm uC Xqcilia (Large Immediate Arithmetic) extension (#124706)
This extension adds eight 48 bit large arithmetic instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
2025-02-24 08:04:29 -08:00