m2isar.transforms.encode_instructions.instr_encodings
This module will create Objects on import which are used to generate Opcodes for custom instructions In Python an Imports will only create the import Object once, so they act like a singleton
Currently this only includes Greenfield instructions and only uses the major opcodes Custom[0-3] as specified by the RISC-V standard
This could be changed in the future by adding a function which adds unused opcodes to the list
Attributes
only using the major op-codes custom-[0,3] as specified in table 19.1 in "Volume I: RISC-V User-Level ISA V2.2" |
|
I-Format: imm | rs1 | func3 | rd | opcode |
|
R-Format: funct7 | rs2 | rs1 | funct3 | rd | opcode |
|
Simmilar to the std R-Format, but with 2 instead of 7 additional funct bits. |
Classes
Class to store and get the next free opcode and funct3 |
|
Class to generate opcodes with an additional funct field, like the standard R-Format |
Functions
This function should only be used in the unit tests! |
|
|
Finds the next available Opcode and creates the encoding for use with the m2isar metamodel |
|
Generate an encoding for the given operands |
|
Helper funtion to reduce boilerplate code |
|
Adjust the width of an immediate to fit the encoding |
Module Contents
- unused_opcodes = [107, 119, 87, 11, 43, 91, 123][source]
only using the major op-codes custom-[0,3] as specified in table 19.1 in “Volume I: RISC-V User-Level ISA V2.2” bits 1:0 are always 11; 00, 01 and 10 are used by the compressed instructions bits 4:2 = 111 could be used if we decide to limit the usage to 32 bit instrucions/rv32 If the opcodes dont need to be standard compatible, this list could be extended at runtime with the opcodes of the unused extensions
- class OpcodeGenerator[source]
Class to store and get the next free opcode and funct3 This should never be used outside of this module, and only be instantiated once
- class FunctNOpcodeGenerator(opcode_gen: OpcodeGenerator, funct_size: int)[source]
Class to generate opcodes with an additional funct field, like the standard R-Format gets a reference to a basic opcode generator
- r_opcodes[source]
R-Format: funct7 | rs2 | rs1 | funct3 | rd | opcode 31:25 |24:20|19:15| 14:12 |11:7| 6:0
- f2_opcodes[source]
Simmilar to the std R-Format, but with 2 instead of 7 additional funct bits. Allows for 3 registers and a 5 bit immediate. Used by e.g. Core-V cv.addN
- _reset_enc_generators()[source]
This function should only be used in the unit tests! It resets the encoding generators, so tests can run independently or in succession
- get_mm_encoding(in_operands: Dict[str, m2isar.transforms.encode_instructions.operands.Operand], out_operands) List[m2isar.metamodel.arch.BitField | m2isar.metamodel.arch.BitVal][source]
Finds the next available Opcode and creates the encoding for use with the m2isar metamodel
- get_cdsl_encoding(operands: Dict[str, m2isar.transforms.encode_instructions.operands.Operand]) str[source]
Generate an encoding for the given operands
Actual encoding gets generated by “get_mm_encoding()” and just performes string formating to emmit CoreDSL
- reg_bitfield(name: str) m2isar.metamodel.arch.BitField[source]
Helper funtion to reduce boilerplate code Returns a BitField Object with the specified name
- update_imm_width(immediate: m2isar.transforms.encode_instructions.operands.Operand, width: int) None[source]
Adjust the width of an immediate to fit the encoding