Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: "absolute" and "register" keywords?

  1. #1

    "absolute" and "register" keywords?

    very uncommon, what is the use for them?
    From brazil (:

    Pascal pownz!

  2. #2

    "absolute" and "register" keywords?

    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.

  3. #3

    "absolute" and "register" keywords?

    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.

    Code:
    // true = positive, false = positive
    function GetSign&#40;x&#58; single&#41;&#58; boolean;
    var
      i&#58; longword absolute x;
    begin
      Result &#58;= i and $80000000 = 0; // integer operator tricks
    end;
    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:
    function DotProduct&#40;const vA, vB&#41;&#58; single; overload;
    var
      A&#58; Vector absolute va;
      B&#58; Vector absolute vb;
    begin
      Result &#58;= 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

  4. #4

    "absolute" and "register" keywords?

    interesting :?
    From brazil (:

    Pascal pownz!

  5. #5

    "absolute" and "register" keywords?

    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

  6. #6

    "absolute" and "register" keywords?

    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.

  7. #7

    "absolute" and "register" keywords?

    Quote Originally Posted by pstudio
    Just curious
    Is it legal to use absolute to make a variable begin from adress 0?
    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.
    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

  8. #8

    "absolute" and "register" keywords?

    Quote Originally Posted by waran
    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.
    so i can optimize functions using different calling conventions?

    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!

  9. #9

    "absolute" and "register" keywords?

    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

  10. #10

    "absolute" and "register" keywords?

    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

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •