• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
        • Program-execution
        • Introduction
        • X86isa-build-instructions
        • Publications
        • Contributors
        • Machine
          • Syscalls
          • Cpuid
          • X86isa-state
          • Linear-memory
          • Rflag-specifications
          • Characterizing-undefined-behavior
          • Top-level-memory
          • App-view
          • X86-decoder
            • Get-prefixes
            • Vex-0f3a-execute
            • Vex-0f38-execute
            • Vex-0f-execute
            • Two-byte-opcode-execute
            • Second-three-byte-opcode-execute
            • One-byte-opcode-execute
            • First-three-byte-opcode-execute
            • Evex-0f3a-execute
            • Evex-0f38-execute
            • Evex-0f-execute
            • X86-fetch-decode-execute
            • Vex-decode-and-execute
              • Evex-decode-and-execute
              • Opcode-maps
              • X86-run
              • Implemented-opcodes
              • Three-byte-opcode-decode-and-execute
              • X86-run-halt-count
              • Two-byte-opcode-decode-and-execute
              • X86-run-steps
              • X86-fetch-decode-execute-halt
              • X86-run-halt
              • X86-run-steps1
            • Physical-memory
            • Decoding-and-spec-utils
            • Instructions
            • X86-modes
            • Segmentation
            • Register-readers-and-writers
            • Other-non-deterministic-computations
            • Environment
            • Paging
          • Implemented-opcodes
          • Proof-utilities
          • To-do
          • Concrete-simulation-examples
          • Model-validation
          • Utils
          • Debugging-code-proofs
        • Execloader
        • Axe
      • Testing-utilities
      • Math
    • X86-decoder

    Vex-decode-and-execute

    Signature
    (vex-decode-and-execute proc-mode start-rip temp-rip 
                            prefixes rex-byte vex-prefixes x86) 
     
      → 
    x86
    Arguments
    temp-rip — temp-rip points to the byte following the first two VEX prefixes that were already read and placed in the vex-prefixes structure in x86-fetch-decode-execute.
    vex-prefixes — Only byte0 and byte1 fields are populated when this function is called.
    Returns
    x86 — Type (x86p x86), given (x86p x86).

    vex-decode-and-execute dispatches control to VEX-encoded instructions.

    Reference: Intel Vol. 2A, Section 2.3: Intel Advanced Vector Extensions (Intel AVX)

    Definitions and Theorems

    Function: vex-decode-and-execute

    (defun
     vex-decode-and-execute
     (proc-mode start-rip temp-rip
                prefixes rex-byte vex-prefixes x86)
     (declare (xargs :stobjs (x86)))
     (declare (type (integer 0 4) proc-mode)
              (type (signed-byte 48) start-rip)
              (type (signed-byte 48) temp-rip)
              (type (unsigned-byte 52) prefixes)
              (type (unsigned-byte 8) rex-byte)
              (type (unsigned-byte 24) vex-prefixes))
     (declare (xargs :guard (and (prefixes-p prefixes)
                                 (vex-prefixes-byte0-p vex-prefixes))))
     (let
      ((__function__ 'vex-decode-and-execute))
      (declare (ignorable __function__))
      (b*
       ((ctx 'vex-decode-and-execute)
        ((when (not (equal rex-byte 0)))
         (!!fault-fresh :ud
                        :vex-prefixes vex-prefixes
                        :rex rex-byte))
        ((when (equal (the (unsigned-byte 8)
                           (prefixes->lck prefixes))
                      240))
         (!!fault-fresh :ud :vex-prefixes
                        vex-prefixes :lock-prefix))
        ((when (equal (the (unsigned-byte 8)
                           (prefixes->rep prefixes))
                      242))
         (!!fault-fresh :ud
                        :vex-prefixes vex-prefixes :f2-prefix))
        ((when (equal (the (unsigned-byte 8)
                           (prefixes->rep prefixes))
                      243))
         (!!fault-fresh :ud
                        :vex-prefixes vex-prefixes :f3-prefix))
        ((when (equal (the (unsigned-byte 8)
                           (prefixes->opr prefixes))
                      102))
         (!!fault-fresh :ud
                        :vex-prefixes vex-prefixes :66-prefix))
        (vex2-prefix? (equal (vex-prefixes->byte0 vex-prefixes)
                             197))
        (vex3-prefix? (equal (vex-prefixes->byte0 vex-prefixes)
                             196))
        (vex-byte1 (vex-prefixes->byte1 vex-prefixes))
        ((mv vex3-0f-map?
             vex3-0f38-map? vex3-0f3a-map?)
         (if vex3-prefix?
             (mv (equal (vex3-byte1->m-mmmm vex-byte1) 1)
                 (equal (vex3-byte1->m-mmmm vex-byte1) 2)
                 (equal (vex3-byte1->m-mmmm vex-byte1)
                        3))
             (mv nil nil nil)))
        ((when (and vex3-prefix?
                    (not (or vex3-0f-map?
                             vex3-0f38-map? vex3-0f3a-map?))))
         (!!fault-fresh :ud
                        :vex-prefixes vex-prefixes
                        :m-mmmm vex-byte1))
        ((mv flg0
             (the (unsigned-byte 8) byte2/next-byte)
             x86)
         (rme08 proc-mode temp-rip 1 :x x86))
        ((when flg0)
         (!!ms-fresh :vex-byte2/next-byte-read-error flg0))
        ((mv flg1 temp-rip)
         (add-to-*ip proc-mode temp-rip 1 x86))
        ((when flg1)
         (!!ms-fresh :increment-error flg1))
        (vex-prefixes
             (if vex3-prefix?
                 (!vex-prefixes->byte2 byte2/next-byte vex-prefixes)
                 vex-prefixes))
        ((mv flg2 (the (unsigned-byte 8) next-byte)
             x86)
         (if vex3-prefix?
             (rme08 proc-mode temp-rip 1 :x x86)
             (mv nil 0 x86)))
        ((when flg2)
         (!!ms-fresh :next-byte-read-error flg2))
        ((mv flg3 temp-rip)
         (if vex3-prefix?
             (add-to-*ip proc-mode temp-rip 1 x86)
             (mv nil temp-rip)))
        ((when flg3)
         (!!ms-fresh :increment-error flg3))
        (opcode (the (unsigned-byte 8)
                     (if vex3-prefix?
                         next-byte byte2/next-byte)))
        (modr/m? (vex-opcode-modr/m-p vex-prefixes opcode))
        ((mv flg4 (the (unsigned-byte 8) modr/m)
             x86)
         (if modr/m?
             (rme08 proc-mode temp-rip 1 :x x86)
             (mv nil 0 x86)))
        ((when flg4)
         (!!ms-fresh :modr/m-byte-read-error flg4))
        ((mv flg5 temp-rip)
         (if modr/m?
             (add-to-*ip proc-mode temp-rip 1 x86)
             (mv nil temp-rip)))
        ((when flg5)
         (!!ms-fresh :increment-error flg5))
        (sib?
          (and modr/m?
               (b* ((p4? (eql 103
                              (the (unsigned-byte 8)
                                   (prefixes->adr prefixes))))
                    (16-bit-addressp
                         (eql 2
                              (select-address-size proc-mode p4? x86))))
                   (x86-decode-sib-p modr/m 16-bit-addressp))))
        ((mv flg6 (the (unsigned-byte 8) sib)
             x86)
         (if sib? (rme08 proc-mode temp-rip 1 :x x86)
             (mv nil 0 x86)))
        ((when flg6)
         (!!ms-fresh :sib-byte-read-error flg6))
        ((mv flg7 temp-rip)
         (if sib?
             (add-to-*ip proc-mode temp-rip 1 x86)
             (mv nil temp-rip)))
        ((when flg7)
         (!!ms-fresh :increment-error flg7)))
       (cond ((mbe :logic (vex-prefixes-map-p 15 vex-prefixes)
                   :exec (or vex2-prefix?
                             (and vex3-prefix? vex3-0f-map?)))
              (vex-0f-execute proc-mode
                              start-rip temp-rip prefixes rex-byte
                              vex-prefixes opcode modr/m sib x86))
             ((mbe :logic (vex-prefixes-map-p 3896 vex-prefixes)
                   :exec (and vex3-prefix? vex3-0f38-map?))
              (vex-0f38-execute proc-mode
                                start-rip temp-rip prefixes rex-byte
                                vex-prefixes opcode modr/m sib x86))
             ((mbe :logic (vex-prefixes-map-p 3898 vex-prefixes)
                   :exec (and vex3-prefix? vex3-0f3a-map?))
              (vex-0f3a-execute proc-mode
                                start-rip temp-rip prefixes rex-byte
                                vex-prefixes opcode modr/m sib x86))
             (t (!!ms-fresh :illegal-value-of-vex-m-mmmm))))))

    Theorem: x86p-of-vex-decode-and-execute

    (defthm
     x86p-of-vex-decode-and-execute
     (implies
      (x86p x86)
      (b*
       ((x86
           (vex-decode-and-execute proc-mode start-rip temp-rip
                                   prefixes rex-byte vex-prefixes x86)))
       (x86p x86)))
     :rule-classes :rewrite)