/[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.41 - (hide annotations)
Fri Jun 30 18:41:23 2006 UTC (7 years, 9 months ago) by rtoy
Branch: MAIN
CVS Tags: snapshot-2007-09, snapshot-2007-08, snapshot-2007-05, snapshot-2008-01, snapshot-2008-02, snapshot-2008-03, snapshot-2006-11, snapshot-2006-10, snapshot-2006-12, snapshot-2007-01, snapshot-2007-02, release-19e, release-19d, snapshot-2007-03, snapshot-2007-04, snapshot-2007-07, snapshot-2007-06, release-19d-base, release-19e-pre1, release-19e-pre2, release-19d-pre2, release-19d-pre1, release-19e-base, snapshot-2007-12, snapshot-2007-10, snapshot-2007-11, snapshot-2006-07, pre-telent-clx, snapshot-2006-08, snapshot-2006-09
Branch point for: release-19d-branch, release-19e-branch
Changes since 1.40: +7 -1 lines
This large checkin merges the double-double float support to HEAD.
The merge is from the tag "double-double-irrat-end".  The
double-double branch is now obsolete.

The code should build without double-double support (tested on sparc)
as well as build with double-double support (tested also on sparc).
1 wlott 1.1 ;;; -*- Package: C; Log: C.Log -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.9 ;;; 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 rtoy 1.41 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/array-tran.lisp,v 1.41 2006/06/30 18:41:23 rtoy Exp $")
9 ram 1.9 ;;;
10 wlott 1.1 ;;; **********************************************************************
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 wlott 1.3 ;;; ASSERT-ARRAY-RANK -- internal
22 wlott 1.1 ;;;
23     ;;; Array operations that use a specific number of indices implicitly assert
24     ;;; that the array is of that rank.
25     ;;;
26 wlott 1.3 (defun assert-array-rank (array rank)
27     (assert-continuation-type
28 wlott 1.1 array
29     (specifier-type `(array * ,(make-list rank :initial-element '*)))))
30    
31     ;;; EXTRACT-ELEMENT-TYPE -- internal
32     ;;;
33 dtc 1.23 ;;; Array access functions return an object from the array, hence it's
34     ;;; type will be asserted to be array element type.
35 wlott 1.1 ;;;
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 dtc 1.23 ;;; 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 wlott 1.1 ;;; 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 dtc 1.28 (assert-continuation-optional-type new-value
62 toy 1.29 (array-type-specialized-element-type type))))
63 wlott 1.1 (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 dtc 1.23 (defoptimizer (aref derive-type) ((array &rest indices) node)
86 wlott 1.4 (assert-array-rank array (length indices))
87 dtc 1.23 ;; If the node continuation has a single use then assert its type.
88 rtoy 1.35 ;;
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 dtc 1.23 (let ((cont (node-cont node)))
103 dtc 1.25 (when (= (length (find-uses cont)) 1)
104 toy 1.29 (assert-continuation-type cont (extract-upgraded-element-type array))))
105 dtc 1.23 (extract-upgraded-element-type array))
106 wlott 1.1
107     ;;; %ASET -- derive-type optimizer.
108     ;;;
109     (defoptimizer (%aset derive-type) ((array &rest stuff))
110     (assert-array-rank array (1- (length stuff)))
111 rtoy 1.37 (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 rtoy 1.38 ;; (defun tst-492 ()
120     ;; (let ((r (make-array nil :element-type '(signed-byte 8))))
121     ;; (fn-492 r 19469591)
122     ;; (aref r)))
123 rtoy 1.37 ;;
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 rtoy 1.38 ;; 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 wlott 1.1
142     ;;; DATA-VECTOR-REF -- derive-type optimizer.
143     ;;;
144     (defoptimizer (data-vector-ref derive-type) ((array index))
145 dtc 1.23 (extract-upgraded-element-type array))
146 wlott 1.1
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 ram 1.10
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 wlott 1.1
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 dtc 1.23 (extract-upgraded-element-type array))
177 wlott 1.1
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 wlott 1.11 (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 wlott 1.1
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 ram 1.16 (if (byte-compiling)
218 ram 1.15 (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 wlott 1.1
231    
232     ;;; MAKE-STRING -- source-transform.
233     ;;;
234     ;;; Just convert it into a make-array.
235     ;;;
236 gerd 1.31 (deftransform make-string ((length &key (element-type 'base-char)
237 gerd 1.30 (initial-element #\NULL)))
238     `(make-array (the (values index &rest t) length)
239     :element-type element-type
240     :initial-element initial-element))
241 wlott 1.1
242     (defconstant array-info
243 wlott 1.12 '((base-char #\NULL 8 vm:simple-string-type)
244 rtoy 1.36 (single-float 0.0f0 32 vm:simple-array-single-float-type)
245 wlott 1.1 (double-float 0.0d0 64 vm:simple-array-double-float-type)
246 dtc 1.26 #+long-float (long-float 0.0l0 #+x86 96 #+sparc 128
247     vm:simple-array-long-float-type)
248 rtoy 1.41 #+double-double
249     (double-double-float 0w0 128
250     vm::simple-array-double-double-float-type)
251 wlott 1.1 (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 dtc 1.27 ((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 rtoy 1.36 ((complex single-float) #C(0.0f0 0.0f0) 64
262 dtc 1.27 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 dtc 1.26 ((complex long-float) #C(0.0l0 0.0l0) #+x86 192 #+sparc 256
267     vm:simple-array-complex-long-float-type)
268 rtoy 1.41 #+double-double
269     ((complex double-double-float) #C(0.0w0 0.0w0) 256
270     vm::simple-array-complex-double-double-float-type)
271 wlott 1.1 (t 0 32 vm:simple-vector-type)))
272    
273     ;;; MAKE-ARRAY -- source-transform.
274     ;;;
275     ;;; The integer type restriction on the length assures that it will be a
276     ;;; vector. The lack of adjustable, fill-pointer, and displaced-to keywords
277     ;;; assures that it will be simple.
278     ;;;
279     (deftransform make-array ((length &key initial-element element-type)
280     (integer &rest *))
281     (let* ((eltype (cond ((not element-type) t)
282     ((not (constant-continuation-p element-type))
283     (give-up "Element-Type is not constant."))
284     (t
285     (continuation-value element-type))))
286     (len (if (constant-continuation-p length)
287     (continuation-value length)
288     '*))
289     (spec `(simple-array ,eltype (,len)))
290     (eltype-type (specifier-type eltype)))
291     (multiple-value-bind
292     (default-initial-element element-size typecode)
293     (dolist (info array-info
294     (give-up "Cannot open-code creation of ~S" spec))
295     (when (csubtypep eltype-type (specifier-type (car info)))
296     (return (values-list (cdr info)))))
297 wlott 1.6 (let* ((nwords-form
298     (if (>= element-size vm:word-bits)
299     `(* length ,(/ element-size vm:word-bits))
300     (let ((elements-per-word (/ 32 element-size)))
301     `(truncate (+ length
302     ,(if (eq 'vm:simple-string-type typecode)
303     elements-per-word
304     (1- elements-per-word)))
305     ,elements-per-word))))
306     (constructor
307     `(truly-the ,spec
308     (allocate-vector ,typecode length ,nwords-form))))
309 wlott 1.1 (values
310 dtc 1.22 (cond ((and default-initial-element
311     (or (null initial-element)
312     (and (constant-continuation-p initial-element)
313     (eql (continuation-value initial-element)
314     default-initial-element))))
315     (unless (csubtypep (ctype-of default-initial-element)
316     eltype-type)
317     (compiler-note "Default initial element ~s is not a ~s."
318     default-initial-element eltype))
319     constructor)
320     (t
321     `(truly-the ,spec (fill ,constructor initial-element))))
322 wlott 1.1 '((declare (type index length))))))))
323    
324     ;;; MAKE-ARRAY -- transform.
325     ;;;
326     ;;; The list type restriction does not assure that the result will be a
327     ;;; multi-dimensional array. But the lack of
328     ;;;
329     (deftransform make-array ((dims &key initial-element element-type)
330     (list &rest *))
331     (unless (or (null element-type) (constant-continuation-p element-type))
332     (give-up "Element-type not constant; cannot open code array creation"))
333     (unless (constant-continuation-p dims)
334     (give-up "Dimension list not constant; cannot open code array creation"))
335     (let ((dims (continuation-value dims)))
336     (unless (every #'integerp dims)
337 wlott 1.6 (give-up "Dimension list contains something other than an integer: ~S"
338 wlott 1.1 dims))
339     (if (= (length dims) 1)
340     `(make-array ',(car dims)
341     ,@(when initial-element
342     '(:initial-element initial-element))
343     ,@(when element-type
344     '(:element-type element-type)))
345     (let* ((total-size (reduce #'* dims))
346     (rank (length dims))
347     (spec `(simple-array
348     ,(cond ((null element-type) t)
349     ((constant-continuation-p element-type)
350     (continuation-value element-type))
351     (t '*))
352     ,(make-list rank :initial-element '*))))
353     `(let ((header (make-array-header vm:simple-array-type ,rank)))
354     (setf (%array-fill-pointer header) ,total-size)
355     (setf (%array-fill-pointer-p header) nil)
356     (setf (%array-available-elements header) ,total-size)
357     (setf (%array-data-vector header)
358     (make-array ,total-size
359     ,@(when element-type
360     '(:element-type element-type))
361     ,@(when initial-element
362     '(:initial-element initial-element))))
363     (setf (%array-displaced-p header) nil)
364     ,@(let ((axis -1))
365     (mapcar #'(lambda (dim)
366     `(setf (%array-dimension header ,(incf axis))
367     ,dim))
368     dims))
369     (truly-the ,spec header))))))
370    
371    
372     ;;;; Random properties of arrays.
373    
374     ;;; Transforms for various random array properties. If the property is know
375     ;;; at compile time because of a type spec, use that constant value.
376    
377     ;;; ARRAY-RANK -- transform.
378     ;;;
379     ;;; If we can tell the rank from the type info, use it instead.
380     ;;;
381     (deftransform array-rank ((array))
382     (let ((array-type (continuation-type array)))
383     (unless (array-type-p array-type)
384     (give-up))
385     (let ((dims (array-type-dimensions array-type)))
386     (if (not (listp dims))
387     (give-up "Array rank not known at compile time: ~S" dims)
388     (length dims)))))
389    
390     ;;; ARRAY-DIMENSION -- transform.
391     ;;;
392     ;;; If we know the dimensions at compile time, just use it. Otherwise, if
393     ;;; we can tell that the axis is in bounds, convert to %array-dimension
394     ;;; (which just indirects the array header) or length (if it's simple and a
395     ;;; vector).
396     ;;;
397     (deftransform array-dimension ((array axis)
398     (array index))
399     (unless (constant-continuation-p axis)
400     (give-up "Axis not constant."))
401     (let ((array-type (continuation-type array))
402     (axis (continuation-value axis)))
403     (unless (array-type-p array-type)
404     (give-up))
405     (let ((dims (array-type-dimensions array-type)))
406     (unless (listp dims)
407     (give-up
408     "Array dimensions unknown, must call array-dimension at runtime."))
409     (unless (> (length dims) axis)
410     (abort-transform "Array has dimensions ~S, ~D is too large."
411     dims axis))
412     (let ((dim (nth axis dims)))
413     (cond ((integerp dim)
414     dim)
415     ((= (length dims) 1)
416     (ecase (array-type-complexp array-type)
417     ((t)
418     '(%array-dimension array 0))
419     ((nil)
420     '(length array))
421 gerd 1.32 ((:maybe *)
422 wlott 1.1 (give-up "Can't tell if array is simple."))))
423     (t
424     '(%array-dimension array axis)))))))
425    
426     ;;; LENGTH -- transform.
427     ;;;
428     ;;; If the length has been declared and it's simple, just return it.
429     ;;;
430     (deftransform length ((vector)
431     ((simple-array * (*))))
432     (let ((type (continuation-type vector)))
433     (unless (array-type-p type)
434     (give-up))
435     (let ((dims (array-type-dimensions type)))
436     (unless (and (listp dims) (integerp (car dims)))
437     (give-up "Vector length unknown, must call length at runtime."))
438     (car dims))))
439    
440     ;;; LENGTH -- transform.
441     ;;;
442     ;;; All vectors can get their length by using vector-length. If it's simple,
443     ;;; it will extract the length slot from the vector. It it's complex, it will
444     ;;; extract the fill pointer slot from the array header.
445     ;;;
446     (deftransform length ((vector) (vector))
447     '(vector-length vector))
448    
449 ram 1.7
450     ;;; If a simple array with known dimensions, then vector-length is a
451     ;;; compile-time constant.
452     ;;;
453     (deftransform vector-length ((vector) ((simple-array * (*))))
454     (let ((vtype (continuation-type vector)))
455     (if (array-type-p vtype)
456     (let ((dim (first (array-type-dimensions vtype))))
457     (when (eq dim '*) (give-up))
458     dim)
459     (give-up))))
460    
461    
462 wlott 1.1 ;;; ARRAY-TOTAL-SIZE -- transform.
463     ;;;
464     ;;; Again, if we can tell the results from the type, just use it. Otherwise,
465     ;;; if we know the rank, convert into a computation based on array-dimension.
466     ;;; We can wrap a truly-the index around the multiplications because we know
467     ;;; that the total size must be an index.
468     ;;;
469     (deftransform array-total-size ((array)
470     (array))
471     (let ((array-type (continuation-type array)))
472     (unless (array-type-p array-type)
473     (give-up))
474     (let ((dims (array-type-dimensions array-type)))
475     (unless (listp dims)
476 wlott 1.2 (give-up "Can't tell the rank at compile time."))
477     (if (member '* dims)
478     (do ((form 1 `(truly-the index
479     (* (array-dimension array ,i) ,form)))
480     (i 0 (1+ i)))
481     ((= i (length dims)) form))
482     (reduce #'* dims)))))
483 wlott 1.1
484     ;;; ARRAY-HAS-FILL-POINTER-P -- transform.
485     ;;;
486     ;;; Only complex vectors have fill pointers.
487     ;;;
488     (deftransform array-has-fill-pointer-p ((array))
489     (let ((array-type (continuation-type array)))
490     (unless (array-type-p array-type)
491     (give-up))
492     (let ((dims (array-type-dimensions array-type)))
493     (if (and (listp dims) (not (= (length dims) 1)))
494     nil
495     (ecase (array-type-complexp array-type)
496     ((t)
497     t)
498     ((nil)
499     nil)
500 rtoy 1.39 (:maybe
501 wlott 1.1 (give-up "Array type ambiguous; must call ~
502     array-has-fill-pointer-p at runtime.")))))))
503    
504     ;;; %CHECK-BOUND -- transform.
505     ;;;
506     ;;; Primitive used to verify indicies into arrays. If we can tell at
507     ;;; compile-time or we are generating unsafe code, don't bother with the VOP.
508     ;;;
509     (deftransform %check-bound ((array dimension index))
510     (unless (constant-continuation-p dimension)
511     (give-up))
512     (let ((dim (continuation-value dimension)))
513 gerd 1.34 `(the (integer 0 (,dim)) index)))
514 wlott 1.1 ;;;
515     (deftransform %check-bound ((array dimension index) * *
516     :policy (and (> speed safety) (= safety 0)))
517     'index)
518    
519    
520     ;;; WITH-ROW-MAJOR-INDEX -- internal.
521     ;;;
522     ;;; Handy macro for computing the row-major index given a set of indices. We
523     ;;; wrap each index with a call to %check-bound to assure that everything
524     ;;; works out correctly. We can wrap all the interior arith with truly-the
525     ;;; index because we know the the resultant row-major index must be an index.
526     ;;;
527     (eval-when (compile eval)
528     ;;;
529     (defmacro with-row-major-index ((array indices index &optional new-value)
530     &rest body)
531     `(let (n-indices dims)
532     (dotimes (i (length ,indices))
533     (push (make-symbol (format nil "INDEX-~D" i)) n-indices)
534     (push (make-symbol (format nil "DIM-~D" i)) dims))
535     (setf n-indices (nreverse n-indices))
536     (setf dims (nreverse dims))
537     `(lambda (,',array ,@n-indices ,@',(when new-value (list new-value)))
538     (let* (,@(let ((,index -1))
539     (mapcar #'(lambda (name)
540     `(,name (array-dimension ,',array
541     ,(incf ,index))))
542     dims))
543     (,',index
544     ,(if (null dims)
545     0
546     (do* ((dims dims (cdr dims))
547     (indices n-indices (cdr indices))
548     (last-dim nil (car dims))
549     (form `(%check-bound ,',array
550     ,(car dims)
551     ,(car indices))
552     `(truly-the index
553     (+ (truly-the index
554     (* ,form
555     ,last-dim))
556     (%check-bound
557     ,',array
558     ,(car dims)
559     ,(car indices))))))
560     ((null (cdr dims)) form)))))
561     ,',@body))))
562     ;;;
563     ); eval-when
564    
565     ;;; ARRAY-ROW-MAJOR-INDEX -- transform.
566     ;;;
567     ;;; Just return the index after computing it.
568     ;;;
569     (deftransform array-row-major-index ((array &rest indices))
570     (with-row-major-index (array indices index)
571     index))
572    
573    
574    
575     ;;;; Array accessors:
576    
577     ;;; SVREF, %SVSET, SCHAR, %SCHARSET, CHAR,
578     ;;; %CHARSET, SBIT, %SBITSET, BIT, %BITSET
579     ;;; -- source transforms.
580     ;;;
581     ;;; We convert all typed array accessors into aref and %aset with type
582     ;;; assertions on the array.
583     ;;;
584     (macrolet ((frob (reffer setter type)
585     `(progn
586     (def-source-transform ,reffer (a &rest i)
587 ram 1.16 (if (byte-compiling)
588 ram 1.15 (values nil t)
589     `(aref (the ,',type ,a) ,@i)))
590 wlott 1.1 (def-source-transform ,setter (a &rest i)
591 ram 1.16 (if (byte-compiling)
592 ram 1.15 (values nil t)
593     `(%aset (the ,',type ,a) ,@i))))))
594 gerd 1.33 (frob sbit %sbitset (simple-array bit))
595     (frob bit %bitset (array bit)))
596    
597     (macrolet ((frob (reffer setter type)
598     `(progn
599     (def-source-transform ,reffer (a i)
600     (if (byte-compiling)
601     (values nil t)
602     `(aref (the ,',type ,a) ,i)))
603     (def-source-transform ,setter (a i v)
604     (if (byte-compiling)
605     (values nil t)
606     `(%aset (the ,',type ,a) ,i ,v))))))
607 wlott 1.1 (frob svref %svset simple-vector)
608     (frob schar %scharset simple-string)
609 gerd 1.33 (frob char %charset string))
610 wlott 1.1
611     ;;; AREF, %ASET -- transform.
612     ;;;
613     ;;; Convert into a data-vector-ref (or set) with the set of indices replaced
614     ;;; with the an expression for the row major index.
615     ;;;
616     (deftransform aref ((array &rest indices))
617     (with-row-major-index (array indices index)
618     (data-vector-ref array index)))
619     ;;;
620     (deftransform %aset ((array &rest stuff))
621     (let ((indices (butlast stuff)))
622     (with-row-major-index (array indices index new-value)
623     (data-vector-set array index new-value))))
624    
625     ;;; ROW-MAJOR-AREF, %SET-ROW-MAJOR-AREF -- transform.
626     ;;;
627     ;;; Just convert into a data-vector-ref (or set) after checking that the
628     ;;; index is inside the array total size.
629     ;;;
630     (deftransform row-major-aref ((array index))
631     `(data-vector-ref array (%check-bound array (array-total-size array) index)))
632     ;;;
633     (deftransform %set-row-major-aref ((array index new-value))
634     `(data-vector-set array
635     (%check-bound array (array-total-size array) index)
636     new-value))
637 ram 1.7
638    
639     ;;;; Bit-vector array operation canonicalization:
640     ;;;
641     ;;; We convert all bit-vector operations to have the result array specified.
642     ;;; This allows any result allocation to be open-coded, and eliminates the need
643     ;;; for any VM-dependent transforms to handle these cases.
644    
645     (dolist (fun '(bit-and bit-ior bit-xor bit-eqv bit-nand bit-nor bit-andc1
646     bit-andc2 bit-orc1 bit-orc2))
647     ;;
648     ;; Make a result array if result is NIL or unsupplied.
649     (deftransform fun ((bit-array-1 bit-array-2 &optional result-bit-array)
650 ram 1.14 '(bit-vector bit-vector &optional null) '*
651 ram 1.7 :eval-name t :policy (>= speed space))
652     `(,fun bit-array-1 bit-array-2
653 rtoy 1.40 (make-array (array-dimension bit-array-1 0) :element-type 'bit)))
654 ram 1.7 ;;
655     ;; If result its T, make it the first arg.
656     (deftransform fun ((bit-array-1 bit-array-2 result-bit-array)
657 ram 1.14 '(bit-vector bit-vector (member t)) '*
658 ram 1.7 :eval-name t)
659     `(,fun bit-array-1 bit-array-2 bit-array-1)))
660    
661     ;;; Similar for BIT-NOT, but there is only one arg...
662     ;;;
663     (deftransform bit-not ((bit-array-1 &optional result-bit-array)
664     (bit-vector &optional null) *
665     :policy (>= speed space))
666     '(bit-not bit-array-1
667     (make-array (length bit-array-1) :element-type 'bit)))
668     ;;;
669     (deftransform bit-not ((bit-array-1 result-bit-array)
670     (bit-vector (constant-argument t)))
671 ram 1.17 '(bit-not bit-array-1 bit-array-1))
672 dtc 1.20
673    
674     ;;; ARRAY-HEADER-P -- transform.
675     ;;;
676     ;;; Pick off some constant cases.
677     ;;;
678     (deftransform array-header-p ((array) (array))
679     (let ((type (continuation-type array)))
680     (declare (optimize (safety 3)))
681     (unless (array-type-p type)
682     (give-up))
683     (let ((dims (array-type-dimensions type)))
684     (cond ((csubtypep type (specifier-type '(simple-array * (*))))
685     ;; No array header.
686     nil)
687     ((and (listp dims) (> (length dims) 1))
688     ;; Multi-dimensional array, will have a header.
689     t)
690     (t
691     (give-up))))))

  ViewVC Help
Powered by ViewVC 1.1.5