42
46
(declare (xargs :guard t))
49
(defun f1-list-tailrec (x acc)
50
(declare (xargs :guard (true-listp acc)))
53
(f1-list-tailrec (cdr x)
54
(cons (f1 (car x)) acc))))
46
57
(declare (xargs :guard t))
58
(f1-list-tailrec x nil))
54
62
(declare (xargs :guard t))
65
(defun f2-list-tailrec (x acc)
66
(declare (xargs :guard (true-listp acc)))
69
(f2-list-tailrec (cdr x)
70
(cons (f2 (car x)) acc))))
58
73
(declare (xargs :guard t))
74
(f2-list-tailrec x nil))
66
78
(declare (xargs :guard t))
81
(defun f3-list-tailrec (x acc)
82
(declare (xargs :guard (true-listp acc)))
87
(f3-list-tailrec (cdr x)
70
92
(declare (xargs :guard t))
73
(mv-let (a b) (f3 (car x))
74
(list* a b (f3-list (cdr x))))))
93
(f3-list-tailrec x nil))
78
97
(declare (xargs :guard t))
98
(cons 1/2 (cons x y)))
100
(defun f4-list-tailrec (x acc)
101
(declare (xargs :guard (true-listp acc)))
106
(f4-list-tailrec (cdr x)
107
(cons (f4 (first x) (second x))
81
110
(defun f4-list (x)
82
111
(declare (xargs :guard t))
87
(cons (f4 (first x) (second x))
112
(f4-list-tailrec x nil))
92
116
(declare (xargs :guard t))
119
(defun f5-list-tailrec (x acc)
120
(declare (xargs :guard (true-listp acc)))
126
(f5 (first x) (second x))
127
(f5-list-tailrec (cdr x)
95
130
(defun f5-list (x)
96
131
(declare (xargs :guard t))
101
(mv-let (a b) (f5 (first x) (second x))
102
(list* a b (f5-list (cdr x)))))))
132
(f5-list-tailrec x nil))
106
135
(defun f6 (x y z)
107
136
(declare (xargs :guard t))
139
(defun f6-list-tailrec (x acc)
140
(declare (xargs :guard (true-listp acc)))
147
(f6-list-tailrec (cdr x)
148
(cons (f6 (first x) (second x) (third x))
110
151
(defun f6-list (x)
111
152
(declare (xargs :guard t))
118
(cons (f6 (first x) (second x) (third x))
119
(f6-list (cdr x)))))))
153
(f6-list-tailrec x nil))
123
156
(defconst *stuff*
237
;; (defun show-me-default-hons-space (from)
238
;; (declare (xargs :guard t)
240
;; (er hard? 'show-me-default-hons-space
241
;; "Raw lisp definition not installed"))
242
;; (defttag :show-me-default-hons-space)
245
;; (defun show-me-default-hons-space (from)
246
;; (format t "~S: Default-hs is ~S~%"
248
;; (funcall (intern "%ADDRESS-OF" "CCL") *default-hs*))
251
(defun test-simultaneously-acons ()
252
; We may need to verify guards to execute the raw Lisp (parallelized) version
254
(declare (xargs :verify-guards t))
256
;; (show-me-default-hons-space 'thread-1-pre)
259
;; (show-me-default-hons-space 'thread-1-post)
263
;; (show-me-default-hons-space 'thread-2-pre)
266
;; (show-me-default-hons-space 'thread-2-post)
270
(assert! (test-simultaneously-acons))
272
(defun test-simultaneously-acons-with-spec-mv-let ()
273
; We must verify guards to execute the raw Lisp (parallelized) version of
275
(declare (xargs :verify-guards t))
279
(mv (hons-acons 3 4 nil)
282
(+ (caar x) (cdar x) (caar y) (cdar y) z)
283
(+ (caar y) (cadr y) z)))))
285
(assert! (test-simultaneously-acons-with-spec-mv-let))
287
(defun test-simultaneously-hons ()
288
; We may need to verify guards to execute the raw Lisp (parallelized) version
290
(declare (xargs :verify-guards t))
294
(assert! (test-simultaneously-hons))
296
(defun test-simultaneously-hons-with-spec-mv-let ()
297
; We must verify guards to execute the raw Lisp (parallelized) version of
299
(declare (xargs :verify-guards t))
305
(+ (car x) (cdr x) (car y) (cdr y) z)
306
(+ (car y) (cdr y) z)))))
308
(assert! (test-simultaneously-hons-with-spec-mv-let))
312
(defun make-memoized-alist (x)
313
(declare (xargs :guard t))
314
(make-fast-alist (cons (cons 'x x)
319
(memoize 'make-memoized-alist)
321
(defun do-stuff-to-fast-alist (n alist)
322
(declare (xargs :guard (natp n)))
325
(?a (hons-get 'a alist))
326
(?b (hons-get 'b alist))
327
(?c (hons-get 'c alist))
328
(alist (hons-acons n n alist)))
329
(do-stuff-to-fast-alist (- n 1) alist)))
333
(defconst *spec* (do-stuff-to-fast-alist 1000 (make-memoized-alist 5)))
335
(defun check-both-with-pand (n)
336
(declare (xargs :guard (natp n)))
337
(pand (equal (do-stuff-to-fast-alist n (make-fast-alist (make-memoized-alist 5))) *spec*)
338
(equal (do-stuff-to-fast-alist n (make-fast-alist (make-memoized-alist 5))) *spec*)))
340
(assert! (check-both-with-pand 1000))
345
;; Basic check to try to see if threads will interfere with one another
347
(defun add-some-honses (x acc)
348
(declare (xargs :guard t))
351
(add-some-honses (cdr x)
352
(list* (hons-copy (car x))
353
(hons (car x) (car x))
356
(declare (xargs :guard t))
357
(let ((x (add-some-honses x x)))
366
(declare (xargs :guard t))
367
(let ((x (add-some-honses x x)))
375
(comp t) ;; so gcl will compile add-some-honses instead of stack overflowing
377
(defconst *thread1-spec* (thread1 *data*))
378
(defconst *thread2-spec* (thread2 *data*))
380
(defun check-thread1 (n)
381
(declare (xargs :guard (natp n)))
384
(and (equal *thread1-spec* (thread1 *data*))
385
(check-thread1 (- n 1)))))
387
(defun check-thread2 (n)
388
(declare (xargs :guard (natp n)))
391
(and (equal *thread2-spec* (thread2 *data*))
392
(check-thread2 (- n 1)))))
394
(defun check-both (n)
395
(declare (xargs :guard (natp n)))
396
(pand (check-thread1 n)
399
;; Timings on compute-1-1:
400
;; - ACL2(hp): no memoization: 12.33 seconds (many GC messages)
401
;; - ACL2(h): no memoization: 15.54 seconds (many GC messages)
403
(assert! (time$ (check-both 100)))
405
(value-triple (clear-memoize-tables))
408
(memoize 'f2 :condition '(not (equal x -1/3)))
410
(memoize 'f4 :condition '(not (equal x -1/3)))
412
(memoize 'f6 :condition '(not (equal x -1/3)))
414
;; Timings on compute-1-1:
415
;; - ACL2(hp): memoization, lock contention: 242 seconds (many gc messages)
416
;; - ACL2(h): memoization, no lock contention: 61 seconds (many gc messages)
417
(assert! (time$ (check-both 100)))