Changeset 13932
- Timestamp:
- Jul 7, 2010, 11:52:11 AM (14 years ago)
- File:
-
- 1 edited
-
branches/arm/level-0/l0-bignum32.lisp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/arm/level-0/l0-bignum32.lisp
r13889 r13932 1434 1434 1435 1435 1436 ;;; These are used by BIGNUM-TRUNCATE and friends in the general case.1437 ;;;1438 (defvar *truncate-x* nil)1439 (defvar *truncate-y* nil)1440 1436 1441 1437 ;;; BIGNUM-TRUNCATE -- Public. … … 1477 1473 (let* ((len-x+1 (1+ len-x))) 1478 1474 (declare (fixnum len-x+1)) 1479 (with-bignum-buffers (( *truncate-x*len-x+1)1480 ( *truncate-y*(the fixnum (1+ len-y))))1475 (with-bignum-buffers ((truncate-x len-x+1) 1476 (truncate-y (the fixnum (1+ len-y)))) 1481 1477 (let ((y-shift (shift-y-for-truncate y))) 1482 (shift-and-store-truncate-buffers x len-x y len-y y-shift)1483 (values (do-truncate len-x+1 len-y)1478 (shift-and-store-truncate-buffers truncate-x truncate-y x len-x y len-y y-shift) 1479 (values (do-truncate truncate-x truncate-y len-x+1 len-y) 1484 1480 ;; DO-TRUNCATE must execute first. 1485 1481 (when (not no-rem) … … 1487 1483 (let* ((res-len-1 (1- len-y))) 1488 1484 (declare (fixnum res-len-1)) 1489 (bignum-shift-right-loop-1 y-shift *truncate-x* *truncate-x*res-len-1 0)))1490 (let ((the-res (%normalize-bignum-macro *truncate-x*)))1485 (bignum-shift-right-loop-1 y-shift truncate-x truncate-y res-len-1 0))) 1486 (let ((the-res (%normalize-bignum-macro truncate-x ))) 1491 1487 (if (not (fixnump the-res)) 1492 1488 (if x-plusp (copy-bignum the-res) (negate-bignum the-res)) … … 1523 1519 (let* ((len-x+1 (1+ len-x))) 1524 1520 (declare (fixnum len-x+1)) 1525 (with-bignum-buffers (( *truncate-x*len-x+1)1526 ( *truncate-y*(the fixnum (1+ len-y))))1521 (with-bignum-buffers ((truncate-x len-x+1) 1522 (truncate-y (the fixnum (1+ len-y)))) 1527 1523 (let ((y-shift (shift-y-for-truncate y))) 1528 (shift-and-store-truncate-buffers x len-x y len-y y-shift)1529 (do-truncate-no-quo len-x+1 len-y)1524 (shift-and-store-truncate-buffers truncate-x truncate-y x len-x y len-y y-shift) 1525 (do-truncate-no-quo truncate-x truncate-y len-x+1 len-y) 1530 1526 (when (not (eql 0 y-shift)) 1531 1527 (let* ((res-len-1 (1- len-y))) … … 1669 1665 1670 1666 1671 (defun do-truncate ( len-x len-y)1667 (defun do-truncate (truncate-x truncate-y len-x len-y) 1672 1668 (declare (type bignum-index len-x len-y)) 1673 1669 (let* ((len-q (- len-x len-y)) … … 1684 1680 (digit-bind (h l) 1685 1681 (digit-bind (guess-h guess-l) 1686 (bignum-truncate-guess-2 *truncate-x* i *truncate-y*(the fixnum (1- len-y)))1687 (try-bignum-truncate-guess guess-h guess-l len-y low-x-digit))1682 (bignum-truncate-guess-2 truncate-x i truncate-y (the fixnum (1- len-y))) 1683 (try-bignum-truncate-guess truncate-x truncate-y guess-h guess-l len-y low-x-digit)) 1688 1684 (%bignum-set q k h l)) 1689 1685 (cond ((zerop k) (return)) … … 1697 1693 (%normalize-bignum-macro q)))) 1698 1694 1699 (defun do-truncate-no-quo ( len-x len-y)1695 (defun do-truncate-no-quo (truncate-x truncate-y len-x len-y) 1700 1696 (declare (type bignum-index len-x len-y)) 1701 1697 (let* ((len-q (- len-x len-y)) … … 1705 1701 (declare (type bignum-index len-q k i low-x-digit)) 1706 1702 (loop 1707 (digit-bind (guess-h guess-l) (bignum-truncate-guess-2 *truncate-x* i *truncate-y*(the fixnum (1- len-y)))1708 (try-bignum-truncate-guess guess-h guess-l len-y low-x-digit)1703 (digit-bind (guess-h guess-l) (bignum-truncate-guess-2 truncate-x i truncate-y (the fixnum (1- len-y))) 1704 (try-bignum-truncate-guess truncate-x truncate-y guess-h guess-l len-y low-x-digit) 1709 1705 (cond ((zerop k) (return)) 1710 1706 (t (decf k) … … 1726 1722 ;;; 1727 1723 1728 (defun try-bignum-truncate-guess ( guess-h guess-l len-y low-x-digit)1724 (defun try-bignum-truncate-guess (truncate-x truncate-y guess-h guess-l len-y low-x-digit) 1729 1725 (declare (type bignum-index low-x-digit len-y)) 1730 1726 … … 1737 1733 ;; Multiply guess and divisor, subtracting from dividend simultaneously. 1738 1734 (dotimes (j len-y) 1739 (multiple-value-bind (y-h y-l) (%bignum-ref *truncate-y*j)1735 (multiple-value-bind (y-h y-l) (%bignum-ref truncate-y j) 1740 1736 (multiple-value-bind (high-h high-l low-h low-l) 1741 1737 (%multiply-and-add-1 guess-h … … 1747 1743 (setq carry-digit-h high-h 1748 1744 carry-digit-l high-l) 1749 (multiple-value-bind (tx-h tx-l) (%bignum-ref *truncate-x*i)1745 (multiple-value-bind (tx-h tx-l) (%bignum-ref truncate-x i) 1750 1746 (multiple-value-bind (x-h x-l temp-borrow) 1751 1747 (%subtract-with-borrow-1 tx-h tx-l low-h low-l borrow) 1752 (%bignum-set *truncate-x*i x-h x-l)1748 (%bignum-set truncate-x i x-h x-l) 1753 1749 (setq borrow temp-borrow))))) 1754 1750 (incf i)) 1755 (multiple-value-bind (tx-h tx-l) (%bignum-ref *truncate-x*i)1751 (multiple-value-bind (tx-h tx-l) (%bignum-ref truncate-x i) 1756 1752 (multiple-value-bind (x-h x-l) 1757 1753 (%subtract-with-borrow-1 tx-h tx-l carry-digit-h carry-digit-l borrow) 1758 (%bignum-set *truncate-x*i x-h x-l)))1754 (%bignum-set truncate-x i x-h x-l))) 1759 1755 ;; See if guess is off by one, adding one Y back in if necessary. 1760 1756 1761 1757 1762 (cond ((%digit-0-or-plusp *truncate-x*i)1758 (cond ((%digit-0-or-plusp truncate-x i) 1763 1759 (values guess-h guess-l)) 1764 1760 (t … … 1766 1762 ;; in. The guess was one too large in magnitude. 1767 1763 ;; hmm - happens about 1.6% of the time 1768 (bignum-add-loop-+ low-x-digit *truncate-x* *truncate-y*len-y)1764 (bignum-add-loop-+ low-x-digit truncate-x truncate-y len-y) 1769 1765 (%subtract-one guess-h guess-l) 1770 1766 ;(%subtract-with-borrow guess-h guess-l 0 1 1) … … 1834 1830 ;;; it assumes *truncate-x* and *truncate-y* are one digit longer than x and y. 1835 1831 ;;; 1836 (defun shift-and-store-truncate-buffers ( x len-x y len-y shift)1832 (defun shift-and-store-truncate-buffers (truncate-x truncate-y x len-x y len-y shift) 1837 1833 (declare (type bignum-index len-x len-y) 1838 1834 (type (integer 0 (#.digit-size)) shift)) 1839 1835 (cond ((eql 0 shift) 1840 (bignum-replace *truncate-x*x :end1 len-x)1841 (bignum-replace *truncate-y*y :end1 len-y))1836 (bignum-replace truncate-x x :end1 len-x) 1837 (bignum-replace truncate-y y :end1 len-y)) 1842 1838 (t 1843 (bignum-ashift-left-unaligned x 0 shift (the fixnum (1+ len-x)) *truncate-x*)1844 (bignum-ashift-left-unaligned y 0 shift (the fixnum (1+ len-y)) *truncate-y*))))1839 (bignum-ashift-left-unaligned x 0 shift (the fixnum (1+ len-x)) truncate-x) 1840 (bignum-ashift-left-unaligned y 0 shift (the fixnum (1+ len-y)) truncate-y)))) 1845 1841 1846 1842
Note:
See TracChangeset
for help on using the changeset viewer.
