Effective address calculation with 16-bit addressing.
(x86-effective-addr-16 proc-mode temp-rip r/m mod x86) → (mv flg address increment-rip-by x86)
This is according to Intel manual, Mar'17, Vol. 2, Table 2-1.
We assume that the additions in the table are modular,
even though the documentation is not clear in that respect.
So we simply apply
Function:
(defun x86-effective-addr-16 (proc-mode temp-rip r/m mod x86) (declare (xargs :stobjs (x86))) (declare (type (integer 0 4) proc-mode) (type (signed-byte 48) temp-rip) (type (unsigned-byte 3) r/m) (type (unsigned-byte 2) mod)) (declare (xargs :guard (and (2bits-p mod) (3bits-p r/m)))) (let ((__function__ 'x86-effective-addr-16)) (declare (ignorable __function__)) (case r/m (0 (b* ((bx (rr16 3 x86)) (si (rr16 6 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ bx si disp)) increment-rip-by x86))) (1 (b* ((bx (rr16 3 x86)) (di (rr16 7 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ bx di disp)) increment-rip-by x86))) (2 (b* ((bp (rr16 5 x86)) (si (rr16 6 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ bp si disp)) increment-rip-by x86))) (3 (b* ((bp (rr16 5 x86)) (di (rr16 7 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ bp di disp)) increment-rip-by x86))) (4 (b* ((si (rr16 6 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ si disp)) increment-rip-by x86))) (5 (b* ((di (rr16 7 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ di disp)) increment-rip-by x86))) (6 (case mod (0 (b* (((mv flg disp x86) (rime-size-opt proc-mode 2 temp-rip 1 :x nil x86 :mem-ptr? nil)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 disp) 2 x86))) (otherwise (b* ((bp (rr16 5 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ bp disp)) increment-rip-by x86))))) (7 (b* ((bx (rr16 3 x86)) ((mv flg disp increment-rip-by x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) ((when flg) (mv flg 0 0 x86))) (mv nil (n16 (+ bx disp)) increment-rip-by x86))) (otherwise (mv :r/m-out-of-range 0 0 x86)))))
Theorem:
(defthm n16p-of-x86-effective-addr-16.address (b* (((mv ?flg ?address ?increment-rip-by ?x86) (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) (n16p address)) :rule-classes :rewrite)
Theorem:
(defthm natp-of-x86-effective-addr-16.increment-rip-by (b* (((mv ?flg ?address ?increment-rip-by ?x86) (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) (natp increment-rip-by)) :rule-classes :rewrite)
Theorem:
(defthm x86p-of-x86-effective-addr-16.x86 (implies (x86p x86) (b* (((mv ?flg ?address ?increment-rip-by ?x86) (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) (x86p x86))) :rule-classes :rewrite)
Theorem:
(defthm i64p-mv-nth-1-x86-effective-addr-16 (signed-byte-p 64 (mv-nth 1 (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) :rule-classes (:rewrite (:type-prescription :corollary (integerp (mv-nth 1 (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) :hints (("Goal" :in-theory '(signed-byte-p integer-range-p)))) (:linear :corollary (and (<= -9223372036854775808 (mv-nth 1 (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) (< (mv-nth 1 (x86-effective-addr-16 proc-mode temp-rip r/m mod x86)) 9223372036854775808)) :hints (("Goal" :in-theory '(signed-byte-p integer-range-p (:e expt)))))))
Theorem:
(defthm natp-mv-nth-2-x86-effective-addr-16 (natp (mv-nth 2 (x86-effective-addr-16 proc-mode temp-rip r/m mod x86))) :rule-classes :type-prescription)
Theorem:
(defthm mv-nth-2-x86-effective-addr-16-<=-4 (<= (mv-nth 2 (x86-effective-addr-16 proc-mode temp-rip r/m mod x86)) 4) :rule-classes :linear)