Changeset 386


Ignore:
Timestamp:
Jan 24, 2004, 3:43:45 PM (21 years ago)
Author:
Gary Byers
Message:

Vector case of SUBSEQ had better be faster ...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lib/sequences.lisp

    r6 r386  
    129129;;; Subseq:
    130130
    131 (defun vector-subseq* (sequence start end)
    132   (declare (vector sequence))
    133   (declare (fixnum end start))
     131;;; SRC is a (SIMPLE-ARRAY * (*)), TYPECODE is its ... typecode,
     132;;; START and END are fixnums and sanity-checked.
     133(defun simple-1d-array-subseq (src typecode start end)
     134  (declare (fixnum start end typecode))
    134135  (let* ((n (- end start))
    135          (copy (make-sequence-like sequence n)))
     136         (dest (%alloc-misc n typecode)))
    136137    (declare (fixnum n))
    137     (multiple-value-bind (v offset subtype) (array-data-offset-subtype sequence)
    138       (let* ((old-index (%i+ offset start)))
    139         (declare (fixnum old-index new-index))
    140         (dotimes (i n copy)
    141           (%typed-miscset subtype copy i (%typed-miscref subtype v old-index))
    142           (incf old-index))))))
     138    (if (= typecode target::subtag-simple-vector)
     139      (%copy-gvector-to-gvector src start dest 0 n)
     140      (ecase typecode
     141        ((#.target::subtag-simple-base-string
     142          #.target::subtag-s8-vector
     143          #.target::subtag-u8-vector)
     144         (%copy-ivector-to-ivector src start dest 0 n))
     145        ((#.target::subtag-s16-vector
     146          #.target::subtag-u16-vector)
     147         (%copy-ivector-to-ivector src
     148                                   (the fixnum (+ start start))
     149                                   dest
     150                                   0
     151                                   (the fixnum (+ n n))))
     152        ((#.target::subtag-s32-vector
     153          #.target::subtag-u32-vector
     154          #.target::subtag-single-float-vector)
     155         (%copy-ivector-to-ivector src
     156                                   (the fixnum (ash start 2))
     157                                   dest
     158                                   0
     159                                   (the fixnum (ash n 2))))
     160        ;; DOUBLE-FLOAT vectors have extra alignment padding on ppc32.
     161        #+ppc32-target
     162        (#.ppc32::subtag-double-float-vector
     163         (%copy-ivector-to-ivector src
     164                                   (the fixnum (+ (the fixnum (ash start 3))
     165                                                  (- ppc32::misc-dfloat-offset
     166                                                     ppc32::misc-data-offset)))
     167                                   dest
     168                                   (- ppc32::misc-dfloat-offset
     169                                                     ppc32::misc-data-offset)
     170                                   (the fixnum (ash n 3))))
     171        #+ppc64-target
     172        ((#.ppc64::subtag-double-float-vector
     173          #+ppc64::subtag-s64-vector
     174          #+ppc64::subtag-u64-vector)
     175         (%copy-ivector-to-ivector src
     176                                   (the fixnum ash start 3)
     177                                   dest
     178                                   0
     179                                   (the fixnum (ash n 3))))
     180        (#.target::subtag-bit-vector
     181         ;; We can probably do a byte at a time if (not (logtest start 7))
     182         (if (not (logtest start 7))
     183           (%copy-ivector-to-ivector src
     184                                     (the fixnum (ash (the fixnum (+ start 7))
     185                                                      -3))
     186                                     dest
     187                                     0
     188                                     (the fixnum (ash (the fixnum (+ n 7))
     189                                                      -3)))
     190           ;; Harder to optimize this case.
     191           (locally  (declare (simple-bit-vector src dest)
     192                              (optimize (speed 3) (safety 0)))
     193             (do* ((i start (1+ i))
     194                   (j 0 (1+ j)))
     195                  ((= i end) dest)
     196               (declare (fixnum i j))
     197               (setf (sbit dest j) (sbit src i))))))))))
     198                   
     199                                     
     200       
     201
    143202
    144203(defun nthcdr-error (index list &aux (copy list))
     
    172231(defun subseq (sequence start &optional end)
    173232  (setq end (check-sequence-bounds sequence start end))
    174   (seq-dispatch
    175    sequence
    176    (list-subseq* sequence start end)
    177    (vector-subseq* sequence start end)))
     233  (locally
     234      (declare (fixnum start end))
     235      (seq-dispatch
     236       sequence
     237       (list-subseq* sequence start end)
     238       (let* ((typecode (typecode sequence)))
     239         (declare (fixnum typecode))
     240         (when (= typecode target::subtag-arrayH)
     241           (multiple-value-bind (data offset)
     242               (array-data-and-offset sequence)
     243             (declare (fixnum offset))
     244             (incf start offset)
     245             (incf end offset)
     246             (setq sequence data typecode (typecode data))))
     247         (simple-1d-array-subseq sequence typecode start end)))))
     248         
    178249
    179250;;; Copy-seq:
Note: See TracChangeset for help on using the changeset viewer.