Download Refinement and Theorem Proving*

Transcript
predictor. If the invalidate signal does not hold, then we increment the program
counter unless we are fetching a branch instruction.
(defun step-pc (MA)
(let* ((pc
(g :pc MA))
(inst
(g (g :pc MA) (g :imem MA)))
(op
(g :opcode inst))
(regs
(g :regs MA))
(latch1
(g :latch1 MA))
(l1op
(g :op latch1))
(latch2
(g :latch2 MA))
(l2op
(g :op latch2))
(l2validp (g :validp latch2))
(l2ra-val (g :ra-val latch2))
(l2rb-val (g :rb-val latch2)))
(cond ((stall-l1p MA)
pc)
((invalidate-l1p MA)
(cond ((and l2validp
(equal l2op ’bez))
(if (equal 0 l2ra-val)
(ifix (ALU-output ’add pc l2rb-val))
(1+ pc)))
((equal l1op ’jump)
(ifix (g (g :ra latch1) regs)))
(t pc)))
;;; must be bez instruction
((in op ’(jump bez))
pc)
(t (1+ pc)))))
This ends the description of the ISA and MA machines. To summarize, we
can use ACL2 to define machines models at any level of abstraction we like.
What we wind up with are simulators for the machines, which we can execute.
For example, consider the following program to multiply x and y (without using
the mul instruction). The data memory contains the constants 0, 1, 4, and 6 in
memory locations 0, 1, 4, and 6, respectively. It also contains x and y in memory
locations 2 and 3.
(defun mul-dmem (x y)
(seq nil 0 0 1 1 2 x 3 y 4 4 6 6))
The instruction memory contains the following code.
(defun inst (op rc ra rb)
(seq nil :opcode op :rc rc :ra ra :rb rb))
(defun mul-imem ()
(seq nil