• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Riscv
          • Specification
            • Semantics
            • Features
            • Instructions
            • Encoding
            • States
              • Stat
              • Stat-validp
              • Read-instruction
              • Write-memory-unsigned64
              • Write-memory-unsigned32
              • Write-memory-unsigned8
              • Write-memory-unsigned16
                • Write-xreg-32
                • Read-xreg-unsigned
                • Write-xreg
                • Read-memory-unsigned64
                • Read-memory-unsigned8
                • Read-memory-unsigned32
                • Read-xreg-signed
                • Read-memory-unsigned16
                • Read-xreg-unsigned32
                • Write-pc
                • Read-xreg-signed32
                • Inc4-pc
                • Read-pc
                • Errorp
                • Error
              • Reads-over-writes
              • Semantics-equivalences
              • Decoding
              • Execution
            • Executable
            • Specialized
            • Optimized
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • States

    Write-memory-unsigned16

    Write an unsigned 16-bit integer to memory.

    Signature
    (write-memory-unsigned16 addr val stat feat) → new-stat
    Arguments
    addr — Guard (integerp addr).
    val — Guard (ubyte16p val).
    stat — Guard (statp stat).
    feat — Guard (featp feat).
    Returns
    new-stat — Type (statp new-stat).

    The memory address is the one of the first byte; we write that, and the subsequent byte. We write the bytes according to endianness.

    As in write-memory-unsigned8, we let the address be any integer. We use write-memory-unsigned8 twice. Note that if addr is 2^XLEN - 1, then addr + 1 wraps around to address 0.

    Definitions and Theorems

    Function: write-memory-unsigned16

    (defun write-memory-unsigned16 (addr val stat feat)
      (declare (xargs :guard (and (integerp addr)
                                  (ubyte16p val)
                                  (statp stat)
                                  (featp feat))))
      (declare (xargs :guard (stat-validp stat feat)))
      (let ((__function__ 'write-memory-unsigned16))
        (declare (ignorable __function__))
        (b* ((val (ubyte16-fix val))
             (b0 (part-select val :low 0 :width 8))
             (b1 (part-select val :low 8 :width 8))
             ((mv 1st-byte 2nd-byte)
              (if (feat-little-endianp feat)
                  (mv b0 b1)
                (mv b1 b0)))
             (stat (write-memory-unsigned8 addr 1st-byte stat feat))
             (stat (write-memory-unsigned8 (+ (lifix addr) 1)
                                           2nd-byte stat feat)))
          stat)))

    Theorem: statp-of-write-memory-unsigned16

    (defthm statp-of-write-memory-unsigned16
      (b* ((new-stat (write-memory-unsigned16 addr val stat feat)))
        (statp new-stat))
      :rule-classes :rewrite)

    Theorem: stat-validp-of-write-memory-unsigned16

    (defthm stat-validp-of-write-memory-unsigned16
     (implies
          (stat-validp stat feat)
          (b* ((?new-stat (write-memory-unsigned16 addr val stat feat)))
            (stat-validp new-stat feat))))

    Theorem: write-memory-unsigned16-of-ifix-addr

    (defthm write-memory-unsigned16-of-ifix-addr
      (equal (write-memory-unsigned16 (ifix addr)
                                      val stat feat)
             (write-memory-unsigned16 addr val stat feat)))

    Theorem: write-memory-unsigned16-int-equiv-congruence-on-addr

    (defthm write-memory-unsigned16-int-equiv-congruence-on-addr
      (implies
           (acl2::int-equiv addr addr-equiv)
           (equal (write-memory-unsigned16 addr val stat feat)
                  (write-memory-unsigned16 addr-equiv val stat feat)))
      :rule-classes :congruence)

    Theorem: write-memory-unsigned16-of-ubyte16-fix-val

    (defthm write-memory-unsigned16-of-ubyte16-fix-val
      (equal (write-memory-unsigned16 addr (ubyte16-fix val)
                                      stat feat)
             (write-memory-unsigned16 addr val stat feat)))

    Theorem: write-memory-unsigned16-ubyte16-equiv-congruence-on-val

    (defthm write-memory-unsigned16-ubyte16-equiv-congruence-on-val
      (implies
           (acl2::ubyte16-equiv val val-equiv)
           (equal (write-memory-unsigned16 addr val stat feat)
                  (write-memory-unsigned16 addr val-equiv stat feat)))
      :rule-classes :congruence)

    Theorem: write-memory-unsigned16-of-stat-fix-stat

    (defthm write-memory-unsigned16-of-stat-fix-stat
      (equal (write-memory-unsigned16 addr val (stat-fix stat)
                                      feat)
             (write-memory-unsigned16 addr val stat feat)))

    Theorem: write-memory-unsigned16-stat-equiv-congruence-on-stat

    (defthm write-memory-unsigned16-stat-equiv-congruence-on-stat
      (implies
           (stat-equiv stat stat-equiv)
           (equal (write-memory-unsigned16 addr val stat feat)
                  (write-memory-unsigned16 addr val stat-equiv feat)))
      :rule-classes :congruence)

    Theorem: write-memory-unsigned16-of-feat-fix-feat

    (defthm write-memory-unsigned16-of-feat-fix-feat
      (equal (write-memory-unsigned16 addr val stat (feat-fix feat))
             (write-memory-unsigned16 addr val stat feat)))

    Theorem: write-memory-unsigned16-feat-equiv-congruence-on-feat

    (defthm write-memory-unsigned16-feat-equiv-congruence-on-feat
      (implies
           (feat-equiv feat feat-equiv)
           (equal (write-memory-unsigned16 addr val stat feat)
                  (write-memory-unsigned16 addr val stat feat-equiv)))
      :rule-classes :congruence)