Skip to content

Commit

Permalink
Implemented x64 compatibility for Freepascal. Removed a few unused un…
Browse files Browse the repository at this point in the history
…its.

-> The stack handling had to be completely rewritten for x64.
Sidenotes: Sometimes stackalignment is not garanted to be properly aligned so I had to introduce some alignment dummy variables.
FPC reserves extra space for parameters thus accessing the parameters instead of the registers leads to different 
results.
  • Loading branch information
[email protected] committed Jul 6, 2014
1 parent e96c172 commit ac07798
Show file tree
Hide file tree
Showing 48 changed files with 2,494 additions and 1,606 deletions.
37 changes: 0 additions & 37 deletions ASMConsts.pas

This file was deleted.

12 changes: 9 additions & 3 deletions ASMMatrixAbsOperations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

interface

{$IFNDEF CPUX64}
{$IFDEF CPUX64}
{$DEFINE x64}
{$ENDIF}
{$IFDEF cpux86_64}
{$DEFINE x64}
{$ENDIF}
{$IFNDEF x64}

uses ASMConsts;
uses MatrixConst;

procedure ASMMatrixAbsAlignedEvenW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
procedure ASMMatrixAbsUnAlignedEvenW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
Expand All @@ -20,7 +26,7 @@ procedure ASMMatrixAbsUnAlignedOddW(Dest : PDouble; const LineWidth, Width, Heig

implementation

{$IFNDEF CPUX64}
{$IFNDEF x64}

{$IFDEF FPC} {$ASMMODE intel} {$ENDIF}

Expand Down
65 changes: 49 additions & 16 deletions ASMMatrixAbsOperationsx64.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
interface

{$IFDEF CPUX64}
{$DEFINE x64}
{$ENDIF}
{$IFDEF cpux86_64}
{$DEFINE x64}
{$ENDIF}
{$IFDEF x64}

uses ASMConsts;
uses MatrixConst;

procedure ASMMatrixAbsAlignedEvenW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
procedure ASMMatrixAbsUnAlignedEvenW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
Expand All @@ -20,20 +26,25 @@ procedure ASMMatrixAbsUnAlignedOddW(Dest : PDouble; const LineWidth, Width, Heig

implementation

{$IFDEF CPUX64}
{$IFDEF x64}

{$IFDEF FPC} {$ASMMODE intel} {$ENDIF}

const cSignBits : Array[0..1] of int64 = ($7FFFFFFFFFFFFFFF, $7FFFFFFFFFFFFFFF);

procedure ASMMatrixAbsAlignedEvenW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
{$IFDEF FPC}
begin
{$ENDIF}
asm
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
//iters := -width*sizeof(double);
mov r10, width;
shl r10, 3;
imul r10, -1;

// helper registers for the mt1, mt2 and dest pointers
sub dest, r10;
// helper registers for the dest pointer
sub rcx, r10;

movupd xmm0, cSignBits;

Expand Down Expand Up @@ -105,18 +116,24 @@ procedure ASMMatrixAbsAlignedEvenW(Dest : PDouble; const LineWidth, Width, Heigh
// loop y end
dec r11;
jnz @@addforyloop;
{$IFDEF FPC}
end;
{$ENDIF}
end;

procedure ASMMatrixAbsUnAlignedEvenW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
{$IFDEF FPC}
begin
{$ENDIF}
asm
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
//iters := -width*sizeof(double);
mov r10, width;
shl r10, 3;
imul r10, -1;

// helper registers for the mt1, mt2 and dest pointers
sub dest, r10;
// helper registers for the dest pointer
sub rcx, r10;

movupd xmm0, cSignBits;

Expand Down Expand Up @@ -186,19 +203,25 @@ procedure ASMMatrixAbsUnAlignedEvenW(Dest : PDouble; const LineWidth, Width, Hei
// loop y end
dec r11;
jnz @@addforyloop;
{$IFDEF FPC}
end;
{$ENDIF}
end;

procedure ASMMatrixAbsAlignedOddW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
{$IFDEF FPC}
begin
{$ENDIF}
asm
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
//iters := -(width - 1)*sizeof(double);
mov r10, width;
dec r10;
shl r10, 3;
imul r10, -1;

// helper registers for the mt1, mt2 and dest pointers
sub dest, r10;
// helper registers for the dest pointer
sub rcx, r10;

movupd xmm0, cSignBits;

Expand Down Expand Up @@ -276,18 +299,25 @@ procedure ASMMatrixAbsAlignedOddW(Dest : PDouble; const LineWidth, Width, Height
// loop y end
dec r11;
jnz @@addforyloop;
{$IFDEF FPC}
end;
{$ENDIF}
end;

procedure ASMMatrixAbsUnAlignedOddW(Dest : PDouble; const LineWidth, Width, Height : TASMNativeInt);
{$IFDEF FPC}
begin
{$ENDIF}
asm
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
//iters := -width*sizeof(double);
// note: RCX = dest, RDX = destLineWidth, R8 = width, R9 = height
//iters := -(width-1)*sizeof(double);
mov r10, width;
dec r10;
shl r10, 3;
imul r10, -1;

// helper registers for the mt1, mt2 and dest pointers
sub dest, r10;
// helper registers for the dest pointer
sub rcx, r10;

movupd xmm0, cSignBits;

Expand Down Expand Up @@ -344,7 +374,7 @@ procedure ASMMatrixAbsUnAlignedOddW(Dest : PDouble; const LineWidth, Width, Heig

@addforxloop2:
movupd xmm1, [rcx + rax];
adnpd xmm1, xmm0;
andpd xmm1, xmm0;
movupd [rcx + rax], xmm1;
add rax, 16;
jnz @addforxloop2;
Expand All @@ -362,6 +392,9 @@ procedure ASMMatrixAbsUnAlignedOddW(Dest : PDouble; const LineWidth, Width, Heig
// loop y end
dec r11;
jnz @@addforyloop;
{$IFDEF FPC}
end;
{$ENDIF}
end;

{$ENDIF}
Expand Down
10 changes: 8 additions & 2 deletions ASMMatrixAddSubOperations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@

interface

{$IFNDEF CPUX64}
{$IFDEF CPUX64}
{$DEFINE x64}
{$ENDIF}
{$IFDEF cpux86_64}
{$DEFINE x64}
{$ENDIF}
{$IFNDEF x64}

uses MatrixConst;

Expand All @@ -41,7 +47,7 @@ procedure ASMMatrixSubUnAlignedOddW(dest : PDouble; const destLinewidth : TASMNa

implementation

{$IFNDEF CPUX64}
{$IFNDEF x64}

{$IFDEF FPC} {$ASMMODE intel} {$ENDIF}

Expand Down
Loading

0 comments on commit ac07798

Please sign in to comment.