Autor Beitrag
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 13.01.05 19:25 
Hey, bewundert mal diese Eleganz :)
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Do 13.01.05 20:26 
Spaceguide hat folgendes geschrieben:
Hey, bewundert mal diese Eleganz :)


Hast du gerade im Baströckchen "Schwanensee" getanzt? Sorry, habe ich verpasst .... :lol:

Oder meinst du deinen Code? Doch, ist ganz nett und leichter zu merken und schwerer zu durchschauen, als mein Vorschlag.
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 13.01.05 20:33 
... und um einiges performanter :)

zudem darf man = nicht mit fliesskommazahlen verwenden.
BenBE Threadstarter
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: Fr 14.01.05 00:19 
Spaceguide hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function IsPowerOfTwo(d : dword) : boolean;
begin
  Result := (d>0and (d and (d - 1) = 0);
end;


Moderiert von user profile iconBenBE: Mod-Tag durch eigenen ersetzt


Wäre also in ASM:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function IsPowerOfTwo(Const Value : DWORD) : Boolean;
asm
    TEST EAX, EAX
    JZ @@FinishZ

    MOV EDX, EAX
    DEC EDX

    TEST EAX, EDX

    SETZ AL
    OR AL, AL
@@FinishZ:
    SETNZ AL
end;


Aber die Grundidee ist cool! Muss man wirklich drauf kommen. Absolutes Lob!

_________________
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.
I.MacLeod
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 109



BeitragVerfasst: Sa 15.01.05 16:30 
Wirklich nicht schlecht ;-)

Spaceguide hat folgendes geschrieben:
zudem darf man = nicht mit fliesskommazahlen verwenden.


Darf man glaub ich nur nicht mit Fließkommazahlen verschiedener Typen machen. Solange man Extended mit Extended und Real mit Single (*g*) vergleicht ist alles ok.

@BenBE:

Das or al, al würde ich einfach durch ein ret ersetzen, dann sparst du dir das or und noch ein setCC, und letzteres wird IIRC auf P4s ziemlich langsam ausgeführt.

Hier ist meine Variante:

mir ist noch aufgefallen dass AL ja sowieso schon 0 ist wenn der Sprung genommen wird.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function IsPowerOfTwo(const Value: DWORD) : Boolean;
asm
      TEST EAX, EAX
      JZ @@done

      MOV EDX, EAX
      DEC EDX
   // oder:
   //   LEA EDX, [EAX-1]

      TEST EAX, EDX

      SETZ AL
  @@done:
end;


Ich nehme an die LEA-Variante ist langsamer, aber überprüft hab ichs jetzt nicht.
BenBE Threadstarter
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: Sa 15.01.05 19:11 
I.MacLeod hat folgendes geschrieben:
@BenBE:

Das or al, al würde ich einfach durch ein ret ersetzen, dann sparst du dir das or und noch ein setCC, und letzteres wird IIRC auf P4s ziemlich langsam ausgeführt.


I.MacLeod hat folgendes geschrieben:
Hier ist meine Variante:

mir ist noch aufgefallen dass AL ja sowieso schon 0 ist wenn der Sprung genommen wird.


Das ist richtig. Hab ich glatt übersehen :D. Hab nur erstmal das übersetzt, wie's der Compiler generieren würde ;-)

I.MacLeod hat folgendes geschrieben:
Ich nehme an die LEA-Variante ist langsamer, aber überprüft hab ichs jetzt nicht.

Ne, ganz im Gegenteil, die LEA ist sogar schneller, da du eine Anweisung sparst ... Wenn man ASM-Anweisungen sparen kann, soll mans machen :D

Wäre also die schnellste (bisher gefundene) Variante folgende:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
{$W-} //Stackframes abschalten!

function IsPowerOfTwo(const Value: DWORD) : Boolean; registerassembler;
asm
    TEST EAX, EAX
    RETZ

    LEA EDX, [EAX-1]
    TEST EAX, EDX
    SETZ AL
end;

_________________
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.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 15.01.05 19:28 
RETZ kennt der delphi compiler net ;> und gibbet auch net

=>
jnz @blub
xor eax, eax
ret

@blub
BenBE Threadstarter
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: Sa 15.01.05 20:14 
Da sind ja Z80-Prozessoren fortschrittlicher :D Die können das nämlich :D

Hieße dann korrigiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function IsPowerOfTwo(const Value: DWORD) : Boolean; registerassembler;
asm
    TEST EAX, EAX
    JZ @@Done

    LEA EDX, [EAX-1]
    TEST EAX, EDX
    SETZ AL
@@Done:
end;


Naja, kann passieren, wenn man I386 und Z80 mischt :D

_________________
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.


Zuletzt bearbeitet von BenBE am Sa 15.01.05 23:55, insgesamt 1-mal bearbeitet
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 15.01.05 20:15 
@Ben: du solltest den Delphi-Tag beim Öffnen nicht schließen :lol:

AXMD
I.MacLeod
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 109



BeitragVerfasst: Sa 15.01.05 21:34 
BenBE hat folgendes geschrieben:
Ne, ganz im Gegenteil, die LEA ist sogar schneller, da du eine Anweisung sparst ... Wenn man ASM-Anweisungen sparen kann, soll mans machen :D

Nja, nicht unbedingt. Wenn ich zwei "einfache" durch eine "exotische" Anweisung ersetze würde ich mich lieber nicht darauf verlassen, dass es danach schneller ist (Womit ich nicht sagen will dass LEA exotisch ist). :roll:

Zitat:
Hieße dann korrigiert:

Kann es sein dass du einfach meine Version nochmal kopiert hast? :P
BenBE Threadstarter
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 16.01.05 00:10 
I.MacLeod hat folgendes geschrieben:
Zitat:
Hieße dann korrigiert:

Kann es sein dass du einfach meine Version nochmal kopiert hast? :P

:P Naja, angefangen hab ich, mit ASM, aber stimmt schon, an meiner Version bist Du nicht ganz unschuldig :P

Aber im Grundegenommen würde das Patent auf diese Methode Spaceguide zustehen ;-) Wir haben da nur dran Optimiert :P

_________________
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.
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: So 16.01.05 00:24 
Zitat:
RETZ kennt der delphi compiler net ;> und gibbet auch net


na, dann werd ich dem compiler mal auf die sprünge helfen ;)
--> retz
BenBE Threadstarter
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 16.01.05 00:49 
I.MacLeod hat folgendes geschrieben:
BenBE hat folgendes geschrieben:
Ne, ganz im Gegenteil, die LEA ist sogar schneller, da du eine Anweisung sparst ... Wenn man ASM-Anweisungen sparen kann, soll mans machen :D

Nja, nicht unbedingt. Wenn ich zwei "einfache" durch eine "exotische" Anweisung ersetze würde ich mich lieber nicht darauf verlassen, dass es danach schneller ist (Womit ich nicht sagen will dass LEA exotisch ist). :roll:

Zitat:
Hieße dann korrigiert:

Kann es sein dass du einfach meine Version nochmal kopiert hast? :P

_________________
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.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 24.01.05 20:15 
glaub das problem ist gelöst, da kann unser Benny ja auch mal den thread als bearbeitet/gelöst markieren
BenBE Threadstarter
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 24.01.05 22:10 
Hab darauf gewartet, dass ein Programmierer mit viel zu viel Freizeit vielleicht noch ne kürzere findet ;-) Aber gut, hab's mal als gelöst markiert :D

_________________
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.