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
 
Kas Ob.
Online

Registriert seit: 3. Sep 2023
465 Beiträge
 
#7

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
 


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 08:40 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