File: alt-branch.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (392 lines) | stat: -rw-r--r-- 13,586 bytes parent folder | download | duplicates (4)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
;; Copyright (C) 2017, Regents of the University of Texas
;; Written by Cuong Chau
;; License: A 3-clause BSD license.  See the LICENSE file distributed with
;; ACL2.

;; Cuong Chau <ckcuong@cs.utexas.edu>
;; May 2019

(in-package "ADE")

(include-book "../link-joint")
(include-book "../vector-module")

(local (in-theory (disable nth)))

;; ======================================================================

;;; Table of Contents:
;;;
;;; 1. DE Module Generator of ALT-BRANCH
;;; 2. Specify and Prove a State Invariant

;; ======================================================================

;; 1. DE Module Generator of ALT-BRANCH
;;
;; Construct a DE module generator for an alternate branch, ALT-BRANCH, using
;; the link-joint model.  Prove the value and state lemmas for this module
;; generator.

(defconst *alt-branch$go-num* 2)

(defun alt-branch$data-ins-len (data-size)
  (declare (xargs :guard (natp data-size)))
  (+ 3 (mbe :logic (nfix data-size)
            :exec  data-size)))

(defun alt-branch$ins-len (data-size)
  (declare (xargs :guard (natp data-size)))
  (+ (alt-branch$data-ins-len data-size)
     *alt-branch$go-num*))

;; DE module generator of ALT-BRANCH

(module-generator
 alt-branch* (data-size)
 (si 'alt-branch data-size)
 (list* 'full-in 'empty-out0- 'empty-out1-
        (append (sis 'data-in 0 data-size)
                (sis 'go 0 *alt-branch$go-num*)))
 (list* 'act 'act0 'act1
        (sis 'data-out 0 data-size))
 '(select select-buf)
 (list
  ;; LINKS
  ;; Select
  '(select (select-status select-out)
           link1
           (buf-act act select-in))

  ;; Select-buf
  '(select-buf (select-buf-status select-buf-out)
               link1
               (act buf-act select-buf-in))

  ;; JOINTS
  ;; Alt-Branch
  '(g0 (select-out~) b-not (select-out))
  '(g1 (m-full-in) b-and (full-in select-status))
  '(g2 (m-empty-out0-) b-or3 (empty-out0- select-buf-status select-out))
  '(g3 (m-empty-out1-) b-or3 (empty-out1- select-buf-status select-out~))
  (list 'alt-branch-cntl0
        '(act0)
        'joint-cntl
        (list 'm-full-in 'm-empty-out0- (si 'go 0)))
  (list 'alt-branch-cntl1
        '(act1)
        'joint-cntl
        (list 'm-full-in 'm-empty-out1- (si 'go 0)))
  '(alt-branch-cntl (act) b-or (act0 act1))

  (list 'alt-branch-op0
        (sis 'data-out 0 data-size)
        (si 'v-buf data-size)
        (sis 'data-in 0 data-size))
  '(alt-branch-op1 (select-buf-in) b-not (select-out))

  ;; Buffer
  (list 'buf-cntl
        '(buf-act)
        'joint-cntl
        (list 'select-buf-status 'select-status (si 'go 1)))
  '(buf-op (select-in) b-buf (select-buf-out)))

 (declare (xargs :guard (natp data-size))))

(make-event
 `(progn
    ,@(state-accessors-gen 'alt-branch '(select select-buf) 0)))

;; DE netlist generator.  A generated netlist will contain an instance of
;; ALT-BRANCH.

(defund alt-branch$netlist (data-size)
  (declare (xargs :guard (natp data-size)))
  (cons (alt-branch* data-size)
        (union$ (link1$netlist)
                *joint-cntl*
                (v-buf$netlist data-size)
                :test 'equal)))

;; Recognizer for ALT-BRANCH

(defund alt-branch& (netlist data-size)
  (declare (xargs :guard (and (alistp netlist)
                              (natp data-size))))
  (b* ((subnetlist (delete-to-eq (si 'alt-branch data-size) netlist)))
    (and (equal (assoc (si 'alt-branch data-size) netlist)
                (alt-branch* data-size))
         (link1& subnetlist)
         (joint-cntl& subnetlist)
         (v-buf& subnetlist data-size))))

;; Sanity check

(local
 (defthmd check-alt-branch$netlist-64
   (and (net-syntax-okp (alt-branch$netlist 64))
        (net-arity-okp (alt-branch$netlist 64))
        (alt-branch& (alt-branch$netlist 64) 64))))

;; Constraints on the state of ALT-BRANCH

(defund alt-branch$valid-st (st)
  (b* ((select (nth *alt-branch$select* st))
       (select-buf (nth *alt-branch$select-buf* st)))
    (and (link1$valid-st select)
         (link1$valid-st select-buf))))

;; Extract the input and output signals for ALT-BRANCH

(progn
  ;; Extract the input data

  (defun alt-branch$data-in (inputs data-size)
    (declare (xargs :guard (and (true-listp inputs)
                                (natp data-size))))
    (take (mbe :logic (nfix data-size)
               :exec  data-size)
          (nthcdr 3 inputs)))

  (defthm len-alt-branch$data-in
    (equal (len (alt-branch$data-in inputs data-size))
           (nfix data-size)))

  (in-theory (disable alt-branch$data-in))

  ;; Extract the "act0" signal

  (defund alt-branch$act0 (inputs st data-size)
    (b* ((full-in     (nth 0 inputs))
         (empty-out0- (nth 1 inputs))
         (go-signals  (nthcdr (alt-branch$data-ins-len data-size) inputs))

         (go-alt-branch (nth 0 go-signals))

         (select (nth *alt-branch$select* st))
         (select.s (nth *link1$s* select))
         (select.d (nth *link1$d* select))
         (select-buf (nth *alt-branch$select-buf* st))
         (select-buf.s (nth *link1$s* select-buf))

         (m-full-in (f-and full-in (car select.s)))
         (m-empty-out0- (f-or3 empty-out0- (car select-buf.s) (car select.d))))

      (joint-act m-full-in m-empty-out0- go-alt-branch)))

  (defthm alt-branch$act0-inactive
    (implies (or (not (nth 0 inputs))
                 (equal (nth 1 inputs) t))
             (not (alt-branch$act0 inputs st data-size)))
    :hints (("Goal" :in-theory (enable f-or3 alt-branch$act0))))

  ;; Extract the "act1" signal

  (defund alt-branch$act1 (inputs st data-size)
    (b* ((full-in     (nth 0 inputs))
         (empty-out1- (nth 2 inputs))
         (go-signals  (nthcdr (alt-branch$data-ins-len data-size) inputs))

         (go-alt-branch (nth 0 go-signals))

         (select (nth *alt-branch$select* st))
         (select.s (nth *link1$s* select))
         (select.d (nth *link1$d* select))
         (select-buf (nth *alt-branch$select-buf* st))
         (select-buf.s (nth *link1$s* select-buf))

         (m-full-in (f-and full-in (car select.s)))
         (m-empty-out1- (f-or3 empty-out1-
                               (car select-buf.s)
                               (f-not (car select.d)))))

      (joint-act m-full-in m-empty-out1- go-alt-branch)))

  (defthm alt-branch$act1-inactive
    (implies (or (not (nth 0 inputs))
                 (equal (nth 2 inputs) t))
             (not (alt-branch$act1 inputs st data-size)))
    :hints (("Goal" :in-theory (enable f-or3 alt-branch$act1))))

  ;; Extract the "act" signal

  (defund alt-branch$act (inputs st data-size)
    (f-or (alt-branch$act0 inputs st data-size)
          (alt-branch$act1 inputs st data-size)))

  (defthm alt-branch$act-inactive
    (implies (or (not (nth 0 inputs))
                 (and (equal (nth 1 inputs) t)
                      (equal (nth 2 inputs) t)))
             (not (alt-branch$act inputs st data-size)))
    :hints (("Goal" :in-theory (enable alt-branch$act))))
  )

;; The value lemma for ALT-BRANCH

(defthm alt-branch$value
  (b* ((inputs (list* full-in empty-out0- empty-out1-
                      (append data-in go-signals))))
    (implies (and (alt-branch& netlist data-size)
                  (true-listp data-in)
                  (equal (len data-in) data-size)
                  (true-listp go-signals)
                  (equal (len go-signals) *alt-branch$go-num*))
             (equal (se (si 'alt-branch data-size) inputs st netlist)
                    (list* (alt-branch$act inputs st data-size)
                           (alt-branch$act0 inputs st data-size)
                           (alt-branch$act1 inputs st data-size)
                           (v-threefix data-in)))))
  :hints (("Goal"
           :do-not-induct t
           :expand (:free (inputs data-size)
                          (se (si 'alt-branch data-size) inputs st netlist))
           :in-theory (e/d (de-rules
                            alt-branch&
                            alt-branch*$destructure
                            alt-branch$act
                            alt-branch$act0
                            alt-branch$act1)
                           (de-module-disabled-rules)))))

;; This function specifies the next state of ALT-BRANCH.

(defun alt-branch$step (inputs st data-size)
  (b* ((go-signals (nthcdr (alt-branch$data-ins-len data-size) inputs))

       (go-buf (nth 1 go-signals))

       (select (nth *alt-branch$select* st))
       (select.s (nth *link1$s* select))
       (select.d (nth *link1$d* select))
       (select-buf (nth *alt-branch$select-buf* st))
       (select-buf.s (nth *link1$s* select-buf))
       (select-buf.d (nth *link1$d* select-buf))

       (act (alt-branch$act inputs st data-size))
       (buf-act (joint-act (car select-buf.s) (car select.s) go-buf))

       (select-inputs (list buf-act act (car select-buf.d)))
       (select-buf-inputs (list act buf-act (f-not (car select.d)))))
    (list
     ;; Select
     (link1$step select-inputs select)
     ;; Select-buf
     (link1$step select-buf-inputs select-buf))))

;; The state lemma for ALT-BRANCH

(defthm alt-branch$state
  (b* ((inputs (list* full-in empty-out0- empty-out1-
                      (append data-in go-signals))))
    (implies (and (alt-branch& netlist data-size)
                  (equal (len data-in) data-size)
                  (true-listp go-signals)
                  (equal (len go-signals) *alt-branch$go-num*))
             (equal (de (si 'alt-branch data-size) inputs st netlist)
                    (alt-branch$step inputs st data-size))))
  :hints (("Goal"
           :do-not-induct t
           :expand (:free (inputs data-size)
                          (de (si 'alt-branch data-size) inputs st netlist))
           :in-theory (e/d (de-rules
                            alt-branch&
                            alt-branch*$destructure
                            alt-branch$act
                            alt-branch$act0
                            alt-branch$act1)
                           (de-module-disabled-rules)))))

(in-theory (disable alt-branch$step))

;; ======================================================================

;; 2. Specify and Prove a State Invariant

;; Conditions on the inputs

(defund alt-branch$input-format (inputs data-size)
  (declare (xargs :guard (and (true-listp inputs)
                              (natp data-size))))
  (b* ((full-in     (nth 0 inputs))
       (empty-out0- (nth 1 inputs))
       (empty-out1- (nth 2 inputs))
       (data-in     (alt-branch$data-in inputs data-size))
       (go-signals  (nthcdr (alt-branch$data-ins-len data-size) inputs)))
    (and
     (booleanp full-in)
     (booleanp empty-out0-)
     (booleanp empty-out1-)
     (or (not full-in) (bvp data-in))
     (true-listp go-signals)
     (= (len go-signals) *alt-branch$go-num*)
     (equal inputs
            (list* full-in empty-out0- empty-out1-
                   (append data-in go-signals))))))

(defthm booleanp-alt-branch$act0
  (implies (and (alt-branch$input-format inputs data-size)
                (alt-branch$valid-st st))
           (booleanp (alt-branch$act0 inputs st data-size)))
  :hints (("Goal" :in-theory (enable alt-branch$input-format
                                     alt-branch$valid-st
                                     alt-branch$act0)))
  :rule-classes (:rewrite :type-prescription))

(defthm booleanp-alt-branch$act1
  (implies (and (alt-branch$input-format inputs data-size)
                (alt-branch$valid-st st))
           (booleanp (alt-branch$act1 inputs st data-size)))
  :hints (("Goal" :in-theory (enable alt-branch$input-format
                                     alt-branch$valid-st
                                     alt-branch$act1)))
  :rule-classes (:rewrite :type-prescription))

(defthm booleanp-alt-branch$act
  (implies (and (alt-branch$input-format inputs data-size)
                (alt-branch$valid-st st))
           (booleanp (alt-branch$act inputs st data-size)))
  :hints (("Goal" :in-theory (enable alt-branch$act)))
  :rule-classes (:rewrite :type-prescription))

(defthm alt-branch$valid-st-preserved
  (implies (and (alt-branch$input-format inputs data-size)
                (alt-branch$valid-st st))
           (alt-branch$valid-st
            (alt-branch$step inputs st data-size)))
  :hints (("Goal"
           :in-theory (e/d (f-sr
                            alt-branch$input-format
                            alt-branch$valid-st
                            alt-branch$step
                            alt-branch$act
                            alt-branch$act0
                            alt-branch$act1)
                           ()))))

;; A state invariant

(defund alt-branch$inv (st)
  (b* ((select (nth *alt-branch$select* st))
       (select.s (nth *link1$s* select))
       (select-buf (nth *alt-branch$select-buf* st))
       (select-buf.s (nth *link1$s* select-buf)))
    (not (equal select.s select-buf.s))))

(defthm alt-branch$inv-preserved
  (implies (and (alt-branch$input-format inputs data-size)
                (alt-branch$valid-st st)
                (alt-branch$inv st))
           (alt-branch$inv (alt-branch$step inputs st data-size)))
  :hints (("Goal"
           :in-theory (e/d (f-sr
                            alt-branch$input-format
                            alt-branch$valid-st
                            alt-branch$inv
                            alt-branch$step
                            alt-branch$act
                            alt-branch$act0
                            alt-branch$act1)
                           ()))))