• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • 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
            • Rme32
            • Rime32
            • Gen-read-function
            • Rme256
            • Rme128
            • Rime64
            • Rime16
            • Rme80
            • Rme64
            • Rme48
            • Rme16
            • Gen-write-function
            • Rme-size
            • Rme08
            • Rime08
            • Rime-size
            • Wme-size
            • Wime-size
            • Wme32
            • Wime32
            • Wme80
            • Wme64
            • Wme48
            • Wme256
            • Wme16
            • Wme128
            • Wime64
            • Wime16
            • Address-aligned-p
              • Wme08
              • Wime08
            • App-view
            • X86-decoder
            • Physical-memory
            • Decoding-and-spec-utils
            • Instructions
            • Register-readers-and-writers
            • 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
    • Top-level-memory

    Address-aligned-p

    Check the alignment of a linear address.

    Signature
    (address-aligned-p addr operand-size memory-ptr?) → yes/no
    Arguments
    memory-ptr? — Guard (booleanp memory-ptr?).
    Returns
    yes/no — Type (booleanp yes/no).

    Besides the address to check for alignment, this function takes as argument the operand size (from which the alignment to check is determined) and a flag indicating whether the address to check for alignment contains a memory operand of the form m16:16, m16:32, or m16:64 (see Intel manual, Mar'17, Volume 2, Section 3.1.1.3).

    Words, doublewords, quadwords, and double quadwords must be aligned at boundaries of 2, 4, 8, or 16 bytes. Memory pointers of the form m16:xx must be aligned so that their xx portion is aligned as a word, doubleword, or quadword; this automatically guarantees that their m16 portion is aligned as a word. See Intel manual, Mar'17, Volume 1, Section 4.1.1. See AMD manual, Dec'17, Volume 2, Table 8-7 (note that the table does not mention explicitly memory pointers of the form m16:64).

    If the operand size is 6, the operand must be an m16:32 pointer. If the operand size is 10, the operand must an m16:64 pointer. If the operand size is 4, it may be either an m16:16 pointer or not; in this case, the memory-ptr? argument is used to determine whether the address should be aligned at a word or doubleword boundary. If the operand size is 1, 2, 8, or 16, it cannot be a memory pointer of the form m16:xx.

    Definitions and Theorems

    Function: address-aligned-p$inline

    (defun address-aligned-p$inline (addr operand-size memory-ptr?)
      (declare (type (signed-byte 48) addr)
               (type (member 1 2 4 6 8 10 16 32 64)
                     operand-size))
      (declare (xargs :guard (booleanp memory-ptr?)))
      (b* ((addr (the (signed-byte 48) addr))
           (operand-size (the (integer 0 65) operand-size)))
        (case operand-size
          (1 t)
          (6 (equal (logand addr 3) 0))
          (10 (equal (logand addr 7) 0))
          (otherwise
               (if (and memory-ptr? (eql operand-size 4))
                   (equal (logand addr 1) 0)
                 (equal (logand addr
                                (the (integer 0 65) (- operand-size 1)))
                        0))))))

    Theorem: booleanp-of-address-aligned-p

    (defthm booleanp-of-address-aligned-p
      (b*
        ((yes/no
              (address-aligned-p$inline addr operand-size memory-ptr?)))
        (booleanp yes/no))
      :rule-classes :type-prescription)

    Theorem: memory-byte-accesses-are-always-aligned

    (defthm memory-byte-accesses-are-always-aligned
      (equal (address-aligned-p addr 1 mem-ptr?)
             t))

    Theorem: address-aligned-p-mem-ptr-input-irrelevant-for-all-but-bytes=4

    (defthm
         address-aligned-p-mem-ptr-input-irrelevant-for-all-but-bytes=4
      (implies (and (syntaxp (not (equal mem-ptr? ''nil)))
                    (not (equal nbytes 4)))
               (equal (address-aligned-p addr nbytes mem-ptr?)
                      (address-aligned-p addr nbytes nil))))