• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Leftist-trees
      • Java
      • Taspi
      • Bitcoin
      • Riscv
        • Instructions
        • States
        • Decoding
        • Encoding
        • Features
        • Semantics
          • Semantics64
          • Semantics32
            • Exec32-bgeu
            • Exec32-bltu
            • Exec32-blt
            • Exec32-bge
            • Exec32-bne
            • Exec32-beq
            • Exec32-jalr
              • Exec32-branch
              • Exec32-jal
              • Exec32-op
              • Exec32-store
              • Exec32-op-imm
              • Exec32-load
              • Exec32-sra
              • Exec32-sltiu
              • Exec32-op-imms
              • Exec32-srl
              • Exec32-slti
              • Exec32-remu
              • Exec32-rem
              • Exec32-auipc
              • Exec32-xori
              • Exec32-srli
              • Exec32-srai
              • Exec32-ori
              • Exec32-divu
              • Exec32-andi
              • Exec32-addi
              • Exec32-sltu
              • Exec32-slt
              • Exec32-sll
              • Exec32-mulhsu
              • Exec32-lhu
              • Exec32-div
              • Exec32-xor
              • Exec32-slli
              • Exec32-sh
              • Exec32-mulhu
              • Exec32-mulh
              • Exec32-lh
              • Exec32-lbu
              • Exec32-sw
              • Exec32-sub
              • Exec32-sb
              • Exec32-or
              • Exec32-lw
              • Exec32-lb
              • Exec32-and
              • Exec32-mul
              • Exec32-add
              • Exec32-instr
              • Eff32-addr
              • Exec32-lui
          • Execution
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Semantics32

    Exec32-jalr

    Semantics of the JALR instruction [ISA:2.5.1].

    Signature
    (exec32-jalr rd rs1 imm pc stat) → new-stat
    Arguments
    rd — Guard (ubyte5p rd).
    rs1 — Guard (ubyte5p rs1).
    imm — Guard (ubyte12p imm).
    pc — Guard (ubyte32p pc).
    stat — Guard (state32p stat).
    Returns
    new-stat — Type (state32p new-stat).

    We read an unsigned 32-bit integer from rs1. We sign-extend the 12-bit immediate to 32 bits, obtaining an unsigned 32-bit offset. We add the offset to the integer from the register, and set the least significant bit to 0; this is the jump target. We write the address of the instruction just after this to rd; since instructions are 32-bit long, the address of the next instruction is obtained by adding 4 to pc, which is the address of this instruction, passed as input to this function. We write the jump target to the program counter.

    Definitions and Theorems

    Function: exec32-jalr

    (defun exec32-jalr (rd rs1 imm pc stat)
      (declare (xargs :guard (and (ubyte5p rd)
                                  (ubyte5p rs1)
                                  (ubyte12p imm)
                                  (ubyte32p pc)
                                  (state32p stat))))
      (let ((__function__ 'exec32-jalr))
        (declare (ignorable __function__))
        (b* ((base (read32-xreg-unsigned rs1 stat))
             (offset (loghead 32 (logext 12 (ubyte12-fix imm))))
             (target-pc (logand 4294967294 (+ base offset)))
             (next-pc (+ (ubyte32-fix pc) 4))
             (stat (write32-xreg rd next-pc stat))
             (stat (write32-pc target-pc stat)))
          stat)))

    Theorem: state32p-of-exec32-jalr

    (defthm state32p-of-exec32-jalr
      (b* ((new-stat (exec32-jalr rd rs1 imm pc stat)))
        (state32p new-stat))
      :rule-classes :rewrite)

    Theorem: exec32-jalr-of-ubyte5-fix-rd

    (defthm exec32-jalr-of-ubyte5-fix-rd
      (equal (exec32-jalr (ubyte5-fix rd)
                          rs1 imm pc stat)
             (exec32-jalr rd rs1 imm pc stat)))

    Theorem: exec32-jalr-ubyte5-equiv-congruence-on-rd

    (defthm exec32-jalr-ubyte5-equiv-congruence-on-rd
      (implies (ubyte5-equiv rd rd-equiv)
               (equal (exec32-jalr rd rs1 imm pc stat)
                      (exec32-jalr rd-equiv rs1 imm pc stat)))
      :rule-classes :congruence)

    Theorem: exec32-jalr-of-ubyte5-fix-rs1

    (defthm exec32-jalr-of-ubyte5-fix-rs1
      (equal (exec32-jalr rd (ubyte5-fix rs1)
                          imm pc stat)
             (exec32-jalr rd rs1 imm pc stat)))

    Theorem: exec32-jalr-ubyte5-equiv-congruence-on-rs1

    (defthm exec32-jalr-ubyte5-equiv-congruence-on-rs1
      (implies (ubyte5-equiv rs1 rs1-equiv)
               (equal (exec32-jalr rd rs1 imm pc stat)
                      (exec32-jalr rd rs1-equiv imm pc stat)))
      :rule-classes :congruence)

    Theorem: exec32-jalr-of-ubyte12-fix-imm

    (defthm exec32-jalr-of-ubyte12-fix-imm
      (equal (exec32-jalr rd rs1 (ubyte12-fix imm)
                          pc stat)
             (exec32-jalr rd rs1 imm pc stat)))

    Theorem: exec32-jalr-ubyte12-equiv-congruence-on-imm

    (defthm exec32-jalr-ubyte12-equiv-congruence-on-imm
      (implies (acl2::ubyte12-equiv imm imm-equiv)
               (equal (exec32-jalr rd rs1 imm pc stat)
                      (exec32-jalr rd rs1 imm-equiv pc stat)))
      :rule-classes :congruence)

    Theorem: exec32-jalr-of-ubyte32-fix-pc

    (defthm exec32-jalr-of-ubyte32-fix-pc
      (equal (exec32-jalr rd rs1 imm (ubyte32-fix pc)
                          stat)
             (exec32-jalr rd rs1 imm pc stat)))

    Theorem: exec32-jalr-ubyte32-equiv-congruence-on-pc

    (defthm exec32-jalr-ubyte32-equiv-congruence-on-pc
      (implies (acl2::ubyte32-equiv pc pc-equiv)
               (equal (exec32-jalr rd rs1 imm pc stat)
                      (exec32-jalr rd rs1 imm pc-equiv stat)))
      :rule-classes :congruence)

    Theorem: exec32-jalr-of-state32-fix-stat

    (defthm exec32-jalr-of-state32-fix-stat
      (equal (exec32-jalr rd rs1 imm pc (state32-fix stat))
             (exec32-jalr rd rs1 imm pc stat)))

    Theorem: exec32-jalr-state32-equiv-congruence-on-stat

    (defthm exec32-jalr-state32-equiv-congruence-on-stat
      (implies (state32-equiv stat stat-equiv)
               (equal (exec32-jalr rd rs1 imm pc stat)
                      (exec32-jalr rd rs1 imm pc stat-equiv)))
      :rule-classes :congruence)