very uncommon, what is the use for them?
very uncommon, what is the use for them?
From brazil (:
Pascal pownz!
Absolute allows you to define an address in memory where you want to have the first byte of the variable. Syntax:
[pascal]
var
Variable: <type> absolute segmentffset;
[/pascal]
Register allows you to register the convention call to define the parameters of the procedures and functions. The first three parameters of functions or procedures bearing the directive will be available via the processor registers, in turn EAX, EDX, ECX, and other parameters will go to the stack in the order from left to right. Example:
[pascal]
procedure Foo(A, B, C, D, E: Integer); register;
begin
end;
[/pascal]
In this procedure, the value of A parameter will be in the register EAX, B - EDX, C - ECX, D and E (in that order) will go to the stack.
example of ABSOLUTE usage as code optimization trick: this function uses a longword integer type at the float parameter address to treat data as integer in order to perform bit operations without typecasting or conversion, this code will beat "result:= x > 0" any time.
You can also come up with code like this, which will use a single vector type and work with ANY memory compatible vector formats (think compatibility between glscene vector types and some other code vector types)Code:// true = positive, false = positive function GetSign(x: single): boolean; var i: longword absolute x; begin Result := i and $80000000 = 0; // integer operator tricks end;
Code:function DotProduct(const vA, vB): single; overload; var A: Vector absolute va; B: Vector absolute vb; begin Result := A.X * B.X + A.Y * B.Y + A.Z * B.Z; end;
This is my game project - Top Down City:
http://www.pascalgamedevelopment.com...y-Topic-Reboot
My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
http://www.pascalgamedevelopment.com...source+manager
interesting :?
From brazil (:
Pascal pownz!
Just curious
Is it legal to use absolute to make a variable begin from adress 0?
Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits
It is legal, but the address is read and write protected (program will crash).
As for register: This is the default calling convention in delphi/pascal. So if
you don't specify anything its register - different to C where parameters are
always passed via stack unless you specify __fastcall as calling convention.
Technically you can make it anywhere, this was useful in DOS times to read bios stuff which was at constant addresses, this is no longer useful today and absolute serves more for cases which i demonstrated.Originally Posted by pstudio
This is my game project - Top Down City:
http://www.pascalgamedevelopment.com...y-Topic-Reboot
My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
http://www.pascalgamedevelopment.com...source+manager
so i can optimize functions using different calling conventions?Originally Posted by waran
examples?
edit:
i did some tests,
seems like fastcall or register is the slower ? why ?
[pascal]program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
type
TPoint4 = array[0..3] of Single;
procedure Test1(const a,b : TPoint4);
begin
end;
procedure Test2(const a,b : TPoint4); stdcall;
begin
end;
procedure Test3(const a,b : TPoint4); cdecl;
begin
end;
var
a,b : TPoint4;
c : Cardinal;
n : Int64;
begin
n := 0;
c := GetTickCount;
repeat
Test3(a,b);
Inc(n);
until GetTickCount >= c + 1000;
Writeln(n);
n := 0;
c := GetTickCount;
repeat
Test2(a,b);
Inc(n);
until GetTickCount >= c + 1000;
Writeln(n);
n := 0;
c := GetTickCount;
repeat
Test1(a,b);
Inc(n);
until GetTickCount >= c + 1000;
Writeln(n);
Readln;
end.
[/pascal]
results:
123686244
130016857
59970038
From brazil (:
Pascal pownz!
try making the functions actually do something? try passing small data, large several MB of data etc.. and see hot it behaves
This is my game project - Top Down City:
http://www.pascalgamedevelopment.com...y-Topic-Reboot
My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
http://www.pascalgamedevelopment.com...source+manager
I see 2 problems with your test code:
First of all you are using GetTickCount. Its propably the most unprecise
counter available. Do this:
[pascal]uses windows;
var
t1, t2, fq: int64;
begin
QueryPerformanceFrequency(fq);
QueryPerformanceCounter(t1);
YourTestCode;
QueryPerformanceCounter(t2);
writeln(((t2-t1)/fq):8:;
end.[/pascal]
And second of all:
The parameters you pass are way too big to fit 2 (or 3, in some
pascal implementations) registers - so the performance improvement,
if any, is very narrow.
It could be that managing to push params over stack and registers
requires some more administration to the compiler.
And yes: Try to make the functions do something (if you use less data,
2x32Bit, then its the data is available immediately because it has not to
be popped from the stack first).
Edit:
I see you are using const. Then forget about my size matters
Bookmarks