unit FastcodePowerUnit01; //Version : 0.1 Preliminary version //Only direct calling supported interface function PowerFastcodeP3(const Base, Exponent: Extended): Extended; overload; function PowerFastcodeP4(const Base, Exponent: Extended): Extended; overload; function PowerFastcodeXP(const Base, Exponent: Extended): Extended; overload; function PowerFastcodeOpteron(const Base, Exponent: Extended): Extended; overload; function PowerFastcodeRTL(const Base, Exponent: Extended): Extended; overload; function PowerFastcodePascal(const Base, Exponent: Extended): Extended; overload; function PowerFastcodeBlended(const Base, Exponent: Extended): Extended; overload; function PowerFastcodeP3(const Base, Exponent: Double): Double; overload; function PowerFastcodeP4(const Base, Exponent: Double): Double; overload; function PowerFastcodeXP(const Base, Exponent: Double): Double; overload; function PowerFastcodeOpteron(const Base, Exponent: Double): Double; overload; function PowerFastcodeRTL(const Base, Exponent: Double): Double; overload; function PowerFastcodePascal(const Base, Exponent: Double): Double; overload; function PowerFastcodeBlended(const Base, Exponent: Double): Double; overload; function PowerFastcodeP3(const Base, Exponent: Single): Single; overload; function PowerFastcodeP4(const Base, Exponent: Single): Single; overload; function PowerFastcodeXP(const Base, Exponent: Single): Single; overload; function PowerFastcodeOpteron(const Base, Exponent: Single): Single; overload; function PowerFastcodeRTL(const Base, Exponent: Single): Single; overload; function PowerFastcodePascal(const Base, Exponent: Single): Single; overload; function PowerFastcodeBlended(const Base, Exponent: Single): Single; overload; implementation //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: P3 //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeP3(const Base, Exponent: Extended): Extended; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: P4 //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeP4(const Base, Exponent: Extended): Extended; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: XP //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeXP(const Base, Exponent: Extended): Extended; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: RTL //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeRTL(const Base, Exponent: Extended): Extended; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Pascal //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodePascal(const Base, Exponent: Extended): Extended; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Blended //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeBlended(const Base, Exponent: Extended): Extended; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: Opteron //Instructionset(s): IA32 //Original name: PowerDKCIA32_3 function PowerFastcodeOpteron(const Base, Exponent: Extended): Extended; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 fnstcw [esp-12].Word //Get current controlword mov ax,$1372 mov [esp-8], ax fldcw word ptr [esp-8] //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $18 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: P4 //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeP4(const Base, Exponent: Double): Double; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: XP //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeXP(const Base, Exponent: Double): Double; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: RTL //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeRTL(const Base, Exponent: Double): Double; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: Pascal //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodePascal(const Base, Exponent: Double): Double; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: Blended //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeBlended(const Base, Exponent: Double): Double; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: P3 //Instructionset(s): IA32 //Original name: PowerDKCIA32_2 function PowerFastcodeP3(const Base, Exponent: Double): Double; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 wait mov esp,ebp pop ebp ret $10 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) wait mov esp,ebp pop ebp ret $10 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 wait mov esp,ebp pop ebp ret $10 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp wait mov esp,ebp pop ebp ret $10 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr wait mov esp,ebp pop ebp ret $10 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp pop ebp ret $10 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp pop ebp ret $10 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) wait mov esp,ebp pop ebp ret $10 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: Opteron //Instructionset(s): IA32 //Original name: PowerDKCIA32_2 function PowerFastcodeOpteron(const Base, Exponent: Double): Double; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 wait mov esp,ebp pop ebp ret $10 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) wait mov esp,ebp pop ebp ret $10 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 wait mov esp,ebp pop ebp ret $10 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) wait mov esp,ebp pop ebp ret $10 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp wait mov esp,ebp pop ebp ret $10 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr wait mov esp,ebp pop ebp ret $10 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp pop ebp ret $10 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp pop ebp ret $10 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) wait mov esp,ebp pop ebp ret $10 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: P4 //Instructionset(s): IA32 //Original name: PowerDKCIA32_2 function PowerFastcodeP4(const Base, Exponent: Single): Single; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 wait mov esp,ebp pop ebp ret $8 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) wait mov esp,ebp pop ebp ret $8 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 wait mov esp,ebp pop ebp ret $8 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) wait mov esp,ebp pop ebp ret $8 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) wait mov esp,ebp pop ebp ret $8 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) wait mov esp,ebp pop ebp ret $8 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) wait mov esp,ebp pop ebp ret $8 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp wait mov esp,ebp pop ebp ret $8 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr wait mov esp,ebp pop ebp ret $8 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp pop ebp ret $8 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp pop ebp ret $8 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) wait mov esp,ebp pop ebp ret $8 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: P3 //Instructionset(s): IA32 //Original name: PowerDKCIA32_3 function PowerFastcodeP3(const Base, Exponent: Single): Single; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 fnstcw [esp-12].Word //Get current controlword mov ax,$1372 mov [esp-8], ax fldcw word ptr [esp-8] //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: XP //Instructionset(s): IA32 //Original name: PowerDKCIA32_3 function PowerFastcodeXP(const Base, Exponent: Single): Single; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 fnstcw [esp-12].Word //Get current controlword mov ax,$1372 mov [esp-8], ax fldcw word ptr [esp-8] //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 31/12 2003 //Optimized for: Blended //Instructionset(s): IA32 //Original name: PowerDKCIA32_3 function PowerFastcodeBlended(const Base, Exponent: Single): Single; overload; const MAXINTFP : Extended = $7fffffff; asm sub esp,$14 fnstcw [esp-12].Word //Get current controlword mov ax,$1372 mov [esp-8], ax fldcw word ptr [esp-8] //if (Abs(Exponent) <= MaxInt) then fld MAXINTFP fld Exponent fld st(0) fabs fcomp st(2) fstsw ax sahf ffree st(1) jae @IfEnd1 //Y := Round(Exponent); fld st(0) frndint fist dword ptr [esp] fcomp st(1) fstsw ax sahf ffree st(0) jnz @IfEnd2 //Result := IntPowerDKCIA32_4e(Base, Y) //if Base = 0 then fldz fld Base fcom st(1) fstsw ax sahf jnz @IntPowIfEnd2 //if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElse2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElse2 : //ResultX := 0; fxch st(1) ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowIfEnd2 : //else if Exponent = 0 then mov ecx,[esp] test ecx,ecx jnz @IntPowElseIf2 //ResultX := 1 ffree st(1) ffree st(0) fld1 fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf2 : //else if Exponent = 1 then cmp ecx,1 jnz @IntPowElseIf3 //ResultX := Base ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf3 : //else if Exponent = 2 then cmp ecx,2 jnz @IntPowElseIf4 //ResultX := Base * Base ffree st(1) fmul st(0),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf4 : //else if Exponent > 2 then cmp ecx,2 jle @IntPowElseIf5 ffree st(1) //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) mov eax,ecx //I := 2; mov edx,2 //I2 := Exponent; @IntPowRepeat1Start : //I2 := I2 shr 1; shr ecx,1 jnc @IntPowIfEnd8 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd8 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add edx,edx //until(I > Exponent); cmp eax,edx jnl @IntPowRepeat1Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf5 : //else if Exponent = -1 then cmp ecx,-1 jnz @IntPowElseIf6 ffree st(1) //ResultX := 1/Base fld1 fdivrp st(1),st(0) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElseIf6 : //else if Exponent = -2 then cmp ecx,-2 jnz @IntPowElse7 //ResultX := 1/(Base*Base) ffree st(1) fmul st(0),st(0) fld1 fdivrp fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IntPowElse7 : ffree st(1) //else //if Exponent < -2 then //I2 := -Exponent; mov eax,ecx neg eax mov edx,eax //I := 2; mov ecx,2 //ResultX2 := 1; fld1 //ResultX := Base; fxch st(1) @IntPowRepeat2Start : //I2 := I2 shr 1; shr eax,1 jnc @IntPowIfEnd7 //ResultX2 := ResultX2 * ResultX; fmul st(1),st(0) @IntPowIfEnd7 : //ResultX := ResultX * ResultX; fmul st(0),st(0) //I := I * 2; add ecx,ecx //until(I > -Exponent); cmp ecx,edx jle @IntPowRepeat2Start //ResultX := ResultX * ResultX2; fmulp st(1),st(0) //ResultX := 1 / ResultX; fld1 fdivr fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd2 : //Result := Exp(Exponent * Ln(Base)) fld Base fldln2 fxch st(1) fyl2x fld Exponent fmulp fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd1 : //if (Exponent > 0) and (Base <> 0) then fldz fcom st(1) fstsw ax sahf jbe @IfEnd3 fld Base fcom st(1) fstsw ax sahf jz @IfEnd3 ffree st(1) //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0), st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @IfEnd3 : //else if Base = 0 then fld Base fcom st(1) fstsw ax sahf ffree st(1) jnz @ElseIfEnd4 //Result := 0 ffree st(2) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp pop ebp ret $8 @ElseIfEnd4 : //Result := Exp(Exponent * Ln(Base)) fldln2 fxch st(1) fyl2x fmul st(0),st(2) ffree st(2) fldl2e fmulp fld st(0) frndint fsub st(1),st(0) fxch st(1) f2xm1 fld1 faddp fscale ffree st(1) fldcw word ptr [esp-12] //Restore controlword wait mov esp,ebp end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: Opteron //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodeOpteron(const Base, Exponent: Single): Single; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: Pascal //Instructionset(s): IA32 //Original name: PowerDKCPas4 function PowerFastcodePascal(const Base, Exponent: Single): Single; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPower(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; //Author: Dennis Kjaer Christensen //Date: 15/10 2003 //Optimized for: RTL //Instructionset(s): IA32 //Original name: PowerDKCIA32_1 function PowerFastcodeRTL(const Base, Exponent: Single): Single; overload; var Y : Integer; begin if (Abs(Exponent) <= MaxInt) then begin Y := Round(Exponent); if (Exponent = Y) then Result := IntPowerDKCIA32_1(Base, Y) else Result := Exp(Exponent * Ln(Base)) end else begin if (Base <> 0) and (Exponent > 0) then Result := Exp(Exponent * Ln(Base)) else if Base = 0 then Result := 0 else Result := Exp(Exponent * Ln(Base)) end; end; end.