1.0.28.10: faster array dimension typechecking code
authorNikodemus Siivola <nikodemus@random-state.net>
Mon, 4 May 2009 20:43:04 +0000 (20:43 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Mon, 4 May 2009 20:43:04 +0000 (20:43 +0000)
 * Put in an explicit ARRAY-HEADER-P, and short-circuit on its result
   when possible, otherwise use the known presence or lack of header
   to get dimensions more efficiently: using either %ARRAY-DIMENSION
   or VECTOR-LENGTH.

NEWS
src/compiler/typetran.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index 3d05ffc..7f2c767 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
+  * optimization: compiler now generates faster typechecking code for
+    array dimensions.
   * optimization: multidimensional array accesses in the absence of type
     information regarding array rank are approximately 10% faster due to
     open coding of ARRAY-RANK.
index 53f3c64..3513498 100644 (file)
         (dims (array-type-dimensions type)))
     (unless (or (eq dims '*)
                 (equal dims (array-type-dimensions stype)))
-      (collect ((res))
-        (when (eq (array-type-dimensions stype) '*)
-          (res `(= (array-rank ,obj) ,(length dims))))
-        (do ((i 0 (1+ i))
-             (dim dims (cdr dim)))
-            ((null dim))
-          (let ((dim (car dim)))
-            (unless (eq dim '*)
-              (res `(= (array-dimension ,obj ,i) ,dim)))))
-        (res)))))
+      (cond ((cdr dims)
+             `((array-header-p ,obj)
+               ,@(when (eq (array-type-dimensions stype) '*)
+                       `((= (%array-rank ,obj) ,(length dims))))
+               ,@(loop for d in dims
+                       for i from 0
+                       unless (eq '* d)
+                       collect `(= (%array-dimension ,obj ,i) ,d))))
+            ((and dims (csubtypep stype (specifier-type 'simple-array)))
+             `((not (array-header-p ,obj))
+               ,@(unless (eq '* (car dims))
+                         `((= (vector-length ,obj) ,@dims)))))
+            ((and dims (csubtypep stype (specifier-type '(and array (not simple-array)))))
+             `((array-header-p ,obj)
+               ,@(unless (eq '* (car dims))
+                         `((= (%array-dimension ,obj 0) ,@dims)))))
+            (dims
+             (unless (eq '* (car dims))
+               `((if (array-header-p ,obj)
+                     (= (%array-dimension ,obj 0) ,@dims)
+                     (= (vector-length ,obj) ,@dims)))))))))
 
 ;;; Return forms to test that OBJ has the element-type specified by
 ;;; type specified by TYPE, where STYPE is the type we have checked
index 9d0525a..3d0b1c5 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.28.9"
+"1.0.28.10"