From 171e45b53474e025b1c82e2bd715ff4b9721f953 Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Mon, 4 May 2009 20:43:04 +0000 Subject: [PATCH] 1.0.28.10: faster array dimension typechecking code * 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 | 2 ++ src/compiler/typetran.lisp | 31 +++++++++++++++++++++---------- version.lisp-expr | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 3d05ffc..7f2c767 100644 --- 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. diff --git a/src/compiler/typetran.lisp b/src/compiler/typetran.lisp index 53f3c64..3513498 100644 --- a/src/compiler/typetran.lisp +++ b/src/compiler/typetran.lisp @@ -340,16 +340,27 @@ (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 diff --git a/version.lisp-expr b/version.lisp-expr index 9d0525a..3d0b1c5 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -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" -- 1.7.10.4