/[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.36 - (hide annotations)
Wed May 5 16:37:22 2004 UTC (9 years, 11 months ago) by rtoy
Branch: MAIN
CVS Tags: snapshot-2004-10, snapshot-2004-08, snapshot-2004-09, snapshot-2004-06, snapshot-2004-07, snapshot-2004-12, snapshot-2004-11, amd64-merge-start, prm-before-macosx-merge-tag, snapshot-2005-01
Changes since 1.35: +3 -3 lines
Fix typo.  0s0 is not a single-float. (Well, it is in CMUCL, but not
in general.)
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.36 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/array-tran.lisp,v 1.36 2004/05/05 16:37:22 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     (assert-new-value-type (car (last stuff)) array))
112    
113     ;;; DATA-VECTOR-REF -- derive-type optimizer.
114     ;;;
115     (defoptimizer (data-vector-ref derive-type) ((array index))
116 dtc 1.23 (extract-upgraded-element-type array))
117 wlott 1.1
118     ;;; DATA-VECTOR-SET -- derive-type optimizer.
119     ;;;
120     (defoptimizer (data-vector-set derive-type) ((array index new-value))
121     (assert-new-value-type new-value array))
122 ram 1.10
123     ;;; %WITH-ARRAY-DATA -- derive-type optimizer.
124     ;;;
125     ;;; Figure out the type of the data vector if we know the argument element
126     ;;; type.
127     ;;;
128     (defoptimizer (%with-array-data derive-type) ((array start end))
129     (let ((atype (continuation-type array)))
130     (when (array-type-p atype)
131     (values-specifier-type
132     `(values (simple-array ,(type-specifier
133     (array-type-element-type atype))
134     (*))
135     index index index)))))
136    
137 wlott 1.1
138     ;;; ARRAY-ROW-MAJOR-INDEX -- derive-type optimizer.
139     ;;;
140     (defoptimizer (array-row-major-index derive-type) ((array &rest indices))
141     (assert-array-rank array (length indices))
142     *universal-type*)
143    
144     ;;; ROW-MAJOR-AREF -- derive-type optimizer.
145     ;;;
146     (defoptimizer (row-major-aref derive-type) ((array index))
147 dtc 1.23 (extract-upgraded-element-type array))
148 wlott 1.1
149     ;;; %SET-ROW-MAJOR-AREF -- derive-type optimizer.
150     ;;;
151     (defoptimizer (%set-row-major-aref derive-type) ((array index new-value))
152     (assert-new-value-type new-value array))
153    
154     ;;; MAKE-ARRAY -- derive-type optimizer.
155     ;;;
156     (defoptimizer (make-array derive-type)
157     ((dims &key initial-element element-type initial-contents
158     adjustable fill-pointer displaced-index-offset displaced-to))
159 wlott 1.11 (let ((simple (and (unsupplied-or-nil adjustable)
160     (unsupplied-or-nil displaced-to)
161     (unsupplied-or-nil fill-pointer))))
162     (specifier-type
163     `(,(if simple 'simple-array 'array)
164     ,(cond ((not element-type) 't)
165     ((constant-continuation-p element-type)
166     (continuation-value element-type))
167     (t
168     '*))
169     ,(cond ((not simple)
170     '*)
171     ((constant-continuation-p dims)
172     (let ((val (continuation-value dims)))
173     (if (listp val) val (list val))))
174     ((csubtypep (continuation-type dims)
175     (specifier-type 'integer))
176     '(*))
177     (t
178     '*))))))
179 wlott 1.1
180    
181     ;;;; Constructors.
182    
183     ;;; VECTOR -- source-transform.
184     ;;;
185     ;;; Convert VECTOR into a make-array followed by setfs of all the elements.
186     ;;;
187     (def-source-transform vector (&rest elements)
188 ram 1.16 (if (byte-compiling)
189 ram 1.15 (values nil t)
190     (let ((len (length elements))
191     (n -1))
192     (once-only ((n-vec `(make-array ,len)))
193     `(progn
194     ,@(mapcar #'(lambda (el)
195     (once-only ((n-val el))
196     `(locally (declare (optimize (safety 0)))
197     (setf (svref ,n-vec ,(incf n))
198     ,n-val))))
199     elements)
200     ,n-vec)))))
201 wlott 1.1
202    
203     ;;; MAKE-STRING -- source-transform.
204     ;;;
205     ;;; Just convert it into a make-array.
206     ;;;
207 gerd 1.31 (deftransform make-string ((length &key (element-type 'base-char)
208 gerd 1.30 (initial-element #\NULL)))
209     `(make-array (the (values index &rest t) length)
210     :element-type element-type
211     :initial-element initial-element))
212 wlott 1.1
213     (defconstant array-info
214 wlott 1.12 '((base-char #\NULL 8 vm:simple-string-type)
215 rtoy 1.36 (single-float 0.0f0 32 vm:simple-array-single-float-type)
216 wlott 1.1 (double-float 0.0d0 64 vm:simple-array-double-float-type)
217 dtc 1.26 #+long-float (long-float 0.0l0 #+x86 96 #+sparc 128
218     vm:simple-array-long-float-type)
219 wlott 1.1 (bit 0 1 vm:simple-bit-vector-type)
220     ((unsigned-byte 2) 0 2 vm:simple-array-unsigned-byte-2-type)
221     ((unsigned-byte 4) 0 4 vm:simple-array-unsigned-byte-4-type)
222     ((unsigned-byte 8) 0 8 vm:simple-array-unsigned-byte-8-type)
223     ((unsigned-byte 16) 0 16 vm:simple-array-unsigned-byte-16-type)
224     ((unsigned-byte 32) 0 32 vm:simple-array-unsigned-byte-32-type)
225 dtc 1.27 ((signed-byte 8) 0 8 vm:simple-array-signed-byte-8-type)
226     ((signed-byte 16) 0 16 vm:simple-array-signed-byte-16-type)
227     ((signed-byte 30) 0 32 vm:simple-array-signed-byte-30-type)
228     ((signed-byte 32) 0 32 vm:simple-array-signed-byte-32-type)
229 rtoy 1.36 ((complex single-float) #C(0.0f0 0.0f0) 64
230 dtc 1.27 vm:simple-array-complex-single-float-type)
231     ((complex double-float) #C(0.0d0 0.0d0) 128
232     vm:simple-array-complex-double-float-type)
233     #+long-float
234 dtc 1.26 ((complex long-float) #C(0.0l0 0.0l0) #+x86 192 #+sparc 256
235     vm:simple-array-complex-long-float-type)
236 wlott 1.1 (t 0 32 vm:simple-vector-type)))
237    
238     ;;; MAKE-ARRAY -- source-transform.
239     ;;;
240     ;;; The integer type restriction on the length assures that it will be a
241     ;;; vector. The lack of adjustable, fill-pointer, and displaced-to keywords
242     ;;; assures that it will be simple.
243     ;;;
244     (deftransform make-array ((length &key initial-element element-type)
245     (integer &rest *))
246     (let* ((eltype (cond ((not element-type) t)
247     ((not (constant-continuation-p element-type))
248     (give-up "Element-Type is not constant."))
249     (t
250     (continuation-value element-type))))
251     (len (if (constant-continuation-p length)
252     (continuation-value length)
253     '*))
254     (spec `(simple-array ,eltype (,len)))
255     (eltype-type (specifier-type eltype)))
256     (multiple-value-bind
257     (default-initial-element element-size typecode)
258     (dolist (info array-info
259     (give-up "Cannot open-code creation of ~S" spec))
260     (when (csubtypep eltype-type (specifier-type (car info)))
261     (return (values-list (cdr info)))))
262 wlott 1.6 (let* ((nwords-form
263     (if (>= element-size vm:word-bits)
264     `(* length ,(/ element-size vm:word-bits))
265     (let ((elements-per-word (/ 32 element-size)))
266     `(truncate (+ length
267     ,(if (eq 'vm:simple-string-type typecode)
268     elements-per-word
269     (1- elements-per-word)))
270     ,elements-per-word))))
271     (constructor
272     `(truly-the ,spec
273     (allocate-vector ,typecode length ,nwords-form))))
274 wlott 1.1 (values
275 dtc 1.22 (cond ((and default-initial-element
276     (or (null initial-element)
277     (and (constant-continuation-p initial-element)
278     (eql (continuation-value initial-element)
279     default-initial-element))))
280     (unless (csubtypep (ctype-of default-initial-element)
281     eltype-type)
282     (compiler-note "Default initial element ~s is not a ~s."
283     default-initial-element eltype))
284     constructor)
285     (t
286     `(truly-the ,spec (fill ,constructor initial-element))))
287 wlott 1.1 '((declare (type index length))))))))
288    
289     ;;; MAKE-ARRAY -- transform.
290     ;;;
291     ;;; The list type restriction does not assure that the result will be a
292     ;;; multi-dimensional array. But the lack of
293     ;;;
294     (deftransform make-array ((dims &key initial-element element-type)
295     (list &rest *))
296     (unless (or (null element-type) (constant-continuation-p element-type))
297     (give-up "Element-type not constant; cannot open code array creation"))
298     (unless (constant-continuation-p dims)
299     (give-up "Dimension list not constant; cannot open code array creation"))
300     (let ((dims (continuation-value dims)))
301     (unless (every #'integerp dims)
302 wlott 1.6 (give-up "Dimension list contains something other than an integer: ~S"
303 wlott 1.1 dims))
304     (if (= (length dims) 1)
305     `(make-array ',(car dims)
306     ,@(when initial-element
307     '(:initial-element initial-element))
308     ,@(when element-type
309     '(:element-type element-type)))
310     (let* ((total-size (reduce #'* dims))
311     (rank (length dims))
312     (spec `(simple-array
313     ,(cond ((null element-type) t)
314     ((constant-continuation-p element-type)
315     (continuation-value element-type))
316     (t '*))
317     ,(make-list rank :initial-element '*))))
318     `(let ((header (make-array-header vm:simple-array-type ,rank)))
319     (setf (%array-fill-pointer header) ,total-size)
320     (setf (%array-fill-pointer-p header) nil)
321     (setf (%array-available-elements header) ,total-size)
322     (setf (%array-data-vector header)
323     (make-array ,total-size
324     ,@(when element-type
325     '(:element-type element-type))
326     ,@(when initial-element
327     '(:initial-element initial-element))))
328     (setf (%array-displaced-p header) nil)
329     ,@(let ((axis -1))
330     (mapcar #'(lambda (dim)
331     `(setf (%array-dimension header ,(incf axis))
332     ,dim))
333     dims))
334     (truly-the ,spec header))))))
335    
336    
337     ;;;; Random properties of arrays.
338    
339     ;;; Transforms for various random array properties. If the property is know
340     ;;; at compile time because of a type spec, use that constant value.
341    
342     ;;; ARRAY-RANK -- transform.
343     ;;;
344     ;;; If we can tell the rank from the type info, use it instead.
345     ;;;
346     (deftransform array-rank ((array))
347     (let ((array-type (continuation-type array)))
348     (unless (array-type-p array-type)
349     (give-up))
350     (let ((dims (array-type-dimensions array-type)))
351     (if (not (listp dims))
352     (give-up "Array rank not known at compile time: ~S" dims)
353     (length dims)))))
354    
355     ;;; ARRAY-DIMENSION -- transform.
356     ;;;
357     ;;; If we know the dimensions at compile time, just use it. Otherwise, if
358     ;;; we can tell that the axis is in bounds, convert to %array-dimension
359     ;;; (which just indirects the array header) or length (if it's simple and a
360     ;;; vector).
361     ;;;
362     (deftransform array-dimension ((array axis)
363     (array index))
364     (unless (constant-continuation-p axis)
365     (give-up "Axis not constant."))
366     (let ((array-type (continuation-type array))
367     (axis (continuation-value axis)))
368     (unless (array-type-p array-type)
369     (give-up))
370     (let ((dims (array-type-dimensions array-type)))
371     (unless (listp dims)
372     (give-up
373     "Array dimensions unknown, must call array-dimension at runtime."))
374     (unless (> (length dims) axis)
375     (abort-transform "Array has dimensions ~S, ~D is too large."
376     dims axis))
377     (let ((dim (nth axis dims)))
378     (cond ((integerp dim)
379     dim)
380     ((= (length dims) 1)
381     (ecase (array-type-complexp array-type)
382     ((t)
383     '(%array-dimension array 0))
384     ((nil)
385     '(length array))
386 gerd 1.32 ((:maybe *)
387 wlott 1.1 (give-up "Can't tell if array is simple."))))
388     (t
389     '(%array-dimension array axis)))))))
390    
391     ;;; LENGTH -- transform.
392     ;;;
393     ;;; If the length has been declared and it's simple, just return it.
394     ;;;
395     (deftransform length ((vector)
396     ((simple-array * (*))))
397     (let ((type (continuation-type vector)))
398     (unless (array-type-p type)
399     (give-up))
400     (let ((dims (array-type-dimensions type)))
401     (unless (and (listp dims) (integerp (car dims)))
402     (give-up "Vector length unknown, must call length at runtime."))
403     (car dims))))
404    
405     ;;; LENGTH -- transform.
406     ;;;
407     ;;; All vectors can get their length by using vector-length. If it's simple,
408     ;;; it will extract the length slot from the vector. It it's complex, it will
409     ;;; extract the fill pointer slot from the array header.
410     ;;;
411     (deftransform length ((vector) (vector))
412     '(vector-length vector))
413    
414 ram 1.7
415     ;;; If a simple array with known dimensions, then vector-length is a
416     ;;; compile-time constant.
417     ;;;
418     (deftransform vector-length ((vector) ((simple-array * (*))))
419     (let ((vtype (continuation-type vector)))
420     (if (array-type-p vtype)
421     (let ((dim (first (array-type-dimensions vtype))))
422     (when (eq dim '*) (give-up))
423     dim)
424     (give-up))))
425    
426    
427 wlott 1.1 ;;; ARRAY-TOTAL-SIZE -- transform.
428     ;;;
429     ;;; Again, if we can tell the results from the type, just use it. Otherwise,
430     ;;; if we know the rank, convert into a computation based on array-dimension.
431     ;;; We can wrap a truly-the index around the multiplications because we know
432     ;;; that the total size must be an index.
433     ;;;
434     (deftransform array-total-size ((array)
435     (array))
436     (let ((array-type (continuation-type array)))
437     (unless (array-type-p array-type)
438     (give-up))
439     (let ((dims (array-type-dimensions array-type)))
440     (unless (listp dims)
441 wlott 1.2 (give-up "Can't tell the rank at compile time."))
442     (if (member '* dims)
443     (do ((form 1 `(truly-the index
444     (* (array-dimension array ,i) ,form)))
445     (i 0 (1+ i)))
446     ((= i (length dims)) form))
447     (reduce #'* dims)))))
448 wlott 1.1
449     ;;; ARRAY-HAS-FILL-POINTER-P -- transform.
450     ;;;
451     ;;; Only complex vectors have fill pointers.
452     ;;;
453     (deftransform array-has-fill-pointer-p ((array))
454     (let ((array-type (continuation-type array)))
455     (unless (array-type-p array-type)
456     (give-up))
457     (let ((dims (array-type-dimensions array-type)))
458     (if (and (listp dims) (not (= (length dims) 1)))
459     nil
460     (ecase (array-type-complexp array-type)
461     ((t)
462     t)
463     ((nil)
464     nil)
465     (*
466     (give-up "Array type ambiguous; must call ~
467     array-has-fill-pointer-p at runtime.")))))))
468    
469     ;;; %CHECK-BOUND -- transform.
470     ;;;
471     ;;; Primitive used to verify indicies into arrays. If we can tell at
472     ;;; compile-time or we are generating unsafe code, don't bother with the VOP.
473     ;;;
474     (deftransform %check-bound ((array dimension index))
475     (unless (constant-continuation-p dimension)
476     (give-up))
477     (let ((dim (continuation-value dimension)))
478 gerd 1.34 `(the (integer 0 (,dim)) index)))
479 wlott 1.1 ;;;
480     (deftransform %check-bound ((array dimension index) * *
481     :policy (and (> speed safety) (= safety 0)))
482     'index)
483    
484    
485     ;;; WITH-ROW-MAJOR-INDEX -- internal.
486     ;;;
487     ;;; Handy macro for computing the row-major index given a set of indices. We
488     ;;; wrap each index with a call to %check-bound to assure that everything
489     ;;; works out correctly. We can wrap all the interior arith with truly-the
490     ;;; index because we know the the resultant row-major index must be an index.
491     ;;;
492     (eval-when (compile eval)
493     ;;;
494     (defmacro with-row-major-index ((array indices index &optional new-value)
495     &rest body)
496     `(let (n-indices dims)
497     (dotimes (i (length ,indices))
498     (push (make-symbol (format nil "INDEX-~D" i)) n-indices)
499     (push (make-symbol (format nil "DIM-~D" i)) dims))
500     (setf n-indices (nreverse n-indices))
501     (setf dims (nreverse dims))
502     `(lambda (,',array ,@n-indices ,@',(when new-value (list new-value)))
503     (let* (,@(let ((,index -1))
504     (mapcar #'(lambda (name)
505     `(,name (array-dimension ,',array
506     ,(incf ,index))))
507     dims))
508     (,',index
509     ,(if (null dims)
510     0
511     (do* ((dims dims (cdr dims))
512     (indices n-indices (cdr indices))
513     (last-dim nil (car dims))
514     (form `(%check-bound ,',array
515     ,(car dims)
516     ,(car indices))
517     `(truly-the index
518     (+ (truly-the index
519     (* ,form
520     ,last-dim))
521     (%check-bound
522     ,',array
523     ,(car dims)
524     ,(car indices))))))
525     ((null (cdr dims)) form)))))
526     ,',@body))))
527     ;;;
528     ); eval-when
529    
530     ;;; ARRAY-ROW-MAJOR-INDEX -- transform.
531     ;;;
532     ;;; Just return the index after computing it.
533     ;;;
534     (deftransform array-row-major-index ((array &rest indices))
535     (with-row-major-index (array indices index)
536     index))
537    
538    
539    
540     ;;;; Array accessors:
541    
542     ;;; SVREF, %SVSET, SCHAR, %SCHARSET, CHAR,
543     ;;; %CHARSET, SBIT, %SBITSET, BIT, %BITSET
544     ;;; -- source transforms.
545     ;;;
546     ;;; We convert all typed array accessors into aref and %aset with type
547     ;;; assertions on the array.
548     ;;;
549     (macrolet ((frob (reffer setter type)
550     `(progn
551     (def-source-transform ,reffer (a &rest i)
552 ram 1.16 (if (byte-compiling)
553 ram 1.15 (values nil t)
554     `(aref (the ,',type ,a) ,@i)))
555 wlott 1.1 (def-source-transform ,setter (a &rest i)
556 ram 1.16 (if (byte-compiling)
557 ram 1.15 (values nil t)
558     `(%aset (the ,',type ,a) ,@i))))))
559 gerd 1.33 (frob sbit %sbitset (simple-array bit))
560     (frob bit %bitset (array bit)))
561    
562     (macrolet ((frob (reffer setter type)
563     `(progn
564     (def-source-transform ,reffer (a i)
565     (if (byte-compiling)
566     (values nil t)
567     `(aref (the ,',type ,a) ,i)))
568     (def-source-transform ,setter (a i v)
569     (if (byte-compiling)
570     (values nil t)
571     `(%aset (the ,',type ,a) ,i ,v))))))
572 wlott 1.1 (frob svref %svset simple-vector)
573     (frob schar %scharset simple-string)
574 gerd 1.33 (frob char %charset string))
575 wlott 1.1
576     ;;; AREF, %ASET -- transform.
577     ;;;
578     ;;; Convert into a data-vector-ref (or set) with the set of indices replaced
579     ;;; with the an expression for the row major index.
580     ;;;
581     (deftransform aref ((array &rest indices))
582     (with-row-major-index (array indices index)
583     (data-vector-ref array index)))
584     ;;;
585     (deftransform %aset ((array &rest stuff))
586     (let ((indices (butlast stuff)))
587     (with-row-major-index (array indices index new-value)
588     (data-vector-set array index new-value))))
589    
590     ;;; ROW-MAJOR-AREF, %SET-ROW-MAJOR-AREF -- transform.
591     ;;;
592     ;;; Just convert into a data-vector-ref (or set) after checking that the
593     ;;; index is inside the array total size.
594     ;;;
595     (deftransform row-major-aref ((array index))
596     `(data-vector-ref array (%check-bound array (array-total-size array) index)))
597     ;;;
598     (deftransform %set-row-major-aref ((array index new-value))
599     `(data-vector-set array
600     (%check-bound array (array-total-size array) index)
601     new-value))
602 ram 1.7
603    
604     ;;;; Bit-vector array operation canonicalization:
605     ;;;
606     ;;; We convert all bit-vector operations to have the result array specified.
607     ;;; This allows any result allocation to be open-coded, and eliminates the need
608     ;;; for any VM-dependent transforms to handle these cases.
609    
610     (dolist (fun '(bit-and bit-ior bit-xor bit-eqv bit-nand bit-nor bit-andc1
611     bit-andc2 bit-orc1 bit-orc2))
612     ;;
613     ;; Make a result array if result is NIL or unsupplied.
614     (deftransform fun ((bit-array-1 bit-array-2 &optional result-bit-array)
615 ram 1.14 '(bit-vector bit-vector &optional null) '*
616 ram 1.7 :eval-name t :policy (>= speed space))
617     `(,fun bit-array-1 bit-array-2
618     (make-array (length bit-array-1) :element-type 'bit)))
619     ;;
620     ;; If result its T, make it the first arg.
621     (deftransform fun ((bit-array-1 bit-array-2 result-bit-array)
622 ram 1.14 '(bit-vector bit-vector (member t)) '*
623 ram 1.7 :eval-name t)
624     `(,fun bit-array-1 bit-array-2 bit-array-1)))
625    
626     ;;; Similar for BIT-NOT, but there is only one arg...
627     ;;;
628     (deftransform bit-not ((bit-array-1 &optional result-bit-array)
629     (bit-vector &optional null) *
630     :policy (>= speed space))
631     '(bit-not bit-array-1
632     (make-array (length bit-array-1) :element-type 'bit)))
633     ;;;
634     (deftransform bit-not ((bit-array-1 result-bit-array)
635     (bit-vector (constant-argument t)))
636 ram 1.17 '(bit-not bit-array-1 bit-array-1))
637 dtc 1.20
638    
639     ;;; ARRAY-HEADER-P -- transform.
640     ;;;
641     ;;; Pick off some constant cases.
642     ;;;
643     (deftransform array-header-p ((array) (array))
644     (let ((type (continuation-type array)))
645     (declare (optimize (safety 3)))
646     (unless (array-type-p type)
647     (give-up))
648     (let ((dims (array-type-dimensions type)))
649     (cond ((csubtypep type (specifier-type '(simple-array * (*))))
650     ;; No array header.
651     nil)
652     ((and (listp dims) (> (length dims) 1))
653     ;; Multi-dimensional array, will have a header.
654     t)
655     (t
656     (give-up))))))

  ViewVC Help
Powered by ViewVC 1.1.5