• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Riscv
          • Specification
            • Semantics
            • Features
            • Instructions
            • Encoding
              • Encode
              • Encoding-decoding-illustration
              • Encoding-validp
              • Encode-load-funct
              • Encode-store-funct
              • Encode-op-imms-32-funct
              • Encode-op-funct
              • Encode-op-32-funct
              • Encode-op-imms64-funct
              • Encode-op-imms32-funct
              • Encode-op-imm-funct
              • Encode-op-imm-32-funct
              • Encode-branch-funct
            • States
            • Reads-over-writes
            • Semantics-equivalences
            • Decoding
            • Execution
          • Executable
          • Specialized
          • Optimized
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
        • Number-theory
        • Lists-light
        • Axe
        • Builtins
        • Solidity
        • Helpers
        • Htclient
        • Typed-lists-light
        • Arithmetic-light
      • X86isa
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Specification

Encoding

Encoding of instructions.

Instructions are encoded as specified in [ISA] and [ISAP]. Here we define encoding as a mapping from the instruction fixtypes to their encodings.

Without the C extension [ISA:27], instructions are encoded in 32 bits per instruction. So we define our mapping from instructions to 32-bit unsigned integers. We plan to model the C extension in the future: we will define a second encoding mapping, which maps certain instructions to 16 bits per instruction; the features will be also extended with an indication of whether the C extension is present.

Even without modeling the C extension yet, our encoding mapping depends on the features, because it is only defined on instructions that are valid according to the features.

We also provide a characterization of the valid encodings as the image of the encoding function.

See encoding-decoding-illustration for an illustration of encoding and decoding.

Subtopics

Encode
Encode an instruction in the normal way (i.e. in 32 bits).
Encoding-decoding-illustration
Illustration of instruction encoding and decoding.
Encoding-validp
Check if a 32-bit word is a valid instruction encoding.
Encode-load-funct
Encode the name of an instruction with the LOAD opcode into the func3 field [ISA:2.6] [ISA:4.3] [ISA:35].
Encode-store-funct
Encode the name of an instruction with the STORE opcode into the funct3 field [ISA:2.6] [ISA:4.3] [ISA:35].
Encode-op-imms-32-funct
Encode the name of a shift instruction with the OP-IMM opcode into the funct3 field and the high 6 immediate bits [ISA:4.2.1] [ISA:35].
Encode-op-funct
Encode the name of an instruction with the OP opcode into the funct3 and funct7 fields [ISA:2.4.2] [ISA:12.1] [ISA:12.2] [ISA:35].
Encode-op-32-funct
Encode the name of an instruction with the OP-32 opcode into the funct3 and funct7 fields [ISA:4.2.2] [ISA:12.1] [ISA:12.2] [ISA:35].
Encode-op-imms64-funct
Encode the name of a 64-bit shift instruction with the OP-IMM opcode into the funct3 field and the high 6 immediate bits [ISA:4.2.1] [ISA:35].
Encode-op-imms32-funct
Encode the name of a 32-bit shift instruction with the OP-IMM opcode into the funct3 field and the high 7 immediate bits [ISA:2.4.1] [ISA:35].
Encode-op-imm-funct
Encode the name of a non-shift instruction with the OP-IMM opcode into the funct3 field [ISA:2.4.1] [ISA:35].
Encode-op-imm-32-funct
Encode the name of a non-shift instruction with the OP-IMM-32 opcode into the funct3 field [ISA:4.2.1] [ISA:35].
Encode-branch-funct
Encode the name of an instruction with the BRANCH opcode into the funct3 field [ISA:2.5.2] [ISA:35].