AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign Delphi Wert eines Defines merken und wiederherstellen
Thema durchsuchen
Ansicht
Themen-Optionen

Wert eines Defines merken und wiederherstellen

Ein Thema von TurboMagic · begonnen am 17. Dez 2023 · letzter Beitrag vom 18. Dez 2023
Antwort Antwort
Kas Ob.

Registriert seit: 3. Sep 2023
457 Beiträge
 
#1

AW: Wert eines Defines merken und wiederherstellen

  Alt 18. Dez 2023, 07:55
Hi,

There is few tricks can be used, but i can't find valuable for you in this case without affecting the performance for this performance critical procedure.

This is perfect workaround for 32bit but will not compile for 64 for the obvious reason
Code:
procedure AddC(var Value: UInt32; Add: UInt32; var Carry: Boolean);
begin
  Value := Value + Add;
  PByte(Value) := PByte(Value) + Ord(Add);
end;
Its assembly
Code:
Project5.dpr.15: Value := Value + Add;
0041A2BC 0110             add [eax],edx
0041A2BE 7305             jnb $0041a2c5
0041A2C0 E83FB3FEFF       call @IntOver
Project5.dpr.16: PByte(Value) := PByte(Value) + Ord(Add);
0041A2C5 0110             add [eax],edx
Project5.dpr.21: end;
0041A2C7 C3               ret
The overhead is one instruction in this case.

but all the other tricks and shenanigans that work for both platforms i can think of will introduce huge overhead instead of one or two instruction.
Like this one
Code:
procedure AddC(var Value: UInt32; Add: UInt32; var Carry: Boolean);
begin
  Value := Value + Add;
  Value := UInt32(PByte(Value) + Ord(Add));
end;
Generated code :
Code:
Project5.dpr.15: Value := Value + Add;
0041A2BC 0110             add [eax],edx
0041A2BE 7305             jnb $0041a2c5
0041A2C0 E83FB3FEFF       call @IntOver
Project5.dpr.16: Value := UInt32(PByte(Value) + Ord(Add));
0041A2C5 8B08             mov ecx,[eax]
0041A2C7 03CA             add ecx,edx
0041A2C9 8908             mov [eax],ecx
Project5.dpr.22: end;
0041A2CB C3               ret
Code:
Project5.dpr.15: Value := Value + Add;
00000000004261E8 0111             add [rcx],edx
00000000004261EA 7305             jnb AddC + $11
00000000004261EC E8AF12FEFF       call @IntOver
Project5.dpr.16: Value := UInt32(PByte(Value) + Ord(Add));
00000000004261F1 8B01             mov eax,[rcx]
00000000004261F3 8BD2             mov edx,edx
00000000004261F5 488D0410         lea rax,[rax+rdx]
00000000004261F9 8901             mov [rcx],eax
Project5.dpr.22: end;
00000000004261FB 488D6520         lea rsp,[rbp+$20]
00000000004261FF 5D               pop rbp
0000000000426200 C3               ret
We have stupid and outdated compiler !
Though the above result is on XE8, and i have no idea on how or will it even compile on newer versions.
Kas
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.557 Beiträge
 
Delphi 12 Athens
 
#2

AW: Wert eines Defines merken und wiederherstellen

  Alt 18. Dez 2023, 08:26
Tja, seit Kurzem sind in neuen Projekten standardmäßig die Bereichs- und Überlaufprüfungen aktiv.
Wer dass nicht Will, braucht es einfach nur zu deaktivieren. (In den Projektoptionen, oder nur an dieser Stelle im Code)

Klar, es produziert zwar mehr Code, aber ich finde es schon sinnvoller. (nur die standardmäßig aktiven Debug-DCUs sind und bleiben IMHO einfach nur nötigender Schwachsinn)


Aber bei der Pointer-Mathematik scheint diese Prüfung nicht eingebaut zu sein.
Ein Therapeut entspricht 1024 Gigapeut.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz