0.8.13.3:
authorChristophe Rhodes <csr21@cam.ac.uk>
Mon, 26 Jul 2004 10:24:40 +0000 (10:24 +0000)
committerChristophe Rhodes <csr21@cam.ac.uk>
Mon, 26 Jul 2004 10:24:40 +0000 (10:24 +0000)
Improve BIGNUM-GCD ever so slightly
... BIGNUM-INDEX isn't actually usefully INDEX, because we
require the ability to index individual bits.  Divide
the type by 32, then.
... rearrange bignum.lisp slightly to declare types of functions
before their use.  (Aside: I'm not sure why I need the
type declaration, given that the final compiler can
derive the type fine.  Maybe the cross-compiler is
lobotomized in some significant way here?)

src/code/bignum.lisp
src/compiler/generic/vm-type.lisp
version.lisp-expr

index c0606e6..c188965 100644 (file)
 \f
 ;;;; GCD
 
+;;; I'm not sure why I need this FTYPE declaration.  Compiled by the
+;;; target compiler, it can deduce the return type fine, but without
+;;; it, we pay a heavy price in BIGNUM-GCD when compiled by the
+;;; cross-compiler. -- CSR, 2004-07-19
+(declaim (ftype (sfunction (bignum-type bignum-index bignum-type bignum-index)
+                          (unsigned-byte 29))
+               bignum-factors-of-two))
+(defun bignum-factors-of-two (a len-a b len-b)
+  (declare (type bignum-index len-a len-b) (type bignum-type a b))
+  (do ((i 0 (1+ i))
+       (end (min len-a len-b)))
+      ((= i end) (error "Unexpected zero bignums?"))
+    (declare (type bignum-index i end))
+    (let ((or-digits (%logior (%bignum-ref a i) (%bignum-ref b i))))
+      (unless (zerop or-digits)
+       (return (do ((j 0 (1+ j))
+                    (or-digits or-digits (%ashr or-digits 1)))
+                   ((oddp or-digits) (+ (* i digit-size) j))
+                 (declare (type (mod 32) j))))))))
+
 (defun bignum-gcd (a b)
   (declare (type bignum-type a b))
   (let* ((a (if (%bignum-0-or-plusp a (%bignum-length a))
                     (bignum-buffer-ashift-right a len-a
                                                 (+ (* index digit-size)
                                                    increment)))))))
-
-(defun bignum-factors-of-two (a len-a b len-b)
-  (declare (type bignum-index len-a len-b) (type bignum-type a))
-  (do ((i 0 (1+ i))
-       (end (min len-a len-b)))
-      ((= i end) (error "Unexpected zero bignums?"))
-    (declare (type bignum-index i end))
-    (let ((or-digits (%logior (%bignum-ref a i) (%bignum-ref b i))))
-      (unless (zerop or-digits)
-       (return (do ((j 0 (1+ j))
-                    (or-digits or-digits (%ashr or-digits 1)))
-                   ((oddp or-digits) (+ (* i digit-size) j))
-                 (declare (type (mod 32) j))))))))
 \f
 ;;;; negation
 
index e43b2d4..fc763a3 100644 (file)
 
 (sb!xc:deftype bignum-element-type () `(unsigned-byte ,sb!vm:n-word-bits))
 (sb!xc:deftype bignum-type () 'bignum)
-(sb!xc:deftype bignum-index () 'index)
+;;; FIXME: see also DEFCONSTANT MAXIMUM-BIGNUM-LENGTH in
+;;; src/code/bignum.lisp.  -- CSR, 2004-07-19
+(sb!xc:deftype bignum-index ()
+  '(integer 0 #.(1- (ash 1 (- 32 sb!vm:n-widetag-bits)))))
 \f
 ;;;; hooks into the type system
 
index 5d498bf..6c5211b 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".)
-"0.8.13.2"
+"0.8.13.3"