new optimized version

This commit is contained in:
zueuk 2007-10-28 13:26:48 +00:00
parent f2c7a7c1c5
commit e647e5481b

View File

@ -6,6 +6,7 @@ uses
BaseVariation, XFormMan; BaseVariation, XFormMan;
const const
var_name = 'julian';
var_n_name='julian_power'; var_n_name='julian_power';
var_c_name='julian_dist'; var_c_name='julian_dist';
@ -17,8 +18,8 @@ type
N: integer; N: integer;
c: double; c: double;
rN: integer; absN: integer;
cn: double; cN, vvar2: double;
procedure CalcPower1; procedure CalcPower1;
procedure CalcPowerMinus1; procedure CalcPowerMinus1;
@ -46,7 +47,7 @@ type
implementation implementation
uses uses
math; Math;
// TVariationJulian // TVariationJulian
@ -59,8 +60,10 @@ end;
procedure TVariationJulian.Prepare; procedure TVariationJulian.Prepare;
begin begin
rN := abs(N); absN := abs(N);
cn := c / N / 2; cN := c / N / 2;
vvar2 := vvar * sqrt(2)/2;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -83,36 +86,20 @@ var
r: double; r: double;
sina, cosa: extended; sina, cosa: extended;
begin begin
sincos((arctan2(FTy^, FTx^) + 2*pi*random(rn)) / N, sina, cosa); sincos((arctan2(FTy^, FTx^) + 2*pi*random(absN)) / N, sina, cosa);
r := vvar * Math.Power(sqr(FTx^) + sqr(FTy^), cn); r := vvar * Math.Power(sqr(FTx^) + sqr(FTy^), cN);
FPx^ := FPx^ + r * cosa; FPx^ := FPx^ + r * cosa;
FPy^ := FPy^ + r * sina; FPy^ := FPy^ + r * sina;
{$else} {$else}
asm asm
mov edx, [eax + FTx] mov edx, [eax + FTx]
fld qword ptr [edx + 8] fld qword ptr [edx] // FTx
fld qword ptr [eax + cn] fld qword ptr [edx + 8] // FTy
// mov edx, [eax + FTx] fld qword ptr [eax + cN]
fld qword ptr [edx]
fld st(2) fld st(2)
fld st(1)
fpatan
mov ecx, eax
mov eax, dword ptr [eax + rN]
call System.@RandInt
push eax
fild dword ptr [esp]
add esp, 4
fldpi
fadd st, st
fmulp
faddp
fidiv dword ptr [ecx + N]
fxch st(3)
fmul st, st fmul st, st
fxch st(1) fld st(2)
fmul st, st fmul st, st
faddp faddp
// --- x^y = 2^(y*log2(x)) // --- x^y = 2^(y*log2(x))
@ -127,17 +114,29 @@ asm
fscale fscale
fstp st(1) fstp st(1)
// --- // ---
fmul qword ptr [ecx + vvar] fmul qword ptr [eax + vvar]
fxch st(1)
fsincos
fmul st, st(2)
fxch st(2)
fpatan
mov ecx, eax
mov eax, dword ptr [eax + absN]
call System.@RandInt
push eax
fild dword ptr [esp]
add esp, 4
fldpi
fadd st, st
fmulp
faddp
fidiv dword ptr [ecx + N]
fsincos
fmul st, st(2)
mov edx, [ecx + FPx] mov edx, [ecx + FPx]
fadd qword ptr [edx] fadd qword ptr [edx] // FPx
fstp qword ptr [edx] fstp qword ptr [edx]
fmulp fmulp
// mov edx, [ecx + FPy] fadd qword ptr [edx + 8] // FPy
fadd qword ptr [edx + 8]
fstp qword ptr [edx + 8] fstp qword ptr [edx + 8]
fwait fwait
{$endif} {$endif}
@ -146,53 +145,48 @@ end;
procedure TVariationJulian.CalcPower2; procedure TVariationJulian.CalcPower2;
{$ifndef _ASM_} {$ifndef _ASM_}
var var
r: double; d: double;
sina, cosa: extended;
begin begin
sincos((arctan2(FTy^, FTx^)/2 + pi*random(2)), sina, cosa); d := sqrt( sqrt(sqr(FTx^) + sqr(FTy^)) + FTx^ );
r := vvar * sqrt(sqrt(sqr(FTx^) + sqr(FTy^)));
FPx^ := FPx^ + r * cosa; if random(2) = 0 then begin
FPy^ := FPy^ + r * sina; FPx^ := FPx^ + vvar2 * d;
FPy^ := FPy^ + vvar2 / d * FTy^;
end
else begin
FPx^ := FPx^ - vvar2 * d;
FPy^ := FPy^ - vvar2 / d * FTy^;
end;
{$else} {$else}
asm asm
mov edx, [eax + FTx] mov edx, [eax + FTx]
fld qword ptr [edx + 8] fld qword ptr [edx + 8] // FTy
// mov edx, [eax + FTx] fld qword ptr [edx] // FTx
fld qword ptr [edx]
fld st(1) fld st(1)
fmul st,st
fld st(1) fld st(1)
fpatan fmul st,st
fld1 faddp
fadd st, st fsqrt
fdivp st(1), st faddp
mov ecx, eax fsqrt
mov eax, 2
fld qword ptr [eax + vvar2]
mov ecx,eax
mov eax,2
call System.@RandInt call System.@RandInt
fldpi shr eax,1
push eax jc @skip
fimul dword ptr [esp] fchs
add esp, 4 @skip:
faddp
fxch st(2) fmul st(2),st
fmul st, st fmul st,st(1)
fxch st(1)
fmul st, st
faddp
fsqrt
fsqrt
fmul qword ptr [ecx + vvar]
fxch st(1)
fsincos
fmul st, st(2)
mov edx, [ecx + FPx] mov edx, [ecx + FPx]
fadd qword ptr [edx] fadd qword ptr [edx]
fstp qword ptr [edx] fstp qword ptr [edx]
fmulp fdivp st(1),st
// mov edx, [ecx + FPy]
fadd qword ptr [edx + 8] fadd qword ptr [edx + 8]
fstp qword ptr [edx + 8] fstp qword ptr [edx + 8]
fwait fwait
@ -202,54 +196,59 @@ end;
procedure TVariationJulian.CalcPowerMinus2; procedure TVariationJulian.CalcPowerMinus2;
{$ifndef _ASM_} {$ifndef _ASM_}
var var
r: double; r, xd: double;
sina, cosa: extended;
begin begin
sincos((arctan2(FTy^, FTx^)/2 + pi*random(2)), sina, cosa); r := sqrt(sqr(FTx^) + sqr(FTy^));
r := vvar / sqrt(sqrt(sqr(FTx^) + sqr(FTy^))); xd := r + FTx^;
FPx^ := FPx^ + r * cosa; r := vvar / sqrt(r * (sqr(Fty^) + sqr(xd)) );
FPy^ := FPy^ - r * sina;
if random(2) = 0 then begin
FPx^ := FPx^ + r * xd;
FPy^ := FPy^ - r * FTy^;
end
else begin
FPx^ := FPx^ - r * xd;
FPy^ := FPy^ + r * FTy^;
end;
{$else} {$else}
asm asm
mov edx, [eax + FTx] mov edx, [eax + FTx]
fld qword ptr [edx + 8] fld qword ptr [edx + 8]
// mov edx, [eax + FTx]
fld qword ptr [edx] fld qword ptr [edx]
fld st(1) fld st(1)
fmul st,st
fld st(1) fld st(1)
fpatan fmul st,st
fld1
fadd st, st
fdivp st(1), st
mov ecx, eax
mov eax, 2
call System.@RandInt
fldpi
push eax
fimul dword ptr [esp]
add esp, 4
faddp
fxch st(2)
fmul st, st
fxch st(1)
fmul st, st
faddp faddp
fsqrt fsqrt
fsqrt fadd st(1),st
fdivr qword ptr [ecx + vvar] fld st(1)
fxch st(1) fmul st,st
fld st(3)
fsincos fmul st,st
faddp
fmul st, st(2)
mov edx, [ecx + FPx]
fadd qword ptr [edx]
fstp qword ptr [edx]
fmulp fmulp
// mov edx, [ecx + FPy] fsqrt
fsubr qword ptr [edx + 8]
fdivr qword ptr [eax + vvar]
mov ecx,eax
mov eax,2
call System.@RandInt
shr eax,1
jc @skip
fchs
@skip:
fmul st(1),st
fmulp st(2),st
mov edx, [ecx + FPx]
fsubr qword ptr [edx]
fstp qword ptr [edx]
fadd qword ptr [edx + 8]
fstp qword ptr [edx + 8] fstp qword ptr [edx + 8]
fwait fwait
{$endif} {$endif}
@ -263,9 +262,9 @@ begin
{$else} {$else}
asm asm
mov edx, [eax + FTx] //[eax + FTy] mov edx, [eax + FTx] //[eax + FTy]
fld qword ptr [edx + 8]
// mov edx, [eax + FTx]
fld qword ptr [edx] fld qword ptr [edx]
// mov edx, [eax + FTx]
fld qword ptr [edx + 8]
fld qword ptr [eax + vvar] fld qword ptr [eax + vvar]
fmul st(2), st fmul st(2), st
fmulp fmulp
@ -321,7 +320,7 @@ end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class function TVariationJulian.GetName: string; class function TVariationJulian.GetName: string;
begin begin
Result := 'julian'; Result := var_name;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////