Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3831

Show
Ignore:
Timestamp:
07/31/08 16:16:02 (4 months ago)
Author:
Don Clugston
Message:

Moved bignum 'impl' stuff into internal. Fixed memory alloc bug (man this stuff is subtle!)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/math/internal

    • Property svn:mergeinfo set
  • trunk/tango/math/internal/BignumNoAsm.d

    r3825 r3831  
    77 * This module is intended only to assist development of high-speed routines 
    88 * on currently unsupported processors. 
     9 * The X86 asm version is about 30 times faster than the D version(DMD). 
    910 * 
    1011 * Copyright: Copyright (C) 2008 Don Clugston.  All rights reserved. 
     
    1314 */ 
    1415 
    15 module tango.math.impl.BignumNoAsm; 
     16module tango.math.internal.BignumNoAsm; 
    1617 
    1718public: 
  • trunk/tango/math/internal/BignumX86.d

    r3825 r3831  
    4040 */ 
    4141 
    42 module tango.math.impl.BignumX86; 
     42module tango.math.internal.BignumX86; 
    4343 
    4444/*   
  • trunk/tango/math/internal/BiguintCore.d

    r3829 r3831  
    66 */ 
    77 
    8 module tango.math.impl.BiguintCore; 
    9  
    10 version(GNU) { 
     8module tango.math.internal.BiguintCore; 
     9 
     10version(TangoBignumNoAsm) { 
     11private import tango.math.internal.BignumNoAsm;     
     12} else version(GNU) { 
    1113    // GDC lies about its X86 support 
    12 private import tango.math.impl.BignumNoAsm;     
     14private import tango.math.internal.BignumNoAsm;     
    1315} else version(D_InlineAsm_X86) {  
    14 private import tango.math.impl.BignumX86; 
     16private import tango.math.internal.BignumX86; 
    1517} else { 
    16 private import tango.math.impl.BignumNoAsm; 
     18private import tango.math.internal.BignumNoAsm; 
    1719} 
    1820 
     
    294296        uint chunksize =  y.length + (x.length % y.length); 
    295297        // We make the buffer a bit bigger so we have space for the partial sums. 
    296         uint [] scratchbuff = new uint[karatsubaRequiredBuffSize(chunksize) + y.length * 2]; 
     298        uint [] scratchbuff = new uint[karatsubaRequiredBuffSize(y.length+ chunksize) + y.length * 2+1]; 
    297299        if (y.length == half) { 
    298300            chunksize = x.length - y.length; 
     
    308310            result[done + y.length .. done + y.length + chunksize]  
    309311                = partial[y.length .. y.length + chunksize]; 
    310             simpleAddAssign(result[done .. y.length + chunksize], partial[0 .. y.length]); 
     312            simpleAddAssign(result[done .. done + y.length+chunksize], partial[0 .. y.length]); 
    311313            done += y.length; 
    312314        } 
     
    391393   assert(result.length > right.length); 
    392394   uint c = multibyteAddSub!('+')(result[0..right.length], result[0..right.length], right, 0); 
    393    if (c) c = multibyteIncrementAssign!('+')(result[right.length .. $], c); 
    394    assert(c==0); 
     395   if (c) { 
     396       c = multibyteIncrementAssign!('+')(result[right.length .. $], c); 
     397       assert(c==0); 
     398   } 
    395399} 
    396400 
     
    403407uint karatsubaRequiredBuffSize(uint xlen) 
    404408{ 
    405     return xlen <= KARATSUBALIMIT ? 0 : xlen * 2; 
    406 
    407  
     409    uint half = (xlen >> 1) + (xlen & 1); 
     410    return xlen <= KARATSUBALIMIT ? 0 : 2*half+1 + karatsubaRequiredBuffSize(half); 
     411
     412 
     413//uint lastleftover = 0; 
    408414/* Sets result = x*y, using Karatsuba multiplication. 
    409415* Valid only for balanced multiplies, and x must be longer than y. 
    410416* ie 2*y.length > x.length >= y.length. 
     417* It is efficient only if sqrt(2)*y.length > x.length >= y.length 
    411418* Params: 
    412419* scratchbuff      An array long enough to store all the temporaries. Will be destroyed. 
     
    435442    uint [] ysum = result[half .. half*2]; 
    436443    uint [] mid = scratchbuff[0 .. half*2+1]; 
    437     uint [] newscratchbuff = scratchbuff[half*2+2 .. $]; 
     444    uint [] newscratchbuff = scratchbuff[half*2+1 .. $]; 
    438445    uint [] resultLow = result[0 .. x0.length + y0.length]; 
    439446    uint [] resultHigh = result[x0.length + y0.length .. $];