Changeset 5431


Ignore:
Timestamp:
Oct 29, 2006, 11:24:28 PM (18 years ago)
Author:
Gary Byers
Message:

Enable the destructive version of %BIGNUM-BIGNUM-GCD; conditionalize it
for 64-bit targets and provide/fix supporting functions. Seems to work
on ppc64; needs testing on x8664.

File:
1 edited

Legend:

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

    r3882 r5431  
    18081808
    18091809
    1810 #+(or safe-but-slow 64-bit-target)
     1810#+safe-but-slow
     1811;;; This is basically the same algorithm as the "destructive"
     1812;;; version below; while it may be more readable, it's often
     1813;;; slower and conses too much to be at all viable.
    18111814(defun %bignum-bignum-gcd (u v)
    18121815  (setq u (abs u) v (abs v))
     
    18231826    (setq u (ash u -1) v (ash v -1))))
    18241827
    1825 #-(or safe-but-slow 64-bit-target)
     1828
     1829
     1830
     1831#-safe-but-slow
    18261832(progn
    18271833(defun %positive-bignum-bignum-gcd (u0 v0)
     
    18671873                           v-trailing-0-bits)))
    18681874          (loop
    1869               (let* ((fix-u (and (= u-len 1)
    1870                                  (let* ((hi-u (bignum-ref-hi u 0)))
    1871                                    (declare (fixnum hi-u))
    1872                                    (= hi-u (the fixnum
    1873                                              (logand hi-u (ash most-positive-fixnum -16)))))
    1874                                  (uvref u 0)))
    1875                      (fix-v (and (= v-len 1)
    1876                                  (let* ((hi-v (bignum-ref-hi v 0)))
    1877                                    (declare (fixnum hi-v))
    1878                                    (= hi-v (the fixnum
    1879                                              (logand hi-v (ash most-positive-fixnum -16)))))
    1880                                  (uvref v 0))))
     1875              (let* ((fix-u (and (<= u-len 2)
     1876                                 (%maybe-fixnum-from-one-or-two-digit-bignum u)))
     1877                     (fix-v (and (<= v-len 2)
     1878                                 (%maybe-fixnum-from-one-or-two-digit-bignum v))))
    18811879                (if fix-v
    18821880                  (if fix-u
     
    18851883                  (if fix-u
    18861884                    (return (ash (bignum-fixnum-gcd v fix-u) shift)))))
    1887              
    18881885              (let* ((signum (if (> u-len v-len)
    18891886                               1
     
    19421939
    19431940
     1941;;; nbits can't be zero here.
     1942(defun bignum-shift-right-loop-1 (nbits result source len idx)
     1943  (declare (type bignum-type result source)
     1944           (type (mod 32) nbits)
     1945           (type bignum-index idx len))
     1946  (let* ((rbits (logand 31 (the (mod 32) (- 32 nbits)))))
     1947    (declare (type (mod 32) rbits))
     1948    (dotimes (j len)
     1949      (let* ((x (bignum-ref source idx)))
     1950        (declare (type bignum-element-type x))
     1951        (setq x (%ilsr nbits x))
     1952        (incf idx)
     1953        (let* ((y (bignum-ref source idx)))
     1954          (declare (type bignum-element-type y))
     1955          (setq y (%ilsl rbits y))
     1956          (setf (bignum-ref result j)
     1957                (%logior x y)))))
     1958    (setf (bignum-ref result len)
     1959          (%ilsr nbits (bignum-ref source idx)))
     1960    idx))
     1961   
     1962
    19441963(defun %logcount (bignum idx)
    19451964  (%ilogcount (bignum-ref bignum idx)))
     
    20042023              carry carry-out)))))
    20052024
    2006 (defun %bignum-count-trailing-zerop-bits (bignum)
     2025(defun %bignum-count-trailing-zero-bits (bignum)
    20072026  (let* ((count 0))
    20082027    (dotimes (i (%bignum-length bignum))
     
    20122031          (incf count 32)
    20132032          (progn
    2014             (do* ((bit 31 (1- bit)))
    2015                  ((zerop bit))
     2033            (dotimes (bit 32)
    20162034              (declare (type (mod 32) bit))
    20172035              (if (logbitp bit digit)
Note: See TracChangeset for help on using the changeset viewer.