Changeset 238


Ignore:
Timestamp:
Jan 7, 2004, 4:29:37 PM (21 years ago)
Author:
Gary Byers
Message:

Detect when destructive right shifts yield a fixnum more accurately (this
was causing the bignums to be passed to internal functions that expect
fixnums in some cases).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-0/l0-bignum.lisp

    r194 r238  
    20002000        (logand mask (ash integer (- position)))))))   
    20012001
    2002 (defun %bignum-bignum-gcd (n1 n2)
    2003   (labels ((integer-gcd-sub (n1 n2)
    2004              (if (eql n2 0)
    2005                n1
    2006                (if (and (typep n1 'fixnum) (typep n2 'fixnum))
    2007                  (%fixnum-gcd n1 n2)
    2008                  (integer-gcd-sub n2
    2009                                   (if (> n2 n1)
    2010                                     (rem n2 n1)
    2011                                     (rem n1 n2))))))
    2012            (gcd-larger-smaller (n1 n2)
    2013              (if (> n1 n2)
    2014                (integer-gcd-sub n1 n2)
    2015                (integer-gcd-sub n2 n1))))
    2016     (with-negated-bignum-buffers n1 n2 gcd-larger-smaller)))
    2017 
    2018 #+fix-later
    20192002(defun %bignum-bignum-gcd (u0 v0)
    20202003  (let* ((u-len (%bignum-length u0))
     
    20442027             (v-trailing-0-digits (ash v-trailing-0-bits -5)))
    20452028        (declare (fixnum u-trailing-0-bits v-trailing-0-bits))
    2046         (bignum-shift-right-loop-1
    2047          (logand u-trailing-0-bits 31)
    2048          u2
    2049          u
    2050          (the fixnum (1- (the fixnum (- u-len u-trailing-0-digits ))))
    2051          u-trailing-0-digits)
    2052         (rotatef u u2)
    2053         (%mostly-normalize-bignum-macro u)
    2054         (setq u-len (%bignum-length u))
    2055         (bignum-shift-right-loop-1
    2056          (logand v-trailing-0-bits 31)
    2057          v2
    2058          v
    2059          (the fixnum (1- (the fixnum (- v-len v-trailing-0-digits))))
    2060          v-trailing-0-digits)
    2061         (rotatef v v2)
    2062         (%mostly-normalize-bignum-macro v)
    2063         (setq v-len (%bignum-length v))
     2029        (unless (zerop u-trailing-0-digits)
     2030          (bignum-shift-right-loop-1
     2031           (logand u-trailing-0-bits 31)
     2032           u2
     2033           u
     2034           (the fixnum (1- (the fixnum (- u-len u-trailing-0-digits ))))
     2035           u-trailing-0-digits)
     2036          (rotatef u u2)
     2037          (%mostly-normalize-bignum-macro u)
     2038          (setq u-len (%bignum-length u)))
     2039        (unless (zerop v-trailing-0-bits)
     2040          (bignum-shift-right-loop-1
     2041           (logand v-trailing-0-bits 31)
     2042           v2
     2043           v
     2044           (the fixnum (1- (the fixnum (- v-len v-trailing-0-digits))))
     2045           v-trailing-0-digits)
     2046          (rotatef v v2)
     2047          (%mostly-normalize-bignum-macro v)
     2048          (setq v-len (%bignum-length v)))
    20642049        (let* ((shift (min u-trailing-0-bits
    20652050                           v-trailing-0-bits)))
    20662051          (loop
    20672052              (let* ((fix-u (and (= u-len 1)
    2068                                  (< (the fixnum (%bignum-ref-hi u 0))
    2069                                     (ash 1 14))
     2053                                 (let* ((hi-u (%bignum-ref-hi u 0)))
     2054                                   (declare (fixnum hi-u))
     2055                                   (= hi-u (the fixnum
     2056                                             (logand hi-u (ash most-positive-fixnum -16)))))
    20702057                                 (uvref u 0)))
    20712058                     (fix-v (and (= v-len 1)
    2072                                  (< (the fixnum (%bignum-ref-hi v 0))
    2073                                     (ash 1 14))
     2059                                 (let* ((hi-v (%bignum-ref-hi v 0)))
     2060                                   (declare (fixnum hi-v))
     2061                                   (= hi-v (the fixnum
     2062                                             (logand hi-v (ash most-positive-fixnum -16)))))
    20742063                                 (uvref v 0))))
    20752064                (if fix-v
Note: See TracChangeset for help on using the changeset viewer.