Using the REX prefix to access general-purpose registers
(reg-index reg rex-byte index) → *
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
In 32-bit mode, the REX prefix is absent. This function can be used in 32-bit mode, by passing 0 as REX.
Function:
(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:
(defthm reg-indexp-reg-index (reg-indexp (reg-index reg rex-byte name) rex-byte))
Theorem:
(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:
(defthm reg-indexp-forward (implies (reg-indexp reg rex-byte) (unsigned-byte-p 4 reg)) :rule-classes :forward-chaining)