/[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.19.2.4 - (show annotations)
Sun Jul 9 14:03:12 2000 UTC (13 years, 9 months ago) by dtc
Branch: RELENG_18
CVS Tags: RELEASE_18d, RELEASE_18c
Changes since 1.19.2.3: +4 -3 lines
Reworking of the values-type system to overcome a number of inconsistencies
causing problems:

o Redefine coerce-to-values to convert a single value type into (values type),
  rather than the former definition (values type &rest t). A single value
  type such as fixnum is now equivalent to (values fixnum).

o Now when the compiler makes assertions for the first value of
  continuations that may be generating multiple values it asserts the
  type as (values type &rest t), or as (value &optional type &rest t) if
  it is not sure that the continuation does generate a value.

o Enhance the type check generation to better handle the now common
  values types with optional and rest arguments. Add the new function
  Values-types-asserted which converts asserted optional and rest
  arguments to required arguments that have been proven to be delivered,
  Thus an assertion such as (values &optional fixnum &rest t) will
  generate a fixnum type check if the proven type if (values t).

o The compiler is now far more likely to pickup attempts to use an
  assertion to select a subset of values. For example
  (the (values fixnum) (values x y)) will generated a compiler warning.

o Update single values type assertions where appropriate to clarify that
  the received values may be optional or that multiple values may be
  received. For example, a macro argument which had been asserted to be
  a list via (the list ,...) would now be asserted to be
  (the (values &optional list &rest t)) etc.

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

  ViewVC Help
Powered by ViewVC 1.1.5