summaryrefslogtreecommitdiff
path: root/books/workshops/2000/manolios/pipeline/pipeline/deterministic-systems/ma/ma-isa.lisp
blob: d5d551b9bf68adf308062a66efc2ae9f1bac5977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
;  Copyright (C) 2000 Panagiotis Manolios

;  This program is free software; you can redistribute it and/or modify
;  it under the terms of the GNU General Public License as published by
;  the Free Software Foundation; either version 2 of the License, or
;  (at your option) any later version.

;  This program is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;  GNU General Public License for more details.

;  You should have received a copy of the GNU General Public License
;  along with this program; if not, write to the Free Software
;  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;  Written by Panagiotis Manolios who can be reached as follows.

;  Email: pete@cs.utexas.edu

;  Postal Mail:
;  Department of Computer Science
;  The University of Texas at Austin
;  Austin, TX 78701 USA

(in-package "ACL2")

(include-book "../../top/nth-thms")
(include-book "../../top/meta")
(include-book "../top/det-encap-wfbisim")
(include-book "isa")
(include-book "ma")

(defun b-to-num (x)
  (if x 1 0))

(defun shift-pc (latch1 latch2)
  (+ (b-to-num (nth (latch1-validp) latch1))
     (b-to-num (nth (latch2-validp) latch2))))

(defun committed-MA (MA)
  (let ((pc (nth (MA-pc) MA))
	(regs (nth (MA-regs) MA))
	(mem (nth (MA-mem) MA))
	(latch1 (nth (MA-latch1) MA))
	(latch2 (nth (MA-latch2) MA)))
    (MA-state
     (- pc (shift-pc latch1 latch2))
     regs
     mem
     (update-nth (latch1-validp) nil latch1)
     (update-nth (latch2-validp) nil latch2))))

(defun MA-= (x y)
  (let ((x-latch1 (nth (MA-latch1) x))
	(x-latch2 (nth (MA-latch2) x))
	(y-latch1 (nth (MA-latch1) y))
	(y-latch2 (nth (MA-latch2) y)))
    (and (equal (nth (MA-pc) x)
		(nth (MA-pc) y))
	 (equal (nth (MA-regs) x)
		(nth (MA-regs) y))
	 (equal (nth (MA-mem) x)
		(nth (MA-mem) y))
	 (cond ((nth (latch1-validp) x-latch1)
		(equal x-latch1 y-latch1))
	       (t (not (nth (latch1-validp) y-latch1))))
	 (cond ((nth (latch2-validp) x-latch2)
		(equal x-latch2 y-latch2))
	       (t (not (nth (latch2-validp) y-latch2)))))))

#|
Notice that I don't need to prove the theorems in the comments.
They are just interesting side theorems.

(defequiv Ma-=)

(defcong Ma-= Ma-= (Ma-step x) 1)

(defcong Ma-= Ma-= (committed-ma x) 1)
|#

(defun good-MA (MA)
  (and (rationalp (nth (MA-pc) MA))
       (let ((latch1 (nth (MA-latch1) MA))
	     (latch2 (nth (MA-latch2) MA))
	     (NMA (committed-MA MA)))
	 (case (shift-pc latch1 latch2)
	   (0 t)
	   (1 (MA-= (MA-step NMA) MA))
	   (otherwise (MA-= (MA-step (MA-step NMA)) MA))))))

#|
Notice that the following definition will do, but it takes longer to prove.

(defun good-MA (ma)
  (and (rationalp (nth (MA-pc) MA))
       (let ((latch1 (nth (MA-latch1) MA))
	     (latch2 (nth (MA-latch2) MA))
	     (nma (committed-ma ma)))
	 (case (shift-pc latch1 latch2)
	   (0 t)
	   (1 (= (ma-step nma) ma))
	   (otherwise (= (ma-step (ma-step nma)) ma))))))
|#


#|
More interesting side theorems.

(defcong Ma-= equal (good-ma x) 1)

(defthm good-ma-invariant
  (implies (good-ma ma)
	   (good-ma (ma-step ma))))
|#

(defun MA-to-ISA (MA)
  (let ((MA (committed-MA MA)))
    (ISA-state
     (nth (MA-pc) MA)
     (nth (MA-regs) MA)
     (nth (MA-mem) MA))))

(defun MA-rank (MA)
  (let ((latch1 (nth (MA-latch1) MA))
	(latch2 (nth (MA-latch2) MA)))
    (cond ((nth (latch2-validp) latch2)
	   0)
	  ((nth (latch1-validp) latch1)
	   1)
	  (t 2))))

(generate-full-system isa-step isa-p ma-step ma-p
		      ma-to-isa good-ma ma-rank)

(in-theory (disable value-of update-valuation))

(prove-web isa-step isa-p ma-step ma-p ma-to-isa ma-rank)

(wrap-it-up isa-step isa-p ma-step ma-p good-ma ma-to-isa ma-rank)