1 ;;;; the HPPA definitions for array operations
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; Allocator for the array header.
15 (define-vop (make-array-header)
16 (:translate make-array-header)
18 (:args (type :scs (any-reg))
19 (rank :scs (any-reg)))
20 (:arg-types tagged-num tagged-num)
21 (:temporary (:scs (descriptor-reg) :to (:result 0) :target result) header)
22 (:temporary (:scs (non-descriptor-reg) :type random) ndescr)
23 (:results (result :scs (descriptor-reg)))
26 (inst move alloc-tn header)
27 (inst dep other-pointer-lowtag 31 3 header)
28 (inst addi (* (1+ array-dimensions-offset) n-word-bytes) rank ndescr)
29 (inst dep 0 31 3 ndescr)
30 (inst add alloc-tn ndescr alloc-tn)
31 (inst addi (fixnumize (1- array-dimensions-offset)) rank ndescr)
32 (inst sll ndescr n-widetag-bits ndescr)
33 (inst or ndescr type ndescr)
34 (inst srl ndescr 2 ndescr)
35 (storew ndescr header 0 other-pointer-lowtag))
36 (move header result)))
39 ;;;; Additional accessors and setters for the array header.
40 (define-full-reffer %array-dimension *
41 array-dimensions-offset other-pointer-lowtag
42 (any-reg) positive-fixnum sb!kernel:%array-dimension)
44 (define-full-setter %set-array-dimension *
45 array-dimensions-offset other-pointer-lowtag
46 (any-reg) positive-fixnum sb!kernel:%set-array-dimension)
48 (define-vop (array-rank-vop)
49 (:translate sb!kernel:%array-rank)
51 (:args (x :scs (descriptor-reg)))
52 (:results (res :scs (unsigned-reg)))
53 (:result-types positive-fixnum)
55 (loadw res x 0 other-pointer-lowtag)
56 (inst srl res n-widetag-bits res)
57 (inst addi (- (1- array-dimensions-offset)) res res)))
59 ;;;; Bounds checking routine.
60 (define-vop (check-bound)
61 (:translate %check-bound)
63 (:args (array :scs (descriptor-reg))
64 (bound :scs (any-reg descriptor-reg))
65 (index :scs (any-reg descriptor-reg) :target result))
66 (:results (result :scs (any-reg descriptor-reg)))
68 (:save-p :compute-only)
70 (let ((error (generate-error-code vop invalid-array-index-error
72 (inst bc :>= nil index bound error))
76 ;;;; Accessors/Setters
78 ;;; Variants built on top of word-index-ref, etc. I.e. those vectors whos
79 ;;; elements are represented in integer registers and are built out of
80 ;;; 8, 16, or 32 bit elements.
81 (macrolet ((def-full-data-vector-frobs (type element-type &rest scs)
83 (define-full-reffer ,(symbolicate "DATA-VECTOR-REF/" type) ,type
84 vector-data-offset other-pointer-lowtag ,scs ,element-type
86 (define-full-setter ,(symbolicate "DATA-VECTOR-SET/" type) ,type
87 vector-data-offset other-pointer-lowtag ,scs ,element-type
90 (def-partial-data-vector-frobs
91 (type element-type size signed &rest scs)
93 (define-partial-reffer ,(symbolicate "DATA-VECTOR-REF/" type) ,type
94 ,size ,signed vector-data-offset other-pointer-lowtag ,scs
95 ,element-type data-vector-ref)
96 (define-partial-setter ,(symbolicate "DATA-VECTOR-SET/" type) ,type
97 ,size vector-data-offset other-pointer-lowtag ,scs
98 ,element-type data-vector-set))))
100 (def-full-data-vector-frobs simple-vector * descriptor-reg any-reg)
102 (def-partial-data-vector-frobs simple-base-string character :byte nil character-reg)
104 (def-full-data-vector-frobs simple-character-string character character-reg)
106 (def-partial-data-vector-frobs simple-array-unsigned-byte-7 positive-fixnum
107 :byte nil unsigned-reg signed-reg)
108 (def-partial-data-vector-frobs simple-array-unsigned-byte-8 positive-fixnum
109 :byte nil unsigned-reg signed-reg)
111 (def-partial-data-vector-frobs simple-array-unsigned-byte-15 positive-fixnum
112 :short nil unsigned-reg signed-reg)
113 (def-partial-data-vector-frobs simple-array-unsigned-byte-16 positive-fixnum
114 :short nil unsigned-reg signed-reg)
116 (def-full-data-vector-frobs simple-array-unsigned-byte-31 unsigned-num
118 (def-full-data-vector-frobs simple-array-unsigned-byte-32 unsigned-num
121 (def-partial-data-vector-frobs simple-array-signed-byte-8 tagged-num
124 (def-partial-data-vector-frobs simple-array-signed-byte-16 tagged-num
127 (def-full-data-vector-frobs simple-array-unsigned-byte-29 positive-fixnum any-reg)
128 (def-full-data-vector-frobs simple-array-signed-byte-30 tagged-num any-reg)
130 (def-full-data-vector-frobs simple-array-signed-byte-32 signed-num signed-reg))
133 ;;; Integer vectors whos elements are smaller than a byte. I.e. bit, 2-bit,
134 ;;; and 4-bit vectors.
135 (macrolet ((def-small-data-vector-frobs (type bits)
136 (let* ((elements-per-word (floor n-word-bits bits))
137 (bit-shift (1- (integer-length elements-per-word))))
139 (define-vop (,(symbolicate 'data-vector-ref/ type))
140 (:note "inline array access")
141 (:translate data-vector-ref)
143 (:args (object :scs (descriptor-reg))
144 (index :scs (unsigned-reg)))
145 (:arg-types ,type positive-fixnum)
146 (:results (result :scs (unsigned-reg) :from (:argument 0)))
147 (:result-types positive-fixnum)
148 (:temporary (:scs (non-descriptor-reg)) temp)
149 (:temporary (:scs (interior-reg)) lip)
151 (inst srl index ,bit-shift temp)
152 (inst sh2add temp object lip)
153 (loadw result lip vector-data-offset other-pointer-lowtag)
154 (inst zdep index ,(- 32 (integer-length bits)) ,bit-shift temp)
156 `((inst addi ,(1- bits) temp temp)))
157 (inst mtctl temp :sar)
158 (inst extru result :variable ,bits result)))
159 (define-vop (,(symbolicate 'data-vector-ref-c/ type))
160 (:translate data-vector-ref)
162 (:args (object :scs (descriptor-reg)))
163 (:arg-types ,type (:constant index))
165 (:results (result :scs (unsigned-reg)))
166 (:result-types positive-fixnum)
167 (:temporary (:scs (non-descriptor-reg)) temp)
169 (multiple-value-bind (word extra) (floor index ,elements-per-word)
170 (let ((offset (- (* (+ word vector-data-offset) n-word-bytes)
171 other-pointer-lowtag)))
172 (cond ((typep offset '(signed-byte 14))
173 (inst ldw offset object result))
175 (inst ldil (ldb (byte 21 11) offset) temp)
176 (inst ldw (ldb (byte 11 0) offset) temp result))))
177 (inst extru result (+ (* extra ,bits) ,(1- bits)) ,bits result))))
178 (define-vop (,(symbolicate 'data-vector-set/ type))
179 (:note "inline array store")
180 (:translate data-vector-set)
182 (:args (object :scs (descriptor-reg))
183 (index :scs (unsigned-reg))
184 (value :scs (unsigned-reg zero immediate) :target result))
185 (:arg-types ,type positive-fixnum positive-fixnum)
186 (:results (result :scs (unsigned-reg)))
187 (:result-types positive-fixnum)
188 (:temporary (:scs (non-descriptor-reg)) temp old)
189 (:temporary (:scs (interior-reg)) lip)
191 (inst srl index ,bit-shift temp)
192 (inst sh2add temp object lip)
193 (loadw old lip vector-data-offset other-pointer-lowtag)
194 (inst zdep index ,(- 32 (integer-length bits)) ,bit-shift temp)
196 `((inst addi ,(1- bits) temp temp)))
197 (inst mtctl temp :sar)
198 (inst dep (sc-case value (immediate (tn-value value)) (t value))
200 (storew old lip vector-data-offset other-pointer-lowtag)
203 (inst li (tn-value value) result))
205 (move value result)))))
206 (define-vop (,(symbolicate 'data-vector-set-c/ type))
207 (:translate data-vector-set)
209 (:args (object :scs (descriptor-reg))
210 (value :scs (unsigned-reg zero immediate) :target result))
215 (:results (result :scs (unsigned-reg)))
216 (:result-types positive-fixnum)
217 (:temporary (:scs (non-descriptor-reg)) old)
218 (:temporary (:scs (interior-reg)) lip)
220 (multiple-value-bind (word extra) (floor index ,elements-per-word)
221 (let ((offset (- (* (+ word vector-data-offset) n-word-bytes)
222 other-pointer-lowtag)))
223 (cond ((typep offset '(signed-byte 14))
224 (inst ldw offset object old))
226 (inst move object lip)
227 (inst addil (ldb (byte 21 11) offset) lip)
228 (inst ldw (ldb (byte 11 0) offset) lip old)))
229 (inst dep (sc-case value
230 (immediate (tn-value value))
232 (+ (* extra ,bits) ,(1- bits))
235 (if (typep offset '(signed-byte 14))
236 (inst stw old offset object)
237 (inst stw old (ldb (byte 11 0) offset) lip)))
240 (inst li (tn-value value) result))
242 (move value result))))))))))
243 (def-small-data-vector-frobs simple-bit-vector 1)
244 (def-small-data-vector-frobs simple-array-unsigned-byte-2 2)
245 (def-small-data-vector-frobs simple-array-unsigned-byte-4 4))
247 ;;; And the float variants.
248 (define-vop (data-vector-ref/simple-array-single-float)
249 (:note "inline array access")
250 (:translate data-vector-ref)
252 (:args (object :scs (descriptor-reg) :to (:argument 1))
253 (index :scs (any-reg) :to (:argument 0) :target offset))
254 (:arg-types simple-array-single-float positive-fixnum)
255 (:results (value :scs (single-reg)))
256 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) offset)
257 (:result-types single-float)
259 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
261 (inst fldx offset object value)))
263 (define-vop (data-vector-set/simple-array-single-float)
264 (:note "inline array store")
265 (:translate data-vector-set)
267 (:args (object :scs (descriptor-reg) :to (:argument 1))
268 (index :scs (any-reg) :to (:argument 0) :target offset)
269 (value :scs (single-reg) :target result))
270 (:arg-types simple-array-single-float positive-fixnum single-float)
271 (:results (result :scs (single-reg)))
272 (:result-types single-float)
273 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) offset)
275 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
277 (inst fstx value offset object)
278 (unless (location= result value)
279 (inst funop :copy value result))))
281 (define-vop (data-vector-ref/simple-array-double-float)
282 (:note "inline array access")
283 (:translate data-vector-ref)
285 (:args (object :scs (descriptor-reg) :to (:argument 1))
286 (index :scs (any-reg) :to (:argument 0) :target offset))
287 (:arg-types simple-array-double-float positive-fixnum)
288 (:results (value :scs (double-reg)))
289 (:result-types double-float)
290 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) offset)
292 (inst sll index 1 offset)
293 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
295 (inst fldx offset object value)))
297 (define-vop (data-vector-set/simple-array-double-float)
298 (:note "inline array store")
299 (:translate data-vector-set)
301 (:args (object :scs (descriptor-reg) :to (:argument 1))
302 (index :scs (any-reg) :to (:argument 0) :target offset)
303 (value :scs (double-reg) :target result))
304 (:arg-types simple-array-double-float positive-fixnum double-float)
305 (:results (result :scs (double-reg)))
306 (:result-types double-float)
307 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) offset)
309 (inst sll index 1 offset)
310 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
312 (inst fstx value offset object)
313 (unless (location= result value)
314 (inst funop :copy value result))))
317 ;;; Complex float arrays.
318 (define-vop (data-vector-ref/simple-array-complex-single-float)
319 (:note "inline array access")
320 (:translate data-vector-ref)
322 (:args (object :scs (descriptor-reg) :to :result)
323 (index :scs (any-reg)))
324 (:arg-types simple-array-complex-single-float positive-fixnum)
325 (:results (value :scs (complex-single-reg)))
326 (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) offset)
327 (:result-types complex-single-float)
329 (inst sll index 1 offset)
330 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
332 (let ((real-tn (complex-single-reg-real-tn value)))
333 (inst fldx offset object real-tn))
334 (let ((imag-tn (complex-single-reg-imag-tn value)))
335 (inst addi n-word-bytes offset offset)
336 (inst fldx offset object imag-tn))))
338 (define-vop (data-vector-set/simple-array-complex-single-float)
339 (:note "inline array store")
340 (:translate data-vector-set)
342 (:args (object :scs (descriptor-reg) :to :result)
343 (index :scs (any-reg))
344 (value :scs (complex-single-reg) :target result))
345 (:arg-types simple-array-complex-single-float positive-fixnum
346 complex-single-float)
347 (:results (result :scs (complex-single-reg)))
348 (:result-types complex-single-float)
349 (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) offset)
351 (inst sll index 1 offset)
352 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
354 (let ((value-real (complex-single-reg-real-tn value))
355 (result-real (complex-single-reg-real-tn result)))
356 (inst fstx value-real offset object)
357 (unless (location= result-real value-real)
358 (inst funop :copy value-real result-real)))
359 (let ((value-imag (complex-single-reg-imag-tn value))
360 (result-imag (complex-single-reg-imag-tn result)))
361 (inst addi n-word-bytes offset offset)
362 (inst fstx value-imag offset object)
363 (unless (location= result-imag value-imag)
364 (inst funop :copy value-imag result-imag)))))
366 (define-vop (data-vector-ref/simple-array-complex-double-float)
367 (:note "inline array access")
368 (:translate data-vector-ref)
370 (:args (object :scs (descriptor-reg) :to :result)
371 (index :scs (any-reg)))
372 (:arg-types simple-array-complex-double-float positive-fixnum)
373 (:results (value :scs (complex-double-reg)))
374 (:result-types complex-double-float)
375 (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) offset)
377 (inst sll index 2 offset)
378 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
380 (let ((real-tn (complex-double-reg-real-tn value)))
381 (inst fldx offset object real-tn))
382 (let ((imag-tn (complex-double-reg-imag-tn value)))
383 (inst addi (* 2 n-word-bytes) offset offset)
384 (inst fldx offset object imag-tn))))
386 (define-vop (data-vector-set/simple-array-complex-double-float)
387 (:note "inline array store")
388 (:translate data-vector-set)
390 (:args (object :scs (descriptor-reg) :to :result)
391 (index :scs (any-reg))
392 (value :scs (complex-double-reg) :target result))
393 (:arg-types simple-array-complex-double-float positive-fixnum
394 complex-double-float)
395 (:results (result :scs (complex-double-reg)))
396 (:result-types complex-double-float)
397 (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) offset)
399 (inst sll index 2 offset)
400 (inst addi (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)
402 (let ((value-real (complex-double-reg-real-tn value))
403 (result-real (complex-double-reg-real-tn result)))
404 (inst fstx value-real offset object)
405 (unless (location= result-real value-real)
406 (inst funop :copy value-real result-real)))
407 (let ((value-imag (complex-double-reg-imag-tn value))
408 (result-imag (complex-double-reg-imag-tn result)))
409 (inst addi (* 2 n-word-bytes) offset offset)
410 (inst fstx value-imag offset object)
411 (unless (location= result-imag value-imag)
412 (inst funop :copy value-imag result-imag)))))
415 ;;; These VOPs are used for implementing float slots in structures (whose raw
416 ;;; data is an unsigned-32 vector.
417 (define-vop (raw-ref-single data-vector-ref/simple-array-single-float)
418 (:translate %raw-ref-single)
419 (:arg-types sb!c::raw-vector positive-fixnum))
420 (define-vop (raw-set-single data-vector-set/simple-array-single-float)
421 (:translate %raw-set-single)
422 (:arg-types sb!c::raw-vector positive-fixnum single-float))
423 (define-vop (raw-ref-double data-vector-ref/simple-array-double-float)
424 (:translate %raw-ref-double)
425 (:arg-types sb!c::raw-vector positive-fixnum))
426 (define-vop (raw-set-double data-vector-set/simple-array-double-float)
427 (:translate %raw-set-double)
428 (:arg-types sb!c::raw-vector positive-fixnum double-float))
429 (define-vop (raw-ref-complex-single
430 data-vector-ref/simple-array-complex-single-float)
431 (:translate %raw-ref-complex-single)
432 (:arg-types sb!c::raw-vector positive-fixnum))
433 (define-vop (raw-set-complex-single
434 data-vector-set/simple-array-complex-single-float)
435 (:translate %raw-set-complex-single)
436 (:arg-types sb!c::raw-vector positive-fixnum complex-single-float))
437 (define-vop (raw-ref-complex-double
438 data-vector-ref/simple-array-complex-double-float)
439 (:translate %raw-ref-complex-double)
440 (:arg-types sb!c::raw-vector positive-fixnum))
441 (define-vop (raw-set-complex-double
442 data-vector-set/simple-array-complex-double-float)
443 (:translate %raw-set-complex-double)
444 (:arg-types sb!c::raw-vector positive-fixnum complex-double-float))
446 ;;; These vops are useful for accessing the bits of a vector irrespective of
447 ;;; what type of vector it is.
448 (define-full-reffer raw-bits * 0 other-pointer-lowtag (unsigned-reg) unsigned-num
450 (define-full-setter set-raw-bits * 0 other-pointer-lowtag (unsigned-reg)
451 unsigned-num %set-raw-bits)
452 (define-full-reffer vector-raw-bits * vector-data-offset other-pointer-lowtag
453 (unsigned-reg) unsigned-num %vector-raw-bits)
454 (define-full-setter set-vector-raw-bits * vector-data-offset other-pointer-lowtag
455 (unsigned-reg) unsigned-num %set-vector-raw-bits)
457 ;;;; Misc. Array VOPs.
458 (define-vop (get-vector-subtype get-header-data))
459 (define-vop (set-vector-subtype set-header-data))