Make CONTAINING-INTEGER-TYPE take N-WORD-BITS into account.
authorLutz Euler <lutz.euler@freenet.de>
Mon, 6 May 2013 17:37:23 +0000 (19:37 +0200)
committerLutz Euler <lutz.euler@freenet.de>
Mon, 6 May 2013 17:37:23 +0000 (19:37 +0200)
Replace the hardcoded 32s in the function with N-WORD-BITS. This in turn
allows SOURCE-TRANSFORM-NUMERIC-TYPEP to find better transformations
for type checks for types larger than fixnum but smaller than a machine
word also under 64-bit word size. The most important improvement this
achieves is to avoid generic arithmetic for the bounds tests in these
cases.

For example, the test (TYPEP X '(UNSIGNED-BYTE 63)) runs about four
times as fast on x86-64 with this change.

(Tests for the exact types (SIGNED-BYTE 64) and (UNSIGNED-BYTE 64) are
unaffected as compiling them takes another code path, which already
generates well optimized code.)

NEWS
src/compiler/generic/vm-type.lisp

diff --git a/NEWS b/NEWS
index 411d233..48e6e1f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,10 @@ changes relative to sbcl-1.1.7:
   * optimization: faster and smaller INTEGER-LENGTH on fixnums on x86-64.
   * optimization: On x86-64, the number of multi-byte NOP instructions used
     for code alignment is now always minimal.
+  * optimization: On 64-bit targets, the compiler generates much faster
+    code for type checks for types known at compile time that are smaller
+    than (SIGNED-BYTE 64) or (UNSIGNED-BYTE 64) and larger than FIXNUM, and
+    their COMPLEX variants.
 
 changes in sbcl-1.1.7 relative to sbcl-1.1.6:
   * enhancement: TRACE :PRINT-ALL handles multiple-valued forms.
index 618de2b..ccacc48 100644 (file)
 ;;; Return the most specific integer type that can be quickly checked that
 ;;; includes the given type.
 (defun containing-integer-type (subtype)
-  (dolist (type '(fixnum
-                  (signed-byte 32)
-                  (unsigned-byte 32)
+  (dolist (type `(fixnum
+                  (signed-byte ,sb!vm:n-word-bits)
+                  (unsigned-byte ,sb!vm:n-word-bits)
                   integer)
                 (error "~S isn't an integer type?" subtype))
     (when (csubtypep subtype (specifier-type type))