forked from g000001/Starlisp-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal-addressing.lisp
217 lines (163 loc) · 7.31 KB
/
internal-addressing.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
;; -*- Mode:Lisp; Syntax:Common-Lisp; Package: (*SIM-I COMMON-LISP-GLOBAL); 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.
;;;> Bugs, comments and revisions due to porting can be sent to:
;;;> [email protected]. Other than to Thinking Machines'
;;;> customers, no promise of support is intended or implied.
;;;>
;;;> *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
;;; Author: JP Massar.
;;; Auxiliary functions for argument checking for the addressing functions
(defun vp-set-check (vp-set function-name)
(assert (vp-set-p vp-set) ()
"The vp set argument to the function ~S was not a vp set, but has the value ~A"
function-name vp-set
))
(defun validate-all-pvars (pvar-index-list function-name)
(new-multiple-pvar-check pvar-index-list function-name)
)
(defun check-grid-indices-values (index-list vp-set function-name)
;; make sure each element of index-list is within the
;; dimension boundaries of its dimension.
(let ((j 0))
(mapc
#'(lambda (index upper-exclusive-bound)
(assert (valid-integer-range-exclusive index 0 upper-exclusive-bound) ()
"In ~S, the value for grid dimension ~D, ~S, is out of range with respect to vp set ~S"
function-name j index vp-set
)
(incf j)
)
index-list
(vp-set-dimensions vp-set)
))
t)
(defun grid-indices-values-valid-p (index-list vp-set)
;; make sure each element of index-list is within the
;; dimension boundaries of its dimension.
(let ((j 0))
(mapc
#'(lambda (index upper-exclusive-bound)
(when (null (valid-integer-range-exclusive index 0 upper-exclusive-bound))
(return-from grid-indices-values-valid-p nil)
)
(incf j)
)
index-list
(vp-set-dimensions vp-set)
))
t)
(defun check-grid-indices (index-list vp-set function-name)
;; make sure index-list is the same length as the
;; number of grid dimensions and that each element
;; of the list is within the dimension boundaries
;; of its dimension.
(assert (eql (length index-list) (length (vp-set-dimensions vp-set))) ()
"In ~S, wrong number of grid addresses provided (should be ~D)"
function-name (length (vp-set-dimensions vp-set)))
(check-grid-indices-values index-list vp-set function-name)
t
)
(defun check-cube-address-pvar (pvar vp-set function-name)
(let ((pvar-array (pvar-array pvar))
(nprocessors (vp-set-size vp-set))
)
(with-simple-vectors (pvar-array)
(do-for-selected-processors (j)
(when (not (valid-integer-range-exclusive (aref pvar-array j) 0 nprocessors))
(error "~S: Cube address value ~S,~% at processor address ~D,~% is not valid with respect to vp set ~S."
function-name (aref pvar-array j) j vp-set
))))))
(defun check-dimension-pvar (pvar vp-set function-name)
(let ((pvar-array (pvar-array pvar))
(number-of-dimensions (length (vp-set-dimensions vp-set)))
)
(with-simple-vectors (pvar-array)
(do-for-selected-processors-internal (j)
(when (not (valid-integer-range-exclusive (aref pvar-array j) 0 number-of-dimensions))
(error
"~S: Dimension value ~S,~% at processor address ~D,~%~
is not valid with respect to vp set ~S, which has ~D dimensions"
function-name (aref pvar-array j) j vp-set (length (vp-set-dimensions vp-set))
))))))
(defun internal-cube-from-vp-grid-address!!
(function-name error-if-bad-address relativep vp-set index-pvars)
"Translates a grid address into a cube address in each selected processor.
If error-if-bad-address is nil, NIL is returned in the returned pvar
for the processors which have an invalid grid address specified,
otherwise an error is generated. The grid addresses may be relative,
in which case they are converted to absolute.
"
(simple-pvar-argument!! &rest index-pvars)
(safety-check
(progn
(vp-set-check vp-set function-name)
(new-multiple-pvar-check index-pvars function-name)
))
(let* ((return-pvar (allocate-temp-general-pvar))
(return-array (pvar-array return-pvar))
(number-of-dimensions (length index-pvars))
(temp-array-of-indices (make-sequence 'simple-vector number-of-dimensions))
(temp-list-of-indices-for-processor (make-list number-of-dimensions))
)
(with-simple-vectors (return-array)
;; put the pvar arrays into a vector for fast access
(dotimes (j number-of-dimensions)
(setf (aref temp-array-of-indices j) (pvar-array (nth j index-pvars)))
)
(let ((any-set nil))
(do-for-selected-processors-internal (processor)
(setq any-set t)
;; for each active processor, put its grid coordinate pvar
;; values into a vector. If the grid coordinates are relative
;; add in the absolute grid coordinates for this processor.
(let ((*interpreter-safety* 0))
(dotimes (dimension number-of-dimensions)
(setf (nth dimension temp-list-of-indices-for-processor)
(if relativep
(+ (aref (aref temp-array-of-indices dimension) processor)
(internal-grid-from-vp-cube-address vp-set processor dimension function-name)
)
(aref (aref temp-array-of-indices dimension) processor)
))))
(if error-if-bad-address
;; check that the grid coordinates are valid, then convert them
;; to a cube address.
(setf (aref return-array processor)
(internal-cube-from-vp-grid-address vp-set temp-list-of-indices-for-processor function-name)
)
;; if it's a valid address convert the address and store it,
;; otherwise store NIL.
(setf (aref return-array processor)
(if (not (grid-indices-values-valid-p temp-list-of-indices-for-processor vp-set))
nil
(internal-cube-address-from-grid-address-list
(vp-set-array-of-cube-addresses vp-set)
temp-list-of-indices-for-processor
)))
))
(when any-set (make-non-void return-pvar))
))
return-pvar
))
(defun internal-grid-from-vp-cube-address (vp-set cube-address dimension function-name)
(safety-check
(progn
(vp-set-check vp-set function-name)
(check-cube-address cube-address vp-set function-name)
(check-dimension dimension vp-set function-name)
))
(aref (vp-set-array-of-grid-addresses vp-set) cube-address dimension)
)
(defun internal-cube-from-vp-grid-address (vp-set indices function-name)
(safety-check
(progn
(vp-set-check vp-set function-name)
(check-grid-indices indices vp-set function-name)
))
(internal-cube-address-from-grid-address-list (vp-set-array-of-cube-addresses vp-set) indices)
)