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

unused_opcodes

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_opcodes

I-Format: imm | rs1 | func3 | rd | opcode

r_opcodes

R-Format: funct7 | rs2 | rs1 | funct3 | rd | opcode

f2_opcodes

Simmilar to the std R-Format, but with 2 instead of 7 additional funct bits.

Classes

OpcodeGenerator

Class to store and get the next free opcode and funct3

FunctNOpcodeGenerator

Class to generate opcodes with an additional funct field, like the standard R-Format

Functions

_reset_enc_generators()

This function should only be used in the unit tests!

get_mm_encoding(in_operands, out_operands) → List[Union[m2isar.metamodel.arch.BitField, m2isar.metamodel.arch.BitVal]]

Finds the next available Opcode and creates the encoding for use with the m2isar metamodel

get_cdsl_encoding(operands) → str

Generate an encoding for the given operands

reg_bitfield(name) → m2isar.metamodel.arch.BitField

Helper funtion to reduce boilerplate code

update_imm_width(immediate, width) → None

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

opcode: int | None = None[source]
funct3: int = 0[source]
get() → Tuple[int, int][source]

Get a new opcode as a tuple of (minor, major) opcode, Returns (funct3, opcode)

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

opcode_generator[source]
opcode: int = 0[source]
funct3: int | None = None[source]
n: int[source]
funct_n: int = 0[source]
get() → Tuple[int, int, int][source]

returns (functN, funct3, opcode)

i_opcodes[source]

I-Format: imm | rs1 | func3 | rd | opcode 31:20 |19:15| 14:12 |11:7| 6:0

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