/[cmucl]/src/compiler/array-tran.lisp
ViewVC logotype

Contents of /src/compiler/array-tran.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.40.10.2 - (show annotations)
Sat Jun 17 02:59:42 2006 UTC (7 years, 10 months ago) by rtoy
Branch: double-double-array-branch
Changes since 1.40.10.1: +2 -2 lines
Initial support for (complex double-double-float).

Use boot-2006-06-2-cross-dd* to cross compile this change (along with
the simple-array double-double-float change).
1 ;;; -*- Package: C; Log: C.Log -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;;
7 (ext:file-comment
8 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/array-tran.lisp,v 1.40.10.2 2006/06/17 02:59:42 rtoy Exp $")
9 ;;;
10 ;;; **********************************************************************
11 ;;;
12 ;;; This file contains array specific optimizers and transforms.
13 ;;;
14 ;;; Extracted from srctran and extended by William Lott.
15 ;;;
16 (in-package "C")
17
18
19 ;;;; Derive-Type Optimizers
20
21 ;;; ASSERT-ARRAY-RANK -- internal
22 ;;;
23 ;;; Array operations that use a specific number of indices implicitly assert
24 ;;; that the array is of that rank.
25 ;;;
26 (defun assert-array-rank (array rank)
27 (assert-continuation-type
28 array
29 (specifier-type `(array * ,(make-list rank :initial-element '*)))))
30
31 ;;; EXTRACT-ELEMENT-TYPE -- internal
32 ;;;
33 ;;; Array access functions return an object from the array, hence it's
34 ;;; type will be asserted to be array element type.
35 ;;;
36 (defun extract-element-type (array)
37 (let ((type (continuation-type array)))
38 (if (array-type-p type)
39 (array-type-element-type type)
40 *universal-type*)))
41
42 ;;; EXTRACT-UPGRADED-ELEMENT-TYPE -- internal
43 ;;;
44 ;;; Array access functions return an object from the array, hence it's
45 ;;; type is going to be the array upgraded element type.
46 ;;;
47 (defun extract-upgraded-element-type (array)
48 (let ((type (continuation-type array)))
49 (if (array-type-p type)
50 (array-type-specialized-element-type type)
51 *universal-type*)))
52
53 ;;; ASSERT-NEW-VALUE-TYPE -- internal
54 ;;;
55 ;;; The ``new-value'' for array setters must fit in the array, and the
56 ;;; return type is going to be the same as the new-value for setf functions.
57 ;;;
58 (defun assert-new-value-type (new-value array)
59 (let ((type (continuation-type array)))
60 (when (array-type-p type)
61 (assert-continuation-optional-type new-value
62 (array-type-specialized-element-type type))))
63 (continuation-type new-value))
64
65 ;;; Unsupplied-Or-NIL -- Internal
66 ;;;
67 ;;; Return true if Arg is NIL, or is a constant-continuation whose value is
68 ;;; NIL, false otherwise.
69 ;;;
70 (defun unsupplied-or-nil (arg)
71 (declare (type (or continuation null) arg))
72 (or (not arg)
73 (and (constant-continuation-p arg)
74 (not (continuation-value arg)))))
75
76
77 ;;; ARRAY-IN-BOUNDS-P -- derive-type optimizer.
78 ;;;
79 (defoptimizer (array-in-bounds-p derive-type) ((array &rest indices))
80 (assert-array-rank array (length indices))
81 *universal-type*)
82
83 ;;; AREF -- derive-type optimizer.
84 ;;;
85 (defoptimizer (aref derive-type) ((array &rest indices) node)
86 (assert-array-rank array (length indices))
87 ;; If the node continuation has a single use then assert its type.
88 ;;
89 ;; Let's not do this. As reported by Lynn Quam on cmucl-imp on
90 ;; 2004-03-30, the compiler generates bogus code for
91 ;;
92 ;; (defun foo (f d)
93 ;; (declare (type (simple-array single-float (*)) f)
94 ;; (type (simple-array double-float (*)) d))
95 ;; (setf (aref f 0) (aref d 0)))
96 ;;
97 ;; and doesn't even warn about the type mismatch. This might be a
98 ;; symptom of other compiler bugs, but removing this at least gives
99 ;; us back the warning. I (RLT) do not know what impact removing
100 ;; this has on other user code.
101 #+(or)
102 (let ((cont (node-cont node)))
103 (when (= (length (find-uses cont)) 1)
104 (assert-continuation-type cont (extract-upgraded-element-type array))))
105 (extract-upgraded-element-type array))
106
107 ;;; %ASET -- derive-type optimizer.
108 ;;;
109 (defoptimizer (%aset derive-type) ((array &rest stuff))
110 (assert-array-rank array (1- (length stuff)))
111 (assert-new-value-type (car (last stuff)) array)
112 ;; Without the following, this function
113 ;;
114 ;; (defun fn-492 (r p1)
115 ;; (declare (optimize speed (safety 1))
116 ;; (type (simple-array (signed-byte 8) nil) r) (type (integer * 22050378) p1))
117 ;; (setf (aref r) (lognand (the (integer 19464371) p1) 2257))
118 ;; (values))
119 ;; (defun tst-492 ()
120 ;; (let ((r (make-array nil :element-type '(signed-byte 8))))
121 ;; (fn-492 r 19469591)
122 ;; (aref r)))
123 ;;
124 ;; causes the compiler to delete (values) as unreachable and in so
125 ;; doing, deletes the return, so we just run off the end. I (rtoy)
126 ;; think this is caused by some confusion in type-derivation. The
127 ;; derived result of the lognand is bigger than a (signed-byte 8).
128 ;;
129 ;; I think doing this also causes some loss, because we return the
130 ;; element-type of the array, even though the result of the aset is
131 ;; the new value. Well, almost. The element type is returned only
132 ;; if the array continuation is really an array type. Otherwise, we
133 ;; do return the type of the new value.
134 ;;
135 ;; FIXME: This needs something better, but I (rtoy) am not smart
136 ;; enough to know what to do about it.
137 (let ((atype (continuation-type array)))
138 (if (array-type-p atype)
139 (array-type-specialized-element-type atype)
140 (continuation-type (car (last stuff))))))
141
142 ;;; DATA-VECTOR-REF -- derive-type optimizer.
143 ;;;
144 (defoptimizer (data-vector-ref derive-type) ((array index))
145 (extract-upgraded-element-type array))
146
147 ;;; DATA-VECTOR-SET -- derive-type optimizer.
148 ;;;
149 (defoptimizer (data-vector-set derive-type) ((array index new-value))
150 (assert-new-value-type new-value array))
151
152 ;;; %WITH-ARRAY-DATA -- derive-type optimizer.
153 ;;;
154 ;;; Figure out the type of the data vector if we know the argument element
155 ;;; type.
156 ;;;
157 (defoptimizer (%with-array-data derive-type) ((array start end))
158 (let ((atype (continuation-type array)))
159 (when (array-type-p atype)
160 (values-specifier-type
161 `(values (simple-array ,(type-specifier
162 (array-type-element-type atype))
163 (*))
164 index index index)))))
165
166
167 ;;; ARRAY-ROW-MAJOR-INDEX -- derive-type optimizer.
168 ;;;
169 (defoptimizer (array-row-major-index derive-type) ((array &rest indices))
170 (assert-array-rank array (length indices))
171 *universal-type*)
172
173 ;;; ROW-MAJOR-AREF -- derive-type optimizer.
174 ;;;
175 (defoptimizer (row-major-aref derive-type) ((array index))
176 (extract-upgraded-element-type array))
177
178 ;;; %SET-ROW-MAJOR-AREF -- derive-type optimizer.
179 ;;;
180 (defoptimizer (%set-row-major-aref derive-type) ((array index new-value))
181 (assert-new-value-type new-value array))
182
183 ;;; MAKE-ARRAY -- derive-type optimizer.
184 ;;;
185 (defoptimizer (make-array derive-type)
186 ((dims &key initial-element element-type initial-contents
187 adjustable fill-pointer displaced-index-offset displaced-to))
188 (let ((simple (and (unsupplied-or-nil adjustable)
189 (unsupplied-or-nil displaced-to)
190 (unsupplied-or-nil fill-pointer))))
191 (specifier-type
192 `(,(if simple 'simple-array 'array)
193 ,(cond ((not element-type) 't)
194 ((constant-continuation-p element-type)
195 (continuation-value element-type))
196 (t
197 '*))
198 ,(cond ((not simple)
199 '*)
200 ((constant-continuation-p dims)
201 (let ((val (continuation-value dims)))
202 (if (listp val) val (list val))))
203 ((csubtypep (continuation-type dims)
204 (specifier-type 'integer))
205 '(*))
206 (t
207 '*))))))
208
209
210 ;;;; Constructors.
211
212 ;;; VECTOR -- source-transform.
213 ;;;
214 ;;; Convert VECTOR into a make-array followed by setfs of all the elements.
215 ;;;
216 (def-source-transform vector (&rest elements)
217 (if (byte-compiling)
218 (values nil t)
219 (let ((len (length elements))
220 (n -1))
221 (once-only ((n-vec `(make-array ,len)))
222 `(progn
223 ,@(mapcar #'(lambda (el)
224 (once-only ((n-val el))
225 `(locally (declare (optimize (safety 0)))
226 (setf (svref ,n-vec ,(incf n))
227 ,n-val))))
228 elements)
229 ,n-vec)))))
230
231
232 ;;; MAKE-STRING -- source-transform.
233 ;;;
234 ;;; Just convert it into a make-array.
235 ;;;
236 (deftransform make-string ((length &key (element-type 'base-char)
237 (initial-element #\NULL)))
238 `(make-array (the (values index &rest t) length)
239 :element-type element-type
240 :initial-element initial-element))
241
242 (defconstant array-info
243 '((base-char #\NULL 8 vm:simple-string-type)
244 (single-float 0.0f0 32 vm:simple-array-single-float-type)
245 (double-float 0.0d0 64 vm:simple-array-double-float-type)
246 #+long-float (long-float 0.0l0 #+x86 96 #+sparc 128
247 vm:simple-array-long-float-type)
248 #+double-double
249 (double-double-float 0w0 128
250 vm::simple-array-double-double-float-type)
251 (bit 0 1 vm:simple-bit-vector-type)
252 ((unsigned-byte 2) 0 2 vm:simple-array-unsigned-byte-2-type)
253 ((unsigned-byte 4) 0 4 vm:simple-array-unsigned-byte-4-type)
254 ((unsigned-byte 8) 0 8 vm:simple-array-unsigned-byte-8-type)
255 ((unsigned-byte 16) 0 16 vm:simple-array-unsigned-byte-16-type)
256 ((unsigned-byte 32) 0 32 vm:simple-array-unsigned-byte-32-type)
257 ((signed-byte 8) 0 8 vm:simple-array-signed-byte-8-type)
258 ((signed-byte 16) 0 16 vm:simple-array-signed-byte-16-type)
259 ((signed-byte 30) 0 32 vm:simple-array-signed-byte-30-type)
260 ((signed-byte 32) 0 32 vm:simple-array-signed-byte-32-type)
261 ((complex single-float) #C(0.0f0 0.0f0) 64
262 vm:simple-array-complex-single-float-type)
263 ((complex double-float) #C(0.0d0 0.0d0) 128
264 vm:simple-array-complex-double-float-type)
265 #+long-float
266 ((complex long-float) #C(0.0l0 0.0l0) #+x86 192 #+sparc 256
267 vm:simple-array-complex-long-float-type)
268 (t 0 32 vm:simple-vector-type)))
269
270 ;;; MAKE-ARRAY -- source-transform.
271 ;;;
272 ;;; The integer type restriction on the length assures that it will be a
273 ;;; vector. The lack of adjustable, fill-pointer, and displaced-to keywords
274 ;;; assures that it will be simple.
275 ;;;
276 (deftransform make-array ((length &key initial-element element-type)
277 (integer &rest *))
278 (let* ((eltype (cond ((not element-type) t)
279 ((not (constant-continuation-p element-type))
280 (give-up "Element-Type is not constant."))
281 (t
282 (continuation-value element-type))))
283 (len (if (constant-continuation-p length)
284 (continuation-value length)
285 '*))
286 (spec `(simple-array ,eltype (,len)))
287 (eltype-type (specifier-type eltype)))
288 (multiple-value-bind
289 (default-initial-element element-size typecode)
290 (dolist (info array-info
291 (give-up "Cannot open-code creation of ~S" spec))
292 (when (csubtypep eltype-type (specifier-type (car info)))
293 (return (values-list (cdr info)))))
294 (let* ((nwords-form
295 (if (>= element-size vm:word-bits)
296 `(* length ,(/ element-size vm:word-bits))
297 (let ((elements-per-word (/ 32 element-size)))
298 `(truncate (+ length
299 ,(if (eq 'vm:simple-string-type typecode)
300 elements-per-word
301 (1- elements-per-word)))
302 ,elements-per-word))))
303 (constructor
304 `(truly-the ,spec
305 (allocate-vector ,typecode length ,nwords-form))))
306 (values
307 (cond ((and default-initial-element
308 (or (null initial-element)
309 (and (constant-continuation-p initial-element)
310 (eql (continuation-value initial-element)
311 default-initial-element))))
312 (unless (csubtypep (ctype-of default-initial-element)
313 eltype-type)
314 (compiler-note "Default initial element ~s is not a ~s."
315 default-initial-element eltype))
316 constructor)
317 (t
318 `(truly-the ,spec (fill ,constructor initial-element))))
319 '((declare (type index length))))))))
320
321 ;;; MAKE-ARRAY -- transform.
322 ;;;
323 ;;; The list type restriction does not assure that the result will be a
324 ;;; multi-dimensional array. But the lack of
325 ;;;
326 (deftransform make-array ((dims &key initial-element element-type)
327 (list &rest *))
328 (unless (or (null element-type) (constant-continuation-p element-type))
329 (give-up "Element-type not constant; cannot open code array creation"))
330 (unless (constant-continuation-p dims)
331 (give-up "Dimension list not constant; cannot open code array creation"))
332 (let ((dims (continuation-value dims)))
333 (unless (every #'integerp dims)
334 (give-up "Dimension list contains something other than an integer: ~S"
335 dims))
336 (if (= (length dims) 1)
337 `(make-array ',(car dims)
338 ,@(when initial-element
339 '(:initial-element initial-element))
340 ,@(when element-type
341 '(:element-type element-type)))
342 (let* ((total-size (reduce #'* dims))
343 (rank (length dims))
344 (spec `(simple-array
345 ,(cond ((null element-type) t)
346 ((constant-continuation-p element-type)
347 (continuation-value element-type))
348 (t '*))
349 ,(make-list rank :initial-element '*))))
350 `(let ((header (make-array-header vm:simple-array-type ,rank)))
351 (setf (%array-fill-pointer header) ,total-size)
352 (setf (%array-fill-pointer-p header) nil)
353 (setf (%array-available-elements header) ,total-size)
354 (setf (%array-data-vector header)
355 (make-array ,total-size
356 ,@(when element-type
357 '(:element-type element-type))
358 ,@(when initial-element
359 '(:initial-element initial-element))))
360 (setf (%array-displaced-p header) nil)
361 ,@(let ((axis -1))
362 (mapcar #'(lambda (dim)
363 `(setf (%array-dimension header ,(incf axis))
364 ,dim))
365 dims))
366 (truly-the ,spec header))))))
367
368
369 ;;;; Random properties of arrays.
370
371 ;;; Transforms for various random array properties. If the property is know
372 ;;; at compile time because of a type spec, use that constant value.
373
374 ;;; ARRAY-RANK -- transform.
375 ;;;
376 ;;; If we can tell the rank from the type info, use it instead.
377 ;;;
378 (deftransform array-rank ((array))
379 (let ((array-type (continuation-type array)))
380 (unless (array-type-p array-type)
381 (give-up))
382 (let ((dims (array-type-dimensions array-type)))
383 (if (not (listp dims))
384 (give-up "Array rank not known at compile time: ~S" dims)
385 (length dims)))))
386
387 ;;; ARRAY-DIMENSION -- transform.
388 ;;;
389 ;;; If we know the dimensions at compile time, just use it. Otherwise, if
390 ;;; we can tell that the axis is in bounds, convert to %array-dimension
391 ;;; (which just indirects the array header) or length (if it's simple and a
392 ;;; vector).
393 ;;;
394 (deftransform array-dimension ((array axis)
395 (array index))
396 (unless (constant-continuation-p axis)
397 (give-up "Axis not constant."))
398 (let ((array-type (continuation-type array))
399 (axis (continuation-value axis)))
400 (unless (array-type-p array-type)
401 (give-up))
402 (let ((dims (array-type-dimensions array-type)))
403 (unless (listp dims)
404 (give-up
405 "Array dimensions unknown, must call array-dimension at runtime."))
406 (unless (> (length dims) axis)
407 (abort-transform "Array has dimensions ~S, ~D is too large."
408 dims axis))
409 (let ((dim (nth axis dims)))
410 (cond ((integerp dim)
411 dim)
412 ((= (length dims) 1)
413 (ecase (array-type-complexp array-type)
414 ((t)
415 '(%array-dimension array 0))
416 ((nil)
417 '(length array))
418 ((:maybe *)
419 (give-up "Can't tell if array is simple."))))
420 (t
421 '(%array-dimension array axis)))))))
422
423 ;;; LENGTH -- transform.
424 ;;;
425 ;;; If the length has been declared and it's simple, just return it.
426 ;;;
427 (deftransform length ((vector)
428 ((simple-array * (*))))
429 (let ((type (continuation-type vector)))
430 (unless (array-type-p type)
431 (give-up))
432 (let ((dims (array-type-dimensions type)))
433 (unless (and (listp dims) (integerp (car dims)))
434 (give-up "Vector length unknown, must call length at runtime."))
435 (car dims))))
436
437 ;;; LENGTH -- transform.
438 ;;;
439 ;;; All vectors can get their length by using vector-length. If it's simple,
440 ;;; it will extract the length slot from the vector. It it's complex, it will
441 ;;; extract the fill pointer slot from the array header.
442 ;;;
443 (deftransform length ((vector) (vector))
444 '(vector-length vector))
445
446
447 ;;; If a simple array with known dimensions, then vector-length is a
448 ;;; compile-time constant.
449 ;;;
450 (deftransform vector-length ((vector) ((simple-array * (*))))
451 (let ((vtype (continuation-type vector)))
452 (if (array-type-p vtype)
453 (let ((dim (first (array-type-dimensions vtype))))
454 (when (eq dim '*) (give-up))
455 dim)
456 (give-up))))
457
458
459 ;;; ARRAY-TOTAL-SIZE -- transform.
460 ;;;
461 ;;; Again, if we can tell the results from the type, just use it. Otherwise,
462 ;;; if we know the rank, convert into a computation based on array-dimension.
463 ;;; We can wrap a truly-the index around the multiplications because we know
464 ;;; that the total size must be an index.
465 ;;;
466 (deftransform array-total-size ((array)
467 (array))
468 (let ((array-type (continuation-type array)))
469 (unless (array-type-p array-type)
470 (give-up))
471 (let ((dims (array-type-dimensions array-type)))
472 (unless (listp dims)
473 (give-up "Can't tell the rank at compile time."))
474 (if (member '* dims)
475 (do ((form 1 `(truly-the index
476 (* (array-dimension array ,i) ,form)))
477 (i 0 (1+ i)))
478 ((= i (length dims)) form))
479 (reduce #'* dims)))))
480
481 ;;; ARRAY-HAS-FILL-POINTER-P -- transform.
482 ;;;
483 ;;; Only complex vectors have fill pointers.
484 ;;;
485 (deftransform array-has-fill-pointer-p ((array))
486 (let ((array-type (continuation-type array)))
487 (unless (array-type-p array-type)
488 (give-up))
489 (let ((dims (array-type-dimensions array-type)))
490 (if (and (listp dims) (not (= (length dims) 1)))
491 nil
492 (ecase (array-type-complexp array-type)
493 ((t)
494 t)
495 ((nil)
496 nil)
497 (:maybe
498 (give-up "Array type ambiguous; must call ~
499 array-has-fill-pointer-p at runtime.")))))))
500
501 ;;; %CHECK-BOUND -- transform.
502 ;;;
503 ;;; Primitive used to verify indicies into arrays. If we can tell at
504 ;;; compile-time or we are generating unsafe code, don't bother with the VOP.
505 ;;;
506 (deftransform %check-bound ((array dimension index))
507 (unless (constant-continuation-p dimension)
508 (give-up))
509 (let ((dim (continuation-value dimension)))
510 `(the (integer 0 (,dim)) index)))
511 ;;;
512 (deftransform %check-bound ((array dimension index) * *
513 :policy (and (> speed safety) (= safety 0)))
514 'index)
515
516
517 ;;; WITH-ROW-MAJOR-INDEX -- internal.
518 ;;;
519 ;;; Handy macro for computing the row-major index given a set of indices. We
520 ;;; wrap each index with a call to %check-bound to assure that everything
521 ;;; works out correctly. We can wrap all the interior arith with truly-the
522 ;;; index because we know the the resultant row-major index must be an index.
523 ;;;
524 (eval-when (compile eval)
525 ;;;
526 (defmacro with-row-major-index ((array indices index &optional new-value)
527 &rest body)
528 `(let (n-indices dims)
529 (dotimes (i (length ,indices))
530 (push (make-symbol (format nil "INDEX-~D" i)) n-indices)
531 (push (make-symbol (format nil "DIM-~D" i)) dims))
532 (setf n-indices (nreverse n-indices))
533 (setf dims (nreverse dims))
534 `(lambda (,',array ,@n-indices ,@',(when new-value (list new-value)))
535 (let* (,@(let ((,index -1))
536 (mapcar #'(lambda (name)
537 `(,name (array-dimension ,',array
538 ,(incf ,index))))
539 dims))
540 (,',index
541 ,(if (null dims)
542 0
543 (do* ((dims dims (cdr dims))
544 (indices n-indices (cdr indices))
545 (last-dim nil (car dims))
546 (form `(%check-bound ,',array
547 ,(car dims)
548 ,(car indices))
549 `(truly-the index
550 (+ (truly-the index
551 (* ,form
552 ,last-dim))
553 (%check-bound
554 ,',array
555 ,(car dims)
556 ,(car indices))))))
557 ((null (cdr dims)) form)))))
558 ,',@body))))
559 ;;;
560 ); eval-when
561
562 ;;; ARRAY-ROW-MAJOR-INDEX -- transform.
563 ;;;
564 ;;; Just return the index after computing it.
565 ;;;
566 (deftransform array-row-major-index ((array &rest indices))
567 (with-row-major-index (array indices index)
568 index))
569
570
571
572 ;;;; Array accessors:
573
574 ;;; SVREF, %SVSET, SCHAR, %SCHARSET, CHAR,
575 ;;; %CHARSET, SBIT, %SBITSET, BIT, %BITSET
576 ;;; -- source transforms.
577 ;;;
578 ;;; We convert all typed array accessors into aref and %aset with type
579 ;;; assertions on the array.
580 ;;;
581 (macrolet ((frob (reffer setter type)
582 `(progn
583 (def-source-transform ,reffer (a &rest i)
584 (if (byte-compiling)
585 (values nil t)
586 `(aref (the ,',type ,a) ,@i)))
587 (def-source-transform ,setter (a &rest i)
588 (if (byte-compiling)
589 (values nil t)
590 `(%aset (the ,',type ,a) ,@i))))))
591 (frob sbit %sbitset (simple-array bit))
592 (frob bit %bitset (array bit)))
593
594 (macrolet ((frob (reffer setter type)
595 `(progn
596 (def-source-transform ,reffer (a i)
597 (if (byte-compiling)
598 (values nil t)
599 `(aref (the ,',type ,a) ,i)))
600 (def-source-transform ,setter (a i v)
601 (if (byte-compiling)
602 (values nil t)
603 `(%aset (the ,',type ,a) ,i ,v))))))
604 (frob svref %svset simple-vector)
605 (frob schar %scharset simple-string)
606 (frob char %charset string))
607
608 ;;; AREF, %ASET -- transform.
609 ;;;
610 ;;; Convert into a data-vector-ref (or set) with the set of indices replaced
611 ;;; with the an expression for the row major index.
612 ;;;
613 (deftransform aref ((array &rest indices))
614 (with-row-major-index (array indices index)
615 (data-vector-ref array index)))
616 ;;;
617 (deftransform %aset ((array &rest stuff))
618 (let ((indices (butlast stuff)))
619 (with-row-major-index (array indices index new-value)
620 (data-vector-set array index new-value))))
621
622 ;;; ROW-MAJOR-AREF, %SET-ROW-MAJOR-AREF -- transform.
623 ;;;
624 ;;; Just convert into a data-vector-ref (or set) after checking that the
625 ;;; index is inside the array total size.
626 ;;;
627 (deftransform row-major-aref ((array index))
628 `(data-vector-ref array (%check-bound array (array-total-size array) index)))
629 ;;;
630 (deftransform %set-row-major-aref ((array index new-value))
631 `(data-vector-set array
632 (%check-bound array (array-total-size array) index)
633 new-value))
634
635
636 ;;;; Bit-vector array operation canonicalization:
637 ;;;
638 ;;; We convert all bit-vector operations to have the result array specified.
639 ;;; This allows any result allocation to be open-coded, and eliminates the need
640 ;;; for any VM-dependent transforms to handle these cases.
641
642 (dolist (fun '(bit-and bit-ior bit-xor bit-eqv bit-nand bit-nor bit-andc1
643 bit-andc2 bit-orc1 bit-orc2))
644 ;;
645 ;; Make a result array if result is NIL or unsupplied.
646 (deftransform fun ((bit-array-1 bit-array-2 &optional result-bit-array)
647 '(bit-vector bit-vector &optional null) '*
648 :eval-name t :policy (>= speed space))
649 `(,fun bit-array-1 bit-array-2
650 (make-array (array-dimension bit-array-1 0) :element-type 'bit)))
651 ;;
652 ;; If result its T, make it the first arg.
653 (deftransform fun ((bit-array-1 bit-array-2 result-bit-array)
654 '(bit-vector bit-vector (member t)) '*
655 :eval-name t)
656 `(,fun bit-array-1 bit-array-2 bit-array-1)))
657
658 ;;; Similar for BIT-NOT, but there is only one arg...
659 ;;;
660 (deftransform bit-not ((bit-array-1 &optional result-bit-array)
661 (bit-vector &optional null) *
662 :policy (>= speed space))
663 '(bit-not bit-array-1
664 (make-array (length bit-array-1) :element-type 'bit)))
665 ;;;
666 (deftransform bit-not ((bit-array-1 result-bit-array)
667 (bit-vector (constant-argument t)))
668 '(bit-not bit-array-1 bit-array-1))
669
670
671 ;;; ARRAY-HEADER-P -- transform.
672 ;;;
673 ;;; Pick off some constant cases.
674 ;;;
675 (deftransform array-header-p ((array) (array))
676 (let ((type (continuation-type array)))
677 (declare (optimize (safety 3)))
678 (unless (array-type-p type)
679 (give-up))
680 (let ((dims (array-type-dimensions type)))
681 (cond ((csubtypep type (specifier-type '(simple-array * (*))))
682 ;; No array header.
683 nil)
684 ((and (listp dims) (> (length dims) 1))
685 ;; Multi-dimensional array, will have a header.
686 t)
687 (t
688 (give-up))))))

  ViewVC Help
Powered by ViewVC 1.1.5