Git Product home page Git Product logo

riscv-opcodes's Introduction

riscv-opcodes

This repo enumerates standard RISC-V instruction opcodes and control and status registers. It also contains a script to convert them into several formats (C, Scala, LaTeX).

Artifacts (encoding.h, latex-tables, etc) from this repo are used in other tools and projects like Spike, PK, RISC-V Manual, etc.

Project Structure

├── constants.py    # contains variables, constants and data-structures used in parse.py
├── encoding.h      # the template encoding.h file
├── LICENSE         # license file
├── Makefile        # makefile to generate artifacts
├── parse.py        # python file to perform checks on the instructions and generate artifacts
├── README.md       # this file
├── rv*             # instruction opcode files
└── unratified      # contains unratified instruction opcode files

File Naming Policy

This project follows a very specific file structure to define the instruction encodings. All files containing instruction encodings start with the prefix rv. These files can either be present in the root directory (if the instructions have been ratified) or the unratified directory. The exact file-naming policy and location is as mentioned below:

  1. rv_x - contains instructions common within the 32-bit and 64-bit modes of extension X.
  2. rv32_x - contains instructions present in rv32x only (absent in rv64x e.g.. brev8)
  3. rv64_x - contains instructions present in rv64x only (absent in rv32x, e.g. addw)
  4. rv_x_y - contains instructions when both extension X and Y are available/enabled. It is recommended to follow canonical ordering for such file names as specified by the spec.
  5. unratified - this directory will also contain files similar to the above policies, but will correspond to instructions which have not yet been ratified.

When an instruction is present in multiple extensions and the spec is vague in defining the extension which owns the instruction, the instruction encoding must be placed in the first canonically ordered extension and should be imported(via the $import keyword) in the remaining extensions.

Encoding Syntax

The encoding syntax uses $ to indicate keywords. As of now 2 keywords have been identified : $import and $pseudo_op (described below). The syntax also uses :: as a means to define the relationship between extension and instruction. .. is used to defined bit ranges. We use # to define comments in the files. All comments must be in a separate line. In-line comments are not supported.

Instruction syntaxes used in this project are broadly categorized into three:

  • regular instructions :- these are instructions which hold a unique opcode in the encoding space. A very generic syntax guideline for these instructions is as follows:

    <instruction name> <arguments>
    

    where <argument> is either <bit encoding> or <variable argument>.

    Examples:

    lui     rd imm20 6..2=0x0D 1..0=3
    beq     bimm12hi rs1 rs2 bimm12lo 14..12=0 6..2=0x18 1..0=3
    

    The bit encodings are usually of 2 types:

    • single bit assignment : here the value of a single bit is assigned using syntax <bit-position>=<value>. For e.g. 6=1 means bit 6 should be 1. Here the value must be 1 or 0.
    • range assignment: here a range of bits is assigned a value using syntax: <msb>..<lsb>=<val>. For e.g. 31..24=0xab. The value here can be either unsigned integer, hex (0x) or binary (0b).
  • pseudo_instructions (a.k.a pseudo_ops) - These are instructions which are aliases of regular instructions. Their encodings force certain restrictions over the regular instruction. The syntax for such instructions uses the $pseudo_op keyword as follows:

    $pseudo_op <extension>::<base-instruction> <instruction name> <instruction args> <bit-encodings>
    

    Here the <extension> specifies the extension which contains the base instruction. <base-instruction> indicates the name of the instruction this pseudo-instruction is an alias of. The remaining fields are the same as the regular instruction syntax, where all the args and the fields of the pseudo instruction are specified.

    Example:

    $pseudo_op rv_zicsr::csrrs frflags rd 19..15=0 31..20=0x001 14..12=2 6..2=0x1C 1..0=3
    

    If a ratified instruction is a pseudo_op of a regular unratified instruction, it is recommended to maintain this pseudo_op relationship i.e. define the new instruction as a pseudo_op of the unratified regular instruction, as this avoids existence of overlapping opcodes for users who are experimenting with unratified extensions as well.

  • imported_instructions - these are instructions which are borrowed from an extension into a new/different extension/sub-extension. Only regular instructions can be imported. Pseudo-op or already imported instructions cannot be imported. Example:

    $import rv32_zkne::aes32esmi
    

RESTRICTIONS

Following are the restrictions one should keep in mind while defining $pseudo_ops and $imported_ops

  • Pseudo-op or already imported instructions cannot be imported again in another file. One should always import base-instructions only.
  • While defining a $pseudo_op, the base-instruction itself cannot be a $pseudo_op

Flow for parse.py

The parse.py python file is used to perform checks on the current set of instruction encodings and also generates multiple artifacts : latex tables, encoding.h header file, etc. This section will provide a brief overview of the flow within the python file.

To start with, parse.py creates a list of all rv* files currently checked into the repo (including those inside the unratified directory as well). It then starts parsing each file line by line. In the first pass, we only capture regular instructions and ignore the imported or pseudo instructions. For each regular instruction, the following checks are performed :

  • for range-assignment syntax, the msb position must be higher than the lsb position
  • for range-assignment syntax, the value of the range must representable in the space identified by msb and lsb
  • values for the same bit positions should not be defined multiple times.
  • All bit positions must be accounted for (either as args or constant value fields)

Once the above checks are passed for a regular instruction, we then create a dictionary for this instruction which contains the following fields:

  • encoding : contains a 32-bit string defining the encoding of the instruction. Here - is used to represent instruction argument fields
  • extension : string indicating which extension/filename this instruction was picked from
  • mask : a 32-bit hex value indicating the bits of the encodings that must be checked for legality of that instruction
  • match : a 32-bit hex value indicating the values the encoding must take for the bits which are set as 1 in the mask above
  • variable_fields : This is list of args required by the instruction

The above dictionary elements are added to a main instr_dict dictionary under the instruction node. This process continues until all regular instructions have been processed. In the second pass, we now process the $pseudo_op instructions. Here, we first check if the base-instruction of this pseudo instruction exists in the relevant extension/filename or not. If it is present, the the remaining part of the syntax undergoes the same checks as above. Once the checks pass and if the base-instruction is not already added to the main instr_dict then the pseudo-instruction is added to the list. In the third, and final, pass we process the imported instructions.

The case where the base-instruction for a pseudo-instruction may not be present in the main instr_dict after the first pass is if the only a subset of extensions are being processed such that the base-instruction is not included.

Artifact Generation and Usage

The following artifacts can be generated using parse.py:

  • instr_dict.yaml : This is file generated always by parse.py and contains the entire main dictionary instr\_dict in YAML format. Note, in this yaml the dots in an instruction are replaced with underscores
  • encoding.out.h : this is the header file that is used by tools like spike, pk, etc
  • instr-table.tex : the latex table of instructions used in the riscv-unpriv spec
  • priv-instr-table.tex : the latex table of instruction used in the riscv-priv spec
  • inst.chisel : chisel code to decode instructions
  • inst.sverilog : system verilog code to decode instructions
  • inst.rs : rust code containing mask and match variables for all instructions
  • inst.spinalhdl : spinalhdl code to decode instructions
  • inst.go : go code to decode instructions

Make sure you install the required python pre-requisites are installed by executing the following command:

sudo apt-get install python-pip3
pip3 install -r requirements.txt

To generate all the above artifacts for all instructions currently checked in, simply run make from the root-directory. This should print the following log on the command-line:

Running with args : ['./parse.py', '-c', '-go', '-chisel', '-sverilog', '-rust', '-latex', '-spinalhdl', 'rv*', 'unratified/rv*']
Extensions selected : ['rv*', 'unratified/rv*']
INFO:: encoding.out.h generated successfully
INFO:: inst.chisel generated successfully
INFO:: inst.spinalhdl generated successfully
INFO:: inst.sverilog generated successfully
INFO:: inst.rs generated successfully
INFO:: inst.go generated successfully
INFO:: instr-table.tex generated successfully
INFO:: priv-instr-table.tex generated successfully

By default all extensions are enabled. To select only a subset of extensions you can change the EXTENSIONS variable of the makefile to contains only the file names of interest. For example if you want only the I and M extensions you can do the following:

make EXTENSIONS='rv*_i rv*_m' 

Which will print the following log:

Running with args : ['./parse.py', '-c', '-chisel', '-sverilog', '-rust', '-latex', 'rv32_i', 'rv64_i', 'rv_i', 'rv64_m', 'rv_m']
Extensions selected : ['rv32_i', 'rv64_i', 'rv_i', 'rv64_m', 'rv_m']
INFO:: encoding.out.h generated successfully
INFO:: inst.chisel generated successfully
INFO:: inst.sverilog generated successfully
INFO:: inst.rs generated successfully
INFO:: instr-table.tex generated successfully
INFO:: priv-instr-table.tex generated successfully

If you only want a specific artifact you can use one or more of the following targets : c, rust, chisel, sverilog, latex

You can use the clean target to remove all artifacts.

Adding a new extension

To add a new extension of instructions, create an appropriate rv* file based on the policy defined in File Structure. Run make from the root directory to ensure that all checks pass and all artifacts are created correctly. A successful run should print the following log on the terminal:

Running with args : ['./parse.py', '-c', '-chisel', '-sverilog', '-rust', '-latex', 'rv*', 'unratified/rv*']
Extensions selected : ['rv*', 'unratified/rv*']
INFO:: encoding.out.h generated successfully
INFO:: inst.chisel generated successfully
INFO:: inst.sverilog generated successfully
INFO:: inst.rs generated successfully
INFO:: instr-table.tex generated successfully
INFO:: priv-instr-table.tex generated successfully

Create a PR for review.

Enabling Debug logs in parse.py

To enable debug logs in parse.py change level=logging.INFO to level=logging.DEBUG and run the python command. You will now see debug statements on the terminal like below:

DEBUG:: Collecting standard instructions first
DEBUG:: Parsing File: ./rv_i
DEBUG::      Processing line: lui     rd imm20 6..2=0x0D 1..0=3
DEBUG::      Processing line: auipc   rd imm20 6..2=0x05 1..0=3
DEBUG::      Processing line: jal     rd jimm20                          6..2=0x1b 1..0=3
DEBUG::      Processing line: jalr    rd rs1 imm12              14..12=0 6..2=0x19 1..0=3
DEBUG::      Processing line: beq     bimm12hi rs1 rs2 bimm12lo 14..12=0 6..2=0x18 1..0=3
DEBUG::      Processing line: bne     bimm12hi rs1 rs2 bimm12lo 14..12=1 6..2=0x18 1..0=3

How do I find where an instruction is defined?

You can use grep "^\s*<instr-name>" rv* unratified/rv* OR run make and open instr_dict.yaml and search of the instruction you are looking for. Within that instruction the extension field will indicate which file the instruction was picked from.

riscv-opcodes's People

Contributors

4a6f656c avatar a4lg avatar adurbin-rivos avatar aswaterman avatar atulkharerivos avatar ben-marshall avatar chihminchao avatar eflaner avatar furuame avatar hirooih avatar hope51607 avatar i2h2 avatar janmatcodasip avatar kito-cheng avatar lucas-wye avatar mjosaarinen avatar neelgala avatar nrajovic avatar pavelkryukov avatar ptomsich avatar qmn avatar scottj97 avatar sdtwigg avatar sequencer avatar timsifive avatar ved-rivos avatar yenhaochen avatar yunsup avatar zarubaf avatar zenithalhourlyrate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

riscv-opcodes's Issues

Wrong encoding of fmvp.d.x instruction

Seems like fmvp.d.x is not in line with specification. Here is what spec states:

For RV32 only, if the D extension is implemented, the FMVP.D.X instruction moves a double-precision
number from a pair of integer registers into a floating-point register. Integer registers rs1 and rs2
supply bits 31:0 and 63:32, respectively; the result is written to floating-point register rd. FMVP.D.X is
encoded in the OP-FP major opcode with funct3=0 and funct7=1011001

The meaning of the above is that instruction consumes three registers, rs1, rs2 and rd but this is how it is defined in unratified/rv32_d_zfa

fmvp.d.x rd rs1 24..20=1 31..27=0x16 14..12=0 26..25=1 6..2=0x14 1..0=3

From the above it can be oserved that fmvp.d.x consumes rd and rs1 while having rs2=1 which is not in line with spec.

Add documentation

This repo clearly has many assumptions about directory layout, etc. It'd be nice to document how to get it up and running; a minimal README would probably suffice.

opcodes-rvc use of ignore considered unhelpful

This may be debatable: the base opcodes table does a reasonable job a naming the individual fields, suchs as rs1, imm12, bimm12lo, jimm20, etc. Enough that you can make a crude disassembler/assembler based on it as long as those fields names are treated correctly.

It seems that the treatment of compressed instructions is significantly different; instead of naming individual fields (and the myrid of immediate encodings) they have all been named ignore.

Wouldn't it be desirable to do the same for compressed as for uncompressed? Eg. instead of

c.lw       1..0=0 15..13=2 12=ignore 11..2=ignore

we could have (untested)

c.lw       15..13=2 c.uimm6hi rs1' c.uimm6lo rd' 1..0=0

(along with the corresponding parse_opcode changes).

Hard to use as a module

The only way to use this is to modify the sources. Two things would improve this:

  • refactoring the code into a function so we can import it
  • renaming parse-opcodes so it can be a legal module name.

parse-opcodes script

Kindly update parse-opcodes script, if possible. It tries to put encoding.h in the riscv-fesvr directory, whose repo is marked obsolete. Also, it seems encoding.h had been updated in other repos manually, leading to parse-opcodes breaking the previously working builds of the tools.

Missing 15. Vector Mask Instructions

The following instructions mentioned in spec:

15. Vector Mask Instructions

But missing in opcodes-rvv file

vmmv.m
vmclr.m
vmset.m
vmnot.m

vcpop.m

Wrong encoding of Vector Mask-Register Logical Instructions

Hi,

Seems like definitions of Vector Mask-Register Logical Instructions are not up to spec.
Namely, Chapter 15.1 of 1.1-draft Vector spec, says the following:

Vector mask logical instructions are always unmasked, so there are no inactive
elements, and the encodings with vm=0 are reserved.

However, lets take one instruction such as vmand.mm, its definition is as follows
(taken from rv_v file):

vmand.mm 31..26=0x19 vm vs2 vs1 14..12=0x2 vd 6..0=0x57

Here we see it says vm is a varible field, which is not in accordance with spec.

How do we proceed here, should I submit a fix for this?

Thanks

including applicable extensions in the opcode syntax

I have been using this repo as the official source of encodings for our internal design and verification tools. One issue that I have been facing is the lack of concrete information of "under which extension(s) is an instruction applicable". I am looking at decoding only instructions which are applicable for a user-defined ISA. So if the user specifies RV64IMC then only instructions under those 3 extensions must be decoded. Even though the filenaming convention right now is somewhat useful, it does not fully address all the issues. two of which I have described below:

  1. c.flw should be applicable only when F and C are both implemented. So placing it inside opcodes-rvc confuses the tools and having a separate file opcodes-rv32fc increases maintenance.
  2. instructions like pack which are present under multiple extensions (zbp, zbf and zbe). Placing pack into individual opcodes file for each sub-extension might work but is not scalable. One has to remember to edit all those files for any change in the instruction

so, having a file-naming convention alone might not work. The syntax of opcode entries will need to change slightly. The following is a very quick and dirty proposal (and will need refining) of what I think can work to address the above issues:

Add the list of comma-separated extensions under which the encoding is a legal instruction; wrapped within | | at the end of the line.

Examples

c.flw      1..0=0 15..13=3 12=ignore 11..2=ignore |RV32FC|

pack       rd rs1 rs2 31..25=4  14..12=4 6..2=0x0C 1..0=3 |RV32Zbp, RV32Zbf, RV32Zbe, RV64Zbp, RV64Zbf, RV64Zbe|

Tools can then use substring matching to identify if that instruction is applicable for the user-defined ISA or not.

A better way of doing the above would be to use regex (less readable but extremely powerful) :

c.flw      1..0=0 15..13=3 12=ignore 11..2=ignore |RV(32).*(F).*(C).*|

pack       rd rs1 rs2 31..25=4  14..12=4 6..2=0x0C 1..0=3 |RV(32|64).*(Zbp|Zbf|Zbe).*|

The regex will need to follow a few strict guidelines while writing but that should be manageable.

Pros of the proposal:

  • the syntax is pretty regex-able and simply adds on to the current syntax. Current tools depending on this repo will simply need to ignore everything between | |.
  • minimal changes to existing scripts in this repo to generate the current set of artifacts
  • does not require a strict file naming convention - improves scalability
  • number of files in the repo will reduce - improves maintenance

Before I go on to work on a PR for the above, I wanted to get a sense if such a change is welcomed/acceptable?

Arguments Position and Range

It seems that the information about the position and range of the arguments is not encoded, and this information is clearly described in the specification.

If a downstream program is parsing the instr_dict.yaml file generated by parse.py, how should it correctly get the position and range of each argument for a instruction?

rv32_i slli/srli/srai should not pseudo_op from rv64_i

I'm trying to update rocket chip's Instructions.scala since the merge of #106. I found that SLLI_RV32, SRLI_RV32, SRAI_RV32 are not generated. It turns out that rv32_i uses the opcode from rv64_i directly

riscv-opcodes/rv32_i

Lines 1 to 3 in 833ba82

$pseudo_op rv64_i::slli slli rd rs1 shamtw 31..25=0 14..12=1 6..2=0x04 1..0=3
$pseudo_op rv64_i::srli srli rd rs1 shamtw 31..25=0 14..12=5 6..2=0x04 1..0=3
$pseudo_op rv64_i::srai srai rd rs1 shamtw 31..25=32 14..12=5 6..2=0x04 1..0=3

However, this would cause problem. In RV32 if the decoder is fed slli rd, rs, 32 as encoded below, the result would be slli rd, rs, 0 whereas originally this would cause an illegal instruction exception.

000000100000?????001?????0010011

Cc @neelgala

FYI

SLLI_RV32 = BitPat("b0000000??????????001?????0010011")
SLLI      = BitPat("b000000???????????001?????0010011")

HFENCE.BVMA incorrect?

opcodes-system has an encoding for "hfence.vvma" but not hfence.bvma. I'm guessing this is a typo, but figured I'd check before setting up a one-character PR.

Change constant.py to constant.json

The background is in the RocketChip, we need metadatas for instruction decoding, rather than instruction name and bitpat only. For downstreams like us, which need to parse instruction metadata from riscv-opcodes. I think it might be good to change constant.py to parse the constant.json(or some structural text file) to make other projects being able to directly use these constant to generate metadatas.

Platform-specific details in encoding.h

#define DEFAULT_RSTVEC 0x00001000

#define DEFAULT_RSTVEC     0x00001000
#define CLINT_BASE         0x02000000
#define CLINT_SIZE         0x000c0000
#define EXT_IO_BASE        0x40000000
#define DRAM_BASE          0x80000000

Correct me if I'm wrong, but these are platform specific details and seem like they don't belong in a "canonical" RISC-V definitions file

Document parser to clarify what exactly is for what

The parser uses things like masks and matches. From the parsers code, I infer that masks and matches are used for determining what instruction is being (de)coded. I'm writing a RISC-V assembler in Rust that uses this repository to generate all the instruction encoding functions, but I don't know what to set the initial instruction value to (mask or match). How does (en)coding instructions work exactly, assuming I want to use this repository?

RV32_I has only 3 instructions?

When using only the rv32_i EXTENSION, the generated masks are only for slli, srai and srli instructions. The rest are all CSR masks. Is this expected? Aren't there several other instructions in the base integer instruction set? The generated LaTeX table has several other instructions. What happened to all of those? Am I missing something?

Provide a standard format output (json?)

It'd be useful for new consumers of riscv-opcodes for parse-opcodes to have a standardized output format, such as json, in addition to language-specific generators. That'll keep the core simple; people can write their own generators from json to their language of choice out of the tree.

For bonus points, commit the generated json for the core RISC-V ISA when anything changes. Then folks can just grab the json instead of having to get the repo up and running (see #6).

I should also say: Thanks so much for having this. So much nicer than transcribing opcodes from a PDF. :)

Questions about the use of pseudo instructions

From the README's description of pseudo instructions, I think the extension is complete even if these pseudo instructions are removed. But I found slli instruction in rv32_i file with the $pseudo prefix which I think is not a pseudo instruction. I don't think slli in rv32i and slli in rv64i are related in this situation.

Make `instr_dict.yaml` more useful

While the individual code generators are useful, it'd be nice to have a machine-readable version-- sometimes the default generators just aren't a fit! instr_dict.yaml almost gets there, but it only includes the instructions and none of the other useful sideband data like csrs or field positions.

To that end, I'd like to propose the following:

  • Move the current contents of the yaml file (ie, the raw mapping of instructions) to a subfield called eg. 'instructions'. This is a breaking change, but as far as I can tell, no open source code directly uses instr_dict.yaml.
  • Add a format version number to it to track changes
  • Start adding other data to get everything from the constants file automatically copied to the yaml file

I'm willing to put in effort here, but is this something the community is interested in?

instr_dict should contain instruction format

This repo has been very useful for gathering information about the ISA in a programmatic way. I think one of the shortcomings is that it doesn't contain any information about the instruction format (ex: I, J, U ...). This could be used to programmatically verify that implementations are handling the instructions in a correct manner.

Currently I do this manually by cross-referencing the spec itself. Is there a better way to do this?

Overlapping opcodes for certain order of instructions not detected

If you define a R-Type instruction with the same opcode and funct3 fields as a previously defined I-Type instruction, the parse-opcode script will not recognise the overlapping.

Example opcodes file (named opcodes-fail), that produces the error:

foo1  rd rs1 imm12            14..12=0 6..2=2 1..0=3
bar1  rd rs1 rs2     31..25=1 14..12=0 6..2=2 1..0=3

bar0  rd rs1 rs2     31..25=1 14..12=1 6..2=2 1..0=3
foo0  rd rs1 imm12            14..12=1 6..2=2 1..0=3

Shell command:

 cat opcodes-fail | ./parse-opcodes -c

Output:

foo0 and bar0 overlap

encoding.h is very far from up-to-date

The version of encoding.h is not even cloe to up-to-date. It doesn't even have all the CSRs in the ratified priv spec (e.g. PMPCFGx, PMPADDRx). This needs to be regenerated as part of a C/I script whenever something new is added in its dependencies.

Can opcodes be XOR'd?

I want to combine 2 instructions add and addi. Both of them have different opcodes and funct3 values.

While declaring a new instruction that combines both these instructions in the opcodes file, can I declare the opcode and funct3 values as a result obtained by XORing the opcode and funct3 values of add and addi?

Conflicts with shared opcodes

Since the P and V extensions have overlapping functionality, yet are largely suited to different application domains, they are considered mutually incompatible. This avails each extension of the other's major opcode without concern of collision.

As allowed, the proposed Vector Crypto encodings overlap with some of the proposed Packed-SIMD encodings. We are getting conflicts when we run the python script in riscv-opcodes (with crypto opcodes in our own branch):

$ make
Running with args : ['./parse.py', '-c', '-go', '-chisel', '-sverilog', '-rust', '-latex', '-spinalhdl', 'rv*', 'unratified/rv*']
Extensions selected : ['rv*', 'unratified/rv*']
ERROR:: instruction : rstsa16 from rv_p has the same encoding with instruction vsha2ms_vv added from ['rv_zvknh'] in same base extensions
make: *** [Makefile:12: everything] Error 1

Right now both of these extensions are in unratified/rv*, but eventually they will be ratified.

@neelgala We need a means to tell the script which extensions' encodings should be processed and which should be ignored when the opcodes are reused in mutually exclusive extensions.

encoding conflict between Zfbf/fcvt.bf16.s and Zfa/fround.h

here, in riscv-opcodes,
Zfa/fround.h is encoded as rd rs1 24..20=4 31..27=0x08 rm 26..25=2 6..2=0x14 1..0=3
Zfbfmin/fcvt.bf16.s is encoded as rd rs1 24..20=8 31..27=0x08 rm 26..25=2 6..2=0x14 1..0=3

However, In the bfloat16 spec,
Zfbfmin/fcvt.bf16.s is encoded as rd rs1 24..20=4 31..27=0x08 rm 26..25=2 6..2=0x14 1..0=3
which is identical and conflicts with fround.h

For fcvt operations, 22..20 are used for the size of the source operand, but in riscv-opcodes [22] is set if the conversion is from/to bfloat16. However, for zfa ops, [22] is an opcode bit for fround/froundnx. Suggestion: change fround/froundnx to be [23:22]=2 instead of [23:22]=1.

Use fd/fs# for floating point operands

The data in riscv-opcodes-master is almost exactly what I need to generate the instruction and operand parsing code for my work on binary code modeling and analysis, except for one thing: both the integer and floating point register fields are named "rs1", "rs2", "rd". The vector register fields are already named "vs1" etc., and if the floating point registers were changed to "fs1" etc., this data would include everything needed for both bit-level parsing and operand identification.

README should explain usage

The current README.md does not explain how one would use this repo to add support for new instructions. I assume this repo can somehow be used to generate files useful to Spike and/or binutils?

There is some evidence for this in Spike's git repo:

riscv/encoding.h:/* Automatically generated by parse_opcodes.  */

Currently the README only refers to riscv-tools, which is (1) obsolete, and (2) doesn't seem to actually use this repo for anything. (At least, I couldn't find any script that refers to its riscv-opcodes submodule, or the parse_opcodes script.)

Spike crashing after adding new instruction!!

I created a new.h file in the riscv-isa-sim/riscv/insns folder to combine 2 instructions,

addi a5,gp,-1436
add a5,a5,a3

So, the code I wrote to combine these instructions is,

int32_t v0 = sext_xlen(RS1 + insn.i_imm());
WRITE_RD(sext_xlen(v0 + RS1));

When I compiled and ran spike, it crashed.

I think there is something wrong with the logic of my code but I do not know how to fix it.

Does rvv-opcodes include all instructions in rvv-1.0?

Hi Sir,
I have some problems.
(1) I can not find some instructions in rvv-opcodes, such as vlseg3e32 and vluxseq3ei32.v, ...
(2) vslideup.vi has a unsigned imm5, but it has simm5 in rvv-opcodes.

Please give confirmation for these problems.

Thanks!

Can add checking for encoding conflict?

Hello,

For the standard/regular instructions, I think checking for encoding conflict is necessary. Note that only checking encoding conflict for instructions that belong to the same base extension. For example, c_ld and c_flw have the same encoding but no conflict because c_ld only exists on rv64 and c_flw only exists on rv32.

If that is ok, I can submit a patch for that checking.

Missing distinction between RV32 and RV64 (and probably also RV128 when the time comes)

I was debugging some instruction generation, and came across an issue with the encoding of SLLI/SRLI/SRAI: In the ISA manual the 32-bit variant has a 5-bit shamt encoding, and the bits above (up until bit 30 in the case of SRAI) are required to be 0.
However the 64-bit variant uses 6-bit shamt, and because they are different base ISAs all the other encoding bits are the same as the 32-bit version.

This then causes problems when using the generated opcode mappings, as they allow for 6-bit shamt fields, while the 32-bit ISA forbids shamt[5] to be 1...

There may also be other instructions where this is a problem, is there a plan for tackling this?
It's a bit late to change the base ISA spec now, but one immediate solution (if it wasn't too late) would be to swap the encodings for SLLI/SRLI/SRAI and SLLIW/SRLIW/SRAIW in RV64I, which would then keep the instruction field boundaries concistent...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.