• 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
              • Exec-bltu
              • Exec-bgeu
              • Exec-bge
              • Exec-blt
              • Exec-bne
              • Exec-beq
              • Exec-jalr
              • Exec-jal
              • Exec-sra
              • Exec-op
              • Exec-srl
                • Exec-op-imms-32
                • Exec-op-32
                • Exec-sll
                • Exec-branch
                • Exec-srlw
                • Exec-sraw
                • Exec-remuw
                • Exec-op-imms64
                • Exec-op-imms32
                • Exec-op-imm-32
                • Exec-srliw
                • Exec-sraiw
                • Exec-sltiu
                • Exec-remw
                • Exec-op-imm
                • Exec-load
                • Exec-divuw
                • Exec-store
                • Exec-srli64
                • Exec-srli32
                • Exec-srai64
                • Exec-srai32
                • Exec-sllw
                • Exec-remu
                • Exec-divw
                • Exec-addiw
                • Exec-xori
                • Exec-slti
                • Exec-slliw
                • Exec-rem
                • Exec-ori
                • Exec-mulhsu
                • Exec-divu
                • Exec-auipc
                • Exec-andi
                • Exec-sw
                • Exec-sltu
                • Exec-slt
                • Exec-slli64
                • Exec-slli32
                • Exec-mulhu
                • Exec-div
                • Exec-addw
                • Exec-addi
                • Exec-xor
                • Exec-mulw
                • Exec-mulh
                • Exec-lwu
                • Exec-and
                • Exec-subw
                • Exec-sub
                • Exec-or
                • Exec-lhu
                • Exec-lbu
                • Exec-sd
                • Exec-mul
                • Exec-lh
                • Exec-ld
                • Exec-lb
                • Exec-add
                • Exec-sh
                • Exec-sb
                • Exec-lw
                • Exec-lui
                • Eff-addr
                • Exec-instr
              • Features
              • Instructions
              • Encoding
              • States
              • 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
    • Semantics

    Exec-srl

    Semantics of the SRL instruction [ISA:4.2.2].

    Signature
    (exec-srl rd rs1 rs2 stat feat) → new-stat
    Arguments
    rd — Guard (ubyte5p rd).
    rs1 — Guard (ubyte5p rs1).
    rs2 — Guard (ubyte5p rs2).
    stat — Guard (statp stat).
    feat — Guard (featp feat).
    Returns
    new-stat — Type (statp new-stat).

    We read two unsigned XLEN-bit integers from rs1 and rs2. In 32-bit mode, the low 5 bits of the second integer are the shift amount, from 0 to 31; in 64-bit mode, the low 6 bits of the second integer are the shift amount, from 0 to 63. We shift the first integer right by the shift amount; this is a logical shift, since the integer is unsigned. We write the result to rd. We increment the program counter.

    Definitions and Theorems

    Function: exec-srl

    (defun exec-srl (rd rs1 rs2 stat feat)
      (declare (xargs :guard (and (ubyte5p rd)
                                  (ubyte5p rs1)
                                  (ubyte5p rs2)
                                  (statp stat)
                                  (featp feat))))
      (declare (xargs :guard (and (stat-validp stat feat)
                                  (< (lnfix rd) (feat->xnum feat))
                                  (< (lnfix rs1) (feat->xnum feat))
                                  (< (lnfix rs2) (feat->xnum feat)))))
      (let ((__function__ 'exec-srl))
        (declare (ignorable __function__))
        (b* ((rs1-operand (read-xreg-unsigned (ubyte5-fix rs1)
                                              stat feat))
             (rs2-operand (read-xreg-unsigned (ubyte5-fix rs2)
                                              stat feat))
             (shift-amount (cond ((feat-32p feat)
                                  (loghead 5 rs2-operand))
                                 ((feat-64p feat)
                                  (loghead 6 rs2-operand))
                                 (t (impossible))))
             (result (ash rs1-operand (- shift-amount)))
             (stat (write-xreg (ubyte5-fix rd)
                               result stat feat))
             (stat (inc4-pc stat feat)))
          stat)))

    Theorem: statp-of-exec-srl

    (defthm statp-of-exec-srl
      (b* ((new-stat (exec-srl rd rs1 rs2 stat feat)))
        (statp new-stat))
      :rule-classes :rewrite)

    Theorem: stat-validp-of-exec-srl

    (defthm stat-validp-of-exec-srl
      (implies (and (stat-validp stat feat)
                    (< (lnfix rd) (feat->xnum feat)))
               (b* ((?new-stat (exec-srl rd rs1 rs2 stat feat)))
                 (stat-validp new-stat feat))))

    Theorem: exec-srl-of-ubyte5-fix-rd

    (defthm exec-srl-of-ubyte5-fix-rd
      (equal (exec-srl (ubyte5-fix rd)
                       rs1 rs2 stat feat)
             (exec-srl rd rs1 rs2 stat feat)))

    Theorem: exec-srl-ubyte5-equiv-congruence-on-rd

    (defthm exec-srl-ubyte5-equiv-congruence-on-rd
      (implies (ubyte5-equiv rd rd-equiv)
               (equal (exec-srl rd rs1 rs2 stat feat)
                      (exec-srl rd-equiv rs1 rs2 stat feat)))
      :rule-classes :congruence)

    Theorem: exec-srl-of-ubyte5-fix-rs1

    (defthm exec-srl-of-ubyte5-fix-rs1
      (equal (exec-srl rd (ubyte5-fix rs1)
                       rs2 stat feat)
             (exec-srl rd rs1 rs2 stat feat)))

    Theorem: exec-srl-ubyte5-equiv-congruence-on-rs1

    (defthm exec-srl-ubyte5-equiv-congruence-on-rs1
      (implies (ubyte5-equiv rs1 rs1-equiv)
               (equal (exec-srl rd rs1 rs2 stat feat)
                      (exec-srl rd rs1-equiv rs2 stat feat)))
      :rule-classes :congruence)

    Theorem: exec-srl-of-ubyte5-fix-rs2

    (defthm exec-srl-of-ubyte5-fix-rs2
      (equal (exec-srl rd rs1 (ubyte5-fix rs2)
                       stat feat)
             (exec-srl rd rs1 rs2 stat feat)))

    Theorem: exec-srl-ubyte5-equiv-congruence-on-rs2

    (defthm exec-srl-ubyte5-equiv-congruence-on-rs2
      (implies (ubyte5-equiv rs2 rs2-equiv)
               (equal (exec-srl rd rs1 rs2 stat feat)
                      (exec-srl rd rs1 rs2-equiv stat feat)))
      :rule-classes :congruence)

    Theorem: exec-srl-of-stat-fix-stat

    (defthm exec-srl-of-stat-fix-stat
      (equal (exec-srl rd rs1 rs2 (stat-fix stat)
                       feat)
             (exec-srl rd rs1 rs2 stat feat)))

    Theorem: exec-srl-stat-equiv-congruence-on-stat

    (defthm exec-srl-stat-equiv-congruence-on-stat
      (implies (stat-equiv stat stat-equiv)
               (equal (exec-srl rd rs1 rs2 stat feat)
                      (exec-srl rd rs1 rs2 stat-equiv feat)))
      :rule-classes :congruence)

    Theorem: exec-srl-of-feat-fix-feat

    (defthm exec-srl-of-feat-fix-feat
      (equal (exec-srl rd rs1 rs2 stat (feat-fix feat))
             (exec-srl rd rs1 rs2 stat feat)))

    Theorem: exec-srl-feat-equiv-congruence-on-feat

    (defthm exec-srl-feat-equiv-congruence-on-feat
      (implies (feat-equiv feat feat-equiv)
               (equal (exec-srl rd rs1 rs2 stat feat)
                      (exec-srl rd rs1 rs2 stat feat-equiv)))
      :rule-classes :congruence)