-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbang-bang.lisp
194 lines (144 loc) · 5.53 KB
/
bang-bang.lisp
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
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: (*SIM-I COMMON-LISP-GLOBAL); Base: 10; Muser: yes -*-
(in-package :*sim-i)
;;;> *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
;;;>
;;;> The Thinking Machines *Lisp Simulator is in the public domain.
;;;> You are free to do whatever you like with it, including but
;;;> not limited to distributing, modifying, and copying.
;;;>
;;;> *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
;;; Author: JP Massar.
(DEFUN !! (VALUE)
"Returns a pvar that contains VALUE in all processors."
(cond
((eq value t) t!!)
((eq value nil) nil!!)
(t (!!-with-hash value))
))
;; Find constants in the hash table and return their
;; corresponding pvar. If the constant isn't in the
;; hash table yet and the hash table isn't full, put it in.
(defun !!-with-hash (value)
;; Get the hash table for the current vp set.
(let* ((current-vp-set *current-vp-set*)
(current-hash-table (vp-set-constants-hash-table current-vp-set))
)
;; If the hash table hasn't been created yet create it.
(when (not current-hash-table)
(setf (vp-set-constants-hash-table current-vp-set)
(make-hash-table :test #'eql :size *maximum-number-of-entries-in-constant-pvar-hash-table*)
)
(setq current-hash-table (vp-set-constants-hash-table current-vp-set))
)
;; If the value is a key in the hash table, use the
;; pvar value of that key.
(let ((pvar (gethash value current-hash-table)))
(if pvar (return-from !!-with-hash pvar))
)
(let ((constant-heap? nil))
(let ((result
(cond
;; We only hash scalars.
((or (numberp value) (characterp value))
;; should we insert this constant into the hash table
;; for future reference?
(let ((insert-into-table
(and (not (floatp value)) (not (complexp value))
(< (hash-table-count current-hash-table)
*maximum-number-of-entries-in-constant-pvar-hash-table*
)))
(new-pvar nil)
)
;; create the new pvar. If it is to go into the hash table
;; make it permanent, otherwise make it temporary.
;; fill all its fields with 'value'.
(setq new-pvar
(if insert-into-table
(prog1
(make-general-pvar :heap)
(setq constant-heap? t)
)
(make-general-pvar :stack)
))
(setf (pvar-name new-pvar) (intern (format nil "CONSTANT-~S" value)))
(fill-array (pvar-array new-pvar) value)
(make-non-void new-pvar)
;; put the pvar into the hash table if we want to.
(if insert-into-table (setf (gethash value current-hash-table) new-pvar))
new-pvar
))
;; handle arrays and structures separately.
((and (symbolp (type-of value))
(structure-pvar-type-known-*defstruct-type (type-of value))
)
(!!-structure (type-of value) value)
)
((arrayp value) (!!-array value))
(t (error "Cannot put values of type ~S into a pvar" (type-of value)))
)))
(setf (pvar-constant? result) (if constant-heap? :heap-constant t))
(setf (pvar-lvalue? result) nil)
(setf (pvar-constant-value result) value)
result
))))
(defun !!-structure (type value)
(let ((!!-function (get type '*defstruct-!!-function)))
(when (null !!-function)
(error "Internal error. The type ~S is a known *DEFSTRUCT type but has no !! function" type)
)
(funcall !!-function value)
))
(defun front-end!! (value)
(*let (result)
(let ((result-array (pvar-array result)))
(with-simple-vectors (result-array)
(do-for-selected-processors-internal (j) (setf (aref result-array j) value))
)
result
)))
(defun front-end-p!! (pvar)
(simple-pvar-argument!! pvar)
(safety-check (new-pvar-check pvar 'front-end-p!!))
(cond
((array-pvar-p pvar) nil!!)
((structure-pvar-p pvar) nil!!)
((general-pvar-p pvar)
(*let (result)
(let ((result-array (pvar-array result))
(pvar-array (pvar-array pvar))
)
(with-simple-vectors (result-array pvar-array)
(do-for-selected-processors-internal (j)
(let ((value (aref pvar-array j)))
(setf (aref result-array j)
(and value (not (eq t value)) (not (numberp value)) (not (characterp value))))
)))
result
)))))
(defun print-hash ()
(maphash #'(lambda (key val) (format t "~%~S: ~S" key val))
*constant-pvar-hash-table*
))
(defun self-address!! ()
"Returns the self address of each processor."
(incf-use-count 'self-address!!)
(vp-set-self-address!! *current-vp-set*)
)
(defun !!-array (value &optional (element-type t))
(assert (arrayp value) () "Internal error. !!-ARRAY called with non-array value")
(let ((result (make-array-pvar :stack `(pvar (array ,element-type ,(array-dimensions value))))))
(setf (pvar-constant? result) nil)
(setf (pvar-lvalue? result) t)
(setf (pvar-name result) '!!-RETURN)
(let ((displaced-value-array
(if (vectorp value)
value
(make-array (array-total-size value) :displaced-to value :element-type (array-element-type value))
))
(displaced-pvar-array (pvar-array-displaced-array result))
)
(dotimes (j (length displaced-value-array))
(*set (aref displaced-pvar-array j) (!! (aref displaced-value-array j)))
))
result
))