• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
        • Program-execution
        • Sdm-instruction-set-summary
        • Tlb
        • Running-linux
        • Introduction
        • Asmtest
        • X86isa-build-instructions
        • Publications
        • Contributors
        • Machine
          • X86isa-state
          • Syscalls
          • Cpuid
          • Linear-memory
          • Rflag-specifications
          • Characterizing-undefined-behavior
          • Top-level-memory
          • App-view
          • X86-decoder
          • Physical-memory
          • Decoding-and-spec-utils
          • Instructions
          • Register-readers-and-writers
            • Zmms-reads-and-writes
            • Gprs-reads-and-writes
            • Mmx-registers-reads-and-writes
            • Xmms-reads-and-writes
            • Rflags-reads-and-writes
            • Gpr-indices
              • Reg-index
                • Reg-indexp
              • Vex-vvvv-reg-index
              • Msr-reads-and-writes
              • Ctr-reads-and-writes
            • X86-modes
            • Segmentation
            • Other-non-deterministic-computations
            • Environment
            • Paging
          • Implemented-opcodes
          • To-do
          • Proof-utilities
          • Peripherals
          • Model-validation
          • Modelcalls
          • Concrete-simulation-examples
          • Utils
          • Debugging-code-proofs
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Gpr-indices

    Reg-index

    Using the REX prefix to access general-purpose registers

    Signature
    (reg-index reg rex-byte index) → *
    Arguments
    reg — Register index.
    rex-byte — REX prefix.
    index — One of the W, R, X, or B bits of the REX prefix.

    In 64-bit mode, in addition to generating 64-bit operand sizes, the REX prefix is used to reference registers R8 to R15. Instructions that include REX prefixes can access these registers if the relevant W, R, X, or B bit in the REX prefix is set. E.g., let R be the relevant bit in the REX prefix and let R be set --- so index = 2 for this function. If reg = 0 (which, in the non-REX world, would refer to rAX), reg-index would give us the register index corresponding to the register r8. If R is not set, reg-index will give us the index corresponding to rAX.

    In 32-bit mode, the REX prefix is absent. This function can be used in 32-bit mode, by passing 0 as REX.

    Definitions and Theorems

    Function: reg-index$inline

    (defun reg-index$inline (reg rex-byte index)
      (declare (type (unsigned-byte 3) reg)
               (type (unsigned-byte 8) rex-byte)
               (type (unsigned-byte 2) index))
      (if (logbitp index rex-byte)
          (logior 8 (mbe :logic (n03 reg) :exec reg))
        (mbe :logic (n03 reg) :exec reg)))

    Theorem: reg-indexp-reg-index

    (defthm reg-indexp-reg-index
      (reg-indexp (reg-index reg rex-byte name)
                  rex-byte))

    Theorem: n04p-reg-index

    (defthm n04p-reg-index
     (unsigned-byte-p 4 (reg-index reg rex-byte name))
     :rule-classes
     (:rewrite
      (:type-prescription
          :corollary (natp (reg-index reg rex-byte name))
          :hints
          (("Goal" :in-theory '(unsigned-byte-p integer-range-p natp))))
      (:linear
       :corollary (and (<= 0 (reg-index reg rex-byte name))
                       (< (reg-index reg rex-byte name) 16))
       :hints
       (("Goal"
            :in-theory '(unsigned-byte-p integer-range-p (:e expt)))))))

    Theorem: reg-indexp-forward

    (defthm reg-indexp-forward
      (implies (reg-indexp reg rex-byte)
               (unsigned-byte-p 4 reg))
      :rule-classes :forward-chaining)