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

Changeset 3911

Show
Ignore:
Timestamp:
08/25/08 02:53:21 (3 months ago)
Author:
Don Clugston
Message:

Asm implementation of subMul. This speeds up division enormously.

Files:

Legend:

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

    r3900 r3911  
    426426uint multibyteMulAdd(char op)(uint [] dest, uint[] src, uint multiplier, uint carry) 
    427427{ 
    428     static if (op=='-') { 
    429       /* This is equivalent to: 
    430         --- 
    431         uint [] tmp = new uint[src.length]; 
    432         uint c = multibyteMul(tmp, src, multiplier, carry); 
    433         return c + multibyteAddSub!('-')(dest, dest, tmp, 0); 
    434         --- 
    435       */ 
    436         ulong c = carry; 
    437         for (int i = 0; i < src.length; i++) { 
    438             c += cast(ulong)multiplier * src[i]; 
    439             ulong t = cast(ulong)dest[i] - cast(uint)c; 
    440             dest[i] = cast(uint)t; 
    441             c = cast(uint)((c>>32) - (t>>32));         
    442         } 
    443         return cast(uint)c;   
    444    } else { 
    445  
    446  
    447428    // Timing: This is the most time-critical bignum function. 
    448429    // Pentium M: 5.4 cycles/operation, still has 2 resource stalls + 1 load block/iteration 
     
    467448    // ESI = src 
    468449     
     450    const char [] OP = (op=='+')? "add" : "sub"; 
    469451    version(D_PIC) { 
    470452        enum { zero = 0 } 
     
    478460     
    479461    enum { LASTPARAM = 5*4 } // 4* pushes + return address. 
     462mixin("         
    480463    asm { 
    481464        naked; 
     
    510493 
    511494        mul int ptr [ESP+LASTPARAM]; 
    512  
    513         add [-4+EDI+4*EBX], EBP; 
     495" ~ OP ~ " [-4+EDI+4*EBX], EBP; 
    514496        mov EBP, zero; 
    515497     
     
    523505L1: 
    524506        mul int ptr [ESP+LASTPARAM]; 
    525         add [-8+EDI+4*EBX], ECX; 
     507        " ~ OP ~ " [-8+EDI+4*EBX], ECX; 
    526508        mov ECX, zero; 
    527509  
     
    538520    asm {         
    539521        mul int ptr [ESP+LASTPARAM]; 
    540         add [-4+EDI+4*EBX], EBP; 
     522        " ~ OP ~ " [-4+EDI+4*EBX], EBP; 
    541523        mov EBP, zero; 
    542524     
     
    547529        add EBX, 2; 
    548530        jl L1; 
    549 L_done: 
    550         add [-8+EDI+4*EBX], ECX; 
     531L_done: " ~ OP ~ " [-8+EDI+4*EBX], ECX; 
    551532        mov EAX, EBP; // get final carry 
    552533        adc EAX, 0; 
     
    567548        jl L1; 
    568549        jmp L_done; 
    569  
    570      } 
    571  }// op=='+' 
     550     } "); 
    572551} 
    573552