Autor Beitrag
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Sa 09.04.05 08:10 
Hi Leute,
ich brauche eine schnellere Funktion, die Power ersetzt. Also kennt jemand von euch einen Weg die Potenzierung ohne Power und natürlich schneller durchzuführen??

MfG, ScorpionKing!


Moderiert von user profile iconmatze: Topic aus Off Topic verschoben am Sa 09.04.2005 um 10:36

_________________
Aus dem Urlaub zurück!
Phobeus
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1280

Linux (FC6), WinXP Pro (Box)
D6 Pers, D7 Pro, FPC 2.x
BeitragVerfasst: Sa 09.04.05 09:35 
SHL? Wobei ich mir fast sicher bin, dass Power darauf zurpckgreift.

_________________
"Menschen sterben nicht wenn man sie zu Grabe trägt, sondern wenn sie ihre Träume verlieren..."
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Sa 09.04.05 10:02 
user profile iconPhobeus hat folgendes geschrieben:
SHL? Wobei ich mir fast sicher bin, dass Power darauf zurpckgreift.
Power selbst nicht, höchstens der Compiler bei der Optimierung, aber selbst da wäre ich mich nicht sehr sicher...

Du könntest mal in den Fließkommabefehlssätzen (FPU, SSE, SSE2, 3DNow! und wie sie nicht alle heißen) nach einem Befehl suchen, der die Potenz ausrechnet. Ich habe eben beim Überfliegen der Standard-FPU-Befehle nichts gefunden, aber vielleicht findest du ja was.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 09.04.05 11:09 
guck dir mal den code von delphifans typarser an. dadrin ist ne assembler power funktion, wenn ich mich richtig erinnere.

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
ScorpionKing Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Sa 09.04.05 12:19 
ja, okay, werde ich machen! danke!

_________________
Aus dem Urlaub zurück!
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: So 10.04.05 18:32 
Wenn du immer zur gleichen Basis die Potenz berechnest, kannst du ja mal mit ln() und exp() herumspielen und das ln()-Ergebnis zwischenspeichern.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 10.04.05 20:19 
Zum Wurzeln ziehen nutz ich diesen Source:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
    PUSH    EAX
    FILD    DWORD PTR [ESP]

    FLDLN2
    FLD     TBYTE PTR [A]               // Load the input number
    FYL2X                               // Get the log out of it
    FDIVRP                              // Divide the log by N to get the N-th root's log
    FLDL2E                              // Calc e^(ln(N-th root)) --> N-th root
    FMULP   ST(1), ST(0)
    FLD     ST(0)
    FRNDINT
    FSUB    ST(1), ST(0)
    FXCH    ST(1)
    F2XM1
    FLD1
    FADDP
    FSCALE
    FSTP    ST(1)

    POP     EAX


Wenn Du das FDIVRP in Zeile 7 durch FMULP ersetzt, kannst Du damit Potenzieren. Davor gingen aber glaube für's reine Potenzieren noch einige Zeilen wegzulassen. Der kann aber speziell am Anfang noch etwas optimiert werden.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mo 11.04.05 12:49 
Wenn ich jetzt noch wüsste, wo meine Assemblerversion von Power rumliegt ... :gruebel:

Edit: Gefunden! Und sogar kommentiert ...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
function xfPower(a,b : Extended) : Extended;
asm
  ffree st(0)
  ffree st(1)
  fld   b          //b laden
  fld   a          //a laden
  fyl2x            //b*ln(a)
  fst   st(1)      //in st(1) kopieren
  frndint          //runden
  fsub  st(1),st   //Vorkommaanteil auf 0 setzen
  fld1             //1 laden
  fscale           //temp:="2 hoch Integer-Anteil"
  fld   st(2)      //Nachkommaanteil laden
  f2xm1            //"2 hoch Nachkommaanteil -1"
  fld1             //1 laden
  faddp st(1),st   //+1
  fmulp st(1),st   //*temp
end;

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!


Zuletzt bearbeitet von .Chef am Mo 11.04.05 13:02, insgesamt 1-mal bearbeitet
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.04.05 13:00 
BAsierend auf meinem Src aus dem vorigen Src, müsste das etwa so hier funktionieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Function ASMPower(A, B:Extended): Extended;
asm
    FLD     TBYTE PTR [B]
    FLDLN2
    FLD     TBYTE PTR [A]               // Load the input number
    FYL2X                               // Get the log out of it
    FMULP                               // Multiply the log by N to get the N-th powers's log
    FLDL2E                              // Calc e^(ln(a)*B) --> A^^B
    FMULP   ST(1), ST(0)
    FLD     ST(0)
    FRNDINT
    FSUB    ST(1), ST(0)
    FXCH    ST(1)
    F2XM1
    FLD1
    FADDP
    FSCALE
    FSTP    ST(1)
end;


Weiß aber jetzt grad nicht, in wie weit, ab dem FLDL2E noch was optimiert werden kann.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mo 11.04.05 13:04 
Ach ja, sooo viel schneller als das normale Power ist meine Funktion nicht. Braucht etwa reichlich die Hälfte der Zeit ...

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.04.05 13:17 
Ab Zeile 8 entspricht meine Funktion dem normalen Power, was auch von Delphi genutzt wird. Ginge das noch optimaler?

@Chef: Wie sieht denn deine aus?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mo 11.04.05 13:21 
user profile iconBenBE hat folgendes geschrieben:
@Chef: Wie sieht denn deine aus?
Siehe oben, habs reineditiert.

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Mo 11.04.05 13:26 

_________________
Ciao, Sprint.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.04.05 19:47 
@Chef: Wozu die beiden FFREE-Zeilen am Anfang? Können die nicht weg?
Wenn die nur zum Freigeben von zwei Registern sind, dann werden sie nicht benötigt, da Delphi selber für einen leeren FPU-Stack sorgt (bei eigenen Routinen) und jegliche anderen Routinen ihre Daten auch wieder abräumen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 11.04.05 19:53 
Übrigens: Meine Funktion ist mehr oder weniger nur eine geinlinte Version von Power :D
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mo 11.04.05 20:12 
@Ben: Keine Ahnung, was Delphi macht. Ich bin schließlich "Vintage"-Asm-Programmierer ...

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 11.04.05 20:15 
@ScorpionKing: Ist deine Basis/Exponent ganzzahlig? Benützst du eine vorgegebene Basis (z.B. e)?
Übrigens: Für x^2 solltest du stets sqr(x) benützen und nicht Power(x,2) und auch nicht x*x.
Für ein ganz allgemeines "Hoch" wirst du wohl nichts finden, was viel schneller ist als Power.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.04.05 20:29 
Naja, für y=x^2 kann man in ASM folgendes nehmen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Function Sqr(var X: Extended): Extended;
asm
    FLD     TBYTE PTR [X]
    FMUL    ST(0), ST(0)
end;


Für x^(2^n) braucht man einfach nur Zeile 4 wiederholen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Function Power2N(var X: Extended; N: DWORD): Extended;
asm
    FLD     TBYTE PTR [X]
    MOV     ECX, N
    INC     ECX
    JMP     @@Start
@@Loop:
    FMUL    ST(0), ST(0)
@@Start:
    DEC     ECX
    JNS     @@Loop:
end;


//Edit: Source gefixt.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ScorpionKing Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Di 12.04.05 14:13 
danke! ihr habt mir schon sehr gut geholfen!

_________________
Aus dem Urlaub zurück!
ScorpionKing Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Mi 13.04.05 13:21 
und gibt es dazu auch ein tutorial? (also zur berechnung mit assembler, wie oben in den power-funktionen verwendet?)

_________________
Aus dem Urlaub zurück!