[gambit-list] Patch for _univlib.scm to enable fast bignum arithmetic in javascript backend.
Bradley Lucier
lucier at math.purdue.edu
Mon Jan 18 16:33:07 EST 2016
The limits on the size of bignums where ffts are used still need to be
changed, but here is a patch for _univlib.scm that adds the primitives.
Change _num.scm to have
(macro-case-target
((C)
(c-declare "#include \"mem.h\"")
(##define-macro (use-fast-bignum-algorithms) #t))
(else
(##define-macro (use-fast-bignum-algorithms) #t)))
Add -never-return-jump to the makefile for _gambit.js.
Apply this patch to _univlib.scm.
Brad
-------------- next part --------------
===================================================================
RCS file: RCS/_univlib.scm,v
retrieving revision 1.1
diff -r1.1 _univlib.scm
245a246,284
> ;; different from C backend
>
> (define ##bignum.fdigit-width 7)
>
> ;; Same as C backend
> (define ##bignum.fdigit-base
> (##fxarithmetic-shift-left 1 ##bignum.fdigit-width))
>
> ;; Different again
>
> (define ##bignum.fdigit-mask
> (##fx- ##bignum.fdigit-base 1))
>
> ;; There are two fdigits for every mdigit, so we just manipulate mdigits
>
> (define-prim (##bignum.fdigit-length x)
> (fx* (##bignum.mdigit-length x) 2))
>
> (define-prim (##bignum.fdigit-ref x i)
> (let ((mdigit (##bignum.mdigit-ref x (##fxquotient i 2))))
> (if (##fxeven? i)
> (##fxand mdigit ##bignum.fdigit-mask)
> (##fxarithmetic-shift-right mdigit ##bignum.fdigit-width))))
>
> (define-prim (##bignum.fdigit-set! x i fdigit)
> (let* ((i/2 (##fxquotient i 2))
> (mdigit (##bignum.mdigit-ref x i/2))
> (new-mdigit
> (if (##fxeven? i)
> (##fxior (##fxand (##fxnot ##bignum.fdigit-mask)
> mdigit)
> fdigit)
> (##fxior (##fxarithmetic-shift-left fdigit ##bignum.fdigit-width)
> (##fxand mdigit ##bignum.fdigit-mask)))))
> (##bignum.mdigit-set! x i/2 new-mdigit)))
>
>
> ;;;--------------------------------------------------------------------
>
More information about the Gambit-list
mailing list