Calculate a REX byte from a VEX prefix.
(rex-byte-from-vex-prefixes vex-prefixes) → rex-byte
The VEX prefix (see Intel manual Volume 2 Section 2.3.5 of Dec 2023) provides an encoding of the REX byte. Since some of the functions in our model depend on the REX byte (e.g. x86-operand-from-modr/m-and-sib-bytes), here we introduce a function to build a REX byte from its encoding in the VEX prefix. We do that for both the 2-byte form and the 3-byte form of the VEX prefix; see vex->r, vex->x, vex->b, and vex->w. See Figure 2-9 in Intel manual Volume 2 of Dec 2023. Note that the R, X, B bits are encoded negated, while the W is encoded directly (not negated).
Function:
(defun rex-byte-from-vex-prefixes (vex-prefixes) (declare (xargs :guard (vex-prefixes-p vex-prefixes))) (declare (xargs :guard (vex-prefixes-byte0-p vex-prefixes))) (let ((__function__ 'rex-byte-from-vex-prefixes)) (declare (ignorable __function__)) (b* ((vex.w (vex->w vex-prefixes)) (vex.r (vex->r vex-prefixes)) (vex.x (vex->x vex-prefixes)) (vex.b (vex->b vex-prefixes)) (rex-byte (+ 64 (if (= vex.w 0) 0 8) (if (= vex.r 1) 0 4) (if (= vex.x 1) 0 2) (if (= vex.b 1) 0 1)))) rex-byte)))
Theorem:
(defthm return-type-of-rex-byte-from-vex-prefixes (b* ((rex-byte (rex-byte-from-vex-prefixes vex-prefixes))) (unsigned-byte-p 8 rex-byte)) :rule-classes :rewrite)
Theorem:
(defthm unsigned-byte-p-of-rex-byte-from-vex-prefixes (unsigned-byte-p 8 (rex-byte-from-vex-prefixes vex-prefixes)) :rule-classes (:rewrite (:type-prescription :corollary (natp (rex-byte-from-vex-prefixes vex-prefixes)) :hints (("Goal" :in-theory '(unsigned-byte-p integer-range-p natp)))) (:linear :corollary (and (<= 0 (rex-byte-from-vex-prefixes vex-prefixes)) (< (rex-byte-from-vex-prefixes vex-prefixes) 256)) :hints (("Goal" :in-theory '(unsigned-byte-p integer-range-p (:e expt)))))))