m2isar.transforms.encode_instructions.instr_encodings ===================================================== .. py:module:: m2isar.transforms.encode_instructions.instr_encodings .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: m2isar.transforms.encode_instructions.instr_encodings.unused_opcodes m2isar.transforms.encode_instructions.instr_encodings.i_opcodes m2isar.transforms.encode_instructions.instr_encodings.r_opcodes m2isar.transforms.encode_instructions.instr_encodings.f2_opcodes Classes ------- .. autoapisummary:: m2isar.transforms.encode_instructions.instr_encodings.OpcodeGenerator m2isar.transforms.encode_instructions.instr_encodings.FunctNOpcodeGenerator Functions --------- .. autoapisummary:: m2isar.transforms.encode_instructions.instr_encodings._reset_enc_generators m2isar.transforms.encode_instructions.instr_encodings.get_mm_encoding m2isar.transforms.encode_instructions.instr_encodings.get_cdsl_encoding m2isar.transforms.encode_instructions.instr_encodings.reg_bitfield m2isar.transforms.encode_instructions.instr_encodings.update_imm_width Module Contents --------------- .. py:data:: unused_opcodes :value: [107, 119, 87, 11, 43, 91, 123] 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 .. py:class:: OpcodeGenerator 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 .. py:attribute:: opcode :type: Optional[int] :value: None .. py:attribute:: funct3 :type: int :value: 0 .. py:method:: get() -> Tuple[int, int] Get a new opcode as a tuple of (minor, major) opcode, Returns (funct3, opcode) .. py:class:: FunctNOpcodeGenerator(opcode_gen: OpcodeGenerator, funct_size: int) Class to generate opcodes with an additional funct field, like the standard R-Format gets a reference to a basic opcode generator .. py:attribute:: opcode_generator .. py:attribute:: opcode :type: int :value: 0 .. py:attribute:: funct3 :type: Optional[int] :value: None .. py:attribute:: n :type: int .. py:attribute:: funct_n :type: int :value: 0 .. py:method:: get() -> Tuple[int, int, int] returns (functN, funct3, opcode) .. py:data:: i_opcodes I-Format: imm | rs1 | func3 | rd | opcode 31:20 |19:15| 14:12 |11:7| 6:0 .. py:data:: r_opcodes R-Format: funct7 | rs2 | rs1 | funct3 | rd | opcode 31:25 |24:20|19:15| 14:12 |11:7| 6:0 .. py:data:: f2_opcodes 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 .. py:function:: _reset_enc_generators() This function should only be used in the unit tests! It resets the encoding generators, so tests can run independently or in succession .. py:function:: get_mm_encoding(in_operands: Dict[str, m2isar.transforms.encode_instructions.operands.Operand], 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 .. py:function:: get_cdsl_encoding(operands: Dict[str, m2isar.transforms.encode_instructions.operands.Operand]) -> str Generate an encoding for the given operands Actual encoding gets generated by "get_mm_encoding()" and just performes string formating to emmit CoreDSL .. py:function:: reg_bitfield(name: str) -> m2isar.metamodel.arch.BitField Helper funtion to reduce boilerplate code Returns a BitField Object with the specified name .. py:function:: update_imm_width(immediate: m2isar.transforms.encode_instructions.operands.Operand, width: int) -> None Adjust the width of an immediate to fit the encoding