3
(set-enforce-redundancy t)
7
(local (include-book "../support/top"))
9
(set-inhibit-warnings "theory")
10
(local (in-theory nil))
12
;;;**********************************************************************
13
;;; Radix-4 Booth Encoding
14
;;;**********************************************************************
17
(+ (bitn y (1- (* 2 i)))
19
(* -2 (bit y (1+ (* 2 i))))))
21
(defun sum-theta (m y)
24
(+ (* (expt 2 (* 2 (1- m))) (theta (1- m) y))
25
(sum-theta (1- m) y))))
28
(defthm sum-theta-lemma
29
(implies (and (not (zp m))
30
(bvecp y (1- (* 2 m))))
31
(equal y (sum-theta m y)))
35
(defun bmux4 (zeta x n)
43
(defun neg (x) (if (< x 0) 1 0))
45
(encapsulate ((zeta (i) t))
46
(local (defun zeta (i) (declare (ignore i)) 0))
48
(and (integerp (zeta i))
56
(lnot (neg (zeta i)) 1) 1
57
(bmux4 (zeta i) x n) n)
59
(lnot (neg (zeta i)) 1) 1
60
(bmux4 (zeta i) x n) n
68
(+ (* (expt 2 (* 2 (1- m))) (zeta (1- m)))
71
(defun sum-pp4 (x m n)
75
(sum-pp4 x (1- m) n))))
79
(implies (and (not (zp n))
84
(+ (expt 2 (+ n (* 2 m)))
86
(- (* (expt 2 (* 2 (1- m))) (neg (zeta (1- m))))))))
89
(defun pp4-theta (i x y n)
92
(lnot (neg (theta i y)) 1) 1
93
(bmux4 (theta i y) x n) n)
95
(lnot (neg (theta i y)) 1) 1
96
(bmux4 (theta i y) x n) n
98
(neg (theta (1- i) y)) 1
101
(defun sum-pp4-theta (x y m n)
104
(+ (pp4-theta (1- m) x y n)
105
(sum-pp4-theta x y (1- m) n))))
108
(defthm booth4-corollary
109
(implies (and (not (zp n))
112
(bvecp y (1- (* 2 m))))
114
(sum-pp4-theta x y m n))
115
(+ (expt 2 (+ n (* 2 m)))
119
;;;**********************************************************************
120
;;; Statically Encoded Multiplier Arrays
121
;;;**********************************************************************
126
(defun mu (i y) (+ (bits y (1+ (* 2 i)) (* 2 i)) (chi i y)))
131
(if (>= (mu (1- i) y) 3)
137
(if (= (bits (mu i y) 1 0) 3)
139
(bits (mu i y) 1 0)))
142
(member (phi i y) '(-1 0 1 2)))
144
(defun sum-odd-powers-of-2 (m)
147
(+ (expt 2 (1- (* 2 m)))
148
(sum-odd-powers-of-2 (1- m)))))
152
(implies (and (natp m)
154
(<= y (sum-odd-powers-of-2 m)))
160
(implies (and (natp m)
162
(<= y (sum-odd-powers-of-2 m)))
163
(>= (phi (1- m) y) 0))
169
(+ (* (expt 2 (* 2 (1- m))) (phi (1- m) y))
170
(sum-phi (1- m) y))))
173
(defthm sum-phi-lemma
174
(implies (and (natp m)
176
(<= y (sum-odd-powers-of-2 m)))
177
(equal y (sum-phi m y)))
180
(defun pp4-phi (i x y n)
183
(lnot (neg (phi i y)) 1) 1
184
(bmux4 (phi i y) x n) n)
186
(lnot (neg (phi i y)) 1) 1
187
(bmux4 (phi i y) x n) n
189
(neg (phi (1- i) y)) 1
192
(defun sum-pp4-phi (x y m n)
195
(+ (pp4-phi (1- m) x y n)
196
(sum-pp4-phi x y (1- m) n))))
200
(implies (and (not (zp n))
203
(<= y (sum-odd-powers-of-2 m)))
205
(sum-pp4-phi x y m n))
206
(+ (expt 2 (+ n (* 2 m)))
210
;;;**********************************************************************
211
;;; Encoding Redundant Representations
212
;;;**********************************************************************
215
(defun gamma (i a b c)
218
(lior (bitn a (1- (* 2 i)))
219
(bitn b (1- (* 2 i)))
223
(defun delta (i a b c d)
226
(land (lior (land (bitn a (- (* 2 i) 2)) (bitn b (- (* 2 i) 2)) 1)
227
(lior (land (bitn a (- (* 2 i) 2)) (gamma (1- i) a b c) 1)
228
(land (bitn b (- (* 2 i) 2)) (gamma (1- i) a b c) 1)))
229
(lnot (lxor (bitn a (1- (* 2 i))) (bitn b (1- (* 2 i))) 1) 1)
233
(defun psi (i a b c d)
234
(+ (bits a (1+ (* 2 i)) (* 2 i))
235
(bits b (1+ (* 2 i)) (* 2 i))
238
(* -4 (+ (gamma (1+ i) a b c)
239
(delta (1+ i) a b c d)))))
242
(implies (and (natp m)
243
(bvecp a (- (* 2 m) 3))
244
(bvecp b (- (* 2 m) 3))
247
(and (equal (gamma m a b c) 0)
248
(equal (delta m a b c d) 0)
249
(>= (psi (1- m) a b c d) 0)))
252
(defun sum-psi (m a b c d)
255
(+ (* (expt 2 (* 2 (1- m))) (psi (1- m) a b c d))
256
(sum-psi (1- m) a b c d))))
259
(defthm sum-psi-lemma
260
(implies (and (natp m)
261
(bvecp a (- (* 2 m) 3))
262
(bvecp b (- (* 2 m) 3))
265
(equal (+ a b c d) (sum-psi m a b c d)))
270
(implies (and (natp m)
271
(bvecp a (- (* 2 m) 3))
272
(bvecp b (- (* 2 m) 3))
277
(and (integerp (psi i a b c d))
278
(<= (psi i a b c d) 2)
279
(>= (psi i a b c d) -2)))
282
(defun pp4-psi (i x a b c d n)
285
(lnot (neg (psi i a b c d)) 1) 1
286
(bmux4 (psi i a b c d) x n) n)
288
(lnot (neg (psi i a b c d)) 1) 1
289
(bmux4 (psi i a b c d) x n) n
291
(neg (psi (1- i) a b c d)) 1
294
(defun sum-pp4-psi (x a b c d m n)
297
(+ (pp4-psi (1- m) x a b c d n)
298
(sum-pp4-psi x a b c d (1- m) n))))
301
(defthm redundant-booth
302
(implies (and (natp m)
303
(bvecp a (- (* 2 m) 3))
304
(bvecp b (- (* 2 m) 3))
309
(sum-pp4-psi x a b c d m n))
310
(+ (expt 2 (+ n (* 2 m)))
314
;;;**********************************************************************
315
;;; Radix-8 Booth Encoding
316
;;;**********************************************************************
320
(+ (bitn y (1- (* 3 i)))
322
(* 2 (bitn y (1+ (* 3 i))))
323
(* -4 (bit y (+ 2 (* 3 i))))))
328
(+ (* (expt 2 (* 3 (1- m))) (eta (1- m) y))
329
(sum-eta (1- m) y))))
332
(defthm sum-eta-lemma
333
(implies (and (not (zp m))
334
(bvecp y (1- (* 2 m))))
335
(equal y (sum-eta m y)))
339
(defun bmux8 (zeta x n)
344
(-2 (lnot (* 2 x) n))
346
(-3 (lnot (* 3 x) n))
348
(-4 (lnot (* 4 x) n))
351
(encapsulate ((xi (i) t))
352
(local (defun xi (i) (declare (ignore i)) 0))
354
(and (integerp (xi i))
362
(lnot (neg (xi i)) 1) 1
363
(bmux8 (xi i) x n) n)
365
(lnot (neg (xi i)) 1) 1
374
(+ (* (expt 2 (* 3 (1- m))) (xi (1- m)))
377
(defun sum-pp8 (x m n)
381
(sum-pp8 x (1- m) n))))
385
(implies (and (not (zp n))
390
(+ (expt 2 (+ n (* 3 m)))
392
(- (* (expt 2 (* 3 (1- m))) (neg (xi (1- m))))))))
395
(defun pp8-eta (i x y n)
398
(lnot (neg (eta i y)) 1) 1
399
(bmux8 (eta i y) x n) n)
401
(lnot (neg (eta i y)) 1) 1
402
(bmux8 (eta i y) x n) n
404
(neg (eta (1- i) y)) 1
407
(defun sum-pp8-eta (x y m n)
410
(+ (pp8-eta (1- m) x y n)
411
(sum-pp8-eta x y (1- m) n))))
414
(defthm booth8-corollary
415
(implies (and (not (zp n))
418
(bvecp y (1- (* 3 m))))
420
(sum-pp8-eta x y m n))
421
(+ (expt 2 (+ n (* 3 m)))