File: bignum

package info (click to toggle)
gcl 2.6.14-19
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 60,804 kB
  • sloc: ansic: 177,407; lisp: 151,508; asm: 128,169; sh: 22,510; cpp: 11,923; tcl: 3,181; perl: 2,930; makefile: 2,360; sed: 334; yacc: 226; lex: 95; awk: 30; fortran: 24; csh: 23
file content (60 lines) | stat: -rw-r--r-- 2,486 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


A directory mp was added to hold the new multi precision arithmetic
code.  The layout and a fair amount of code in the mp directory is an
enhanced version of gpari version 34. The gpari c code was rewritten
to be more efficient, and gcc assembler macros were added to allow
inlining of operations not possible to do in C.  On a 68K machine,
this allows the C version to be as efficient as the very carefully
written assembler in the gpari distribution.  For the main machines,
an assembler file (produced by gcc) based on this new method, is
included.   This is for sites which do not have gcc, or do not
wish to compile the whole system with gcc.

Bignum arithmetic is much faster now.  Many changes were made to
cmpnew also, to add 'integer' as a new type.  It differs from
variables of other types, in that storage is associated to each such
variable, and assignments mean copying the storage.  This allows a
function which does a good deal of bignum arithmetic, to do very
little consing in the heap.  An example is the computation of PI-INV
in scratchpad, which calculates the inverse of pi to a prescribed
number of bits accuracy.  That function is now about 20 times faster,
and no longer causes garbage collection.  In versions of AKCL  where
HAVE_ALLOCA is defined, the temporary storage growth is on the C
stack, although this often not so critical (for example it makes
virtually no difference in the PI-INV example, since in spite of the
many operations, only one storage allocation takes place.
	
Below is the actual code for PI-INV

On a sun3/280 (cli.com)

Here is the comparison of lucid and akcl before and after
on that pi-inv.   Times are in seconds with multiples of the
akcl time in parentheses.

On a sun3/280 (cli.com)

pi-inv   akcl-566  franz        lucid         old kcl/akcl
----------------------------------------
10000      3.3     9.2(2.8 X)  15.3 (4.6X)    92.7   (29.5 X)
20000      12.7    31.0(2.4 X) 62.2 (4.9X)    580.0  (45.5 X)


(defun pi-inv (bits &aux (m 0))
  (declare (integer bits m))
  (let* ((n (+ bits (integer-length bits) 11))
         (tt (truncate (ash 1 n) 882))
         (d (* 4 882 882))
         (s 0))
    (declare (integer s d tt n))
    (do ((i 2 (+ i 2))
         (j 1123 (+ j 21460)))
        ((zerop tt) (cons s (- (+ n 2))))
      (declare (integer i j))
        (setq s (+ s (* j tt))
              m (- (* (- i 1) (- (* 2 i) 1) (- (* 2 i) 3)))
              tt (truncate (* m tt) (* d (the integer (expt i 3))))))))