Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime optimization + x64 bug fix #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions Source/x64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,6 @@ _XMM0: Double;
end;
{$ENDIF}

procedure StoreStack(const aData; Len: Integer);
var
p: Pointer;
begin
if Len > 8 then
if Length(Stack) mod 16 <> 0 then begin
SetLength(Stack, Length(Stack)+ (16-(Length(Stack) mod 16)));
end;
SetLength(Stack, Length(Stack)+Len);
p := @Stack[Length(Stack)-Len];
Move(aData, p^, Len);
end;

{$IFDEF WINDOWS}
procedure StoreReg(data: Double); overload;
var p: Pointer;
Expand Down Expand Up @@ -476,6 +463,11 @@ _XMM0: Double;
end;
{$ENDIF}
function GetPtr(fVar: PPSVariantIFC): Boolean;
type
TMethodCallData = record
AType : Byte;
Data : TMethod;
end;
var
varPtr: Pointer;
//UseReg: Boolean;
Expand All @@ -493,6 +485,8 @@ _XMM0: Double;
begin
p := CreateOpenArray(True, Self, FVar);
if p = nil then exit;
if CallData = nil then
CallData := TPSList.Create;
CallData.Add(p);
StoreReg(IPointer(POpenArray(p)^.Data));
StoreReg(IPointer(POpenArray(p)^.ItemCount -1));
Expand Down Expand Up @@ -541,6 +535,8 @@ _XMM0: Double;
begin
p := CreateOpenArray(False, SElf, FVar);
if p =nil then exit;
if CallData = nil then
CallData := TPSList.Create;
CallData.Add(p);
StoreReg(IPointer(POpenArray(p)^.Data));
StoreReg(IPointer(POpenArray(p)^.ItemCount -1));
Expand Down Expand Up @@ -608,10 +604,16 @@ _XMM0: Double;

btProcPtr:
begin
GetMem(p, PointerSize2);
TMethod(p^) := MKMethod(Self, Longint(FVar.Dta^));
StoreStack(p^, Pointersize2);
FreeMem(p);
GetMem(p, sizeof(TMethodCallData));
TMethodCallData(p^).AType:=255;
TMethodCallData(p^).Data.Code:=nil;
TMethodCallData(p^).Data.Data:=nil;
if CallData = nil then
CallData := TPSList.Create;
CallData.Add(p);
// Uncomment when Handler will be implemented
// TMethodCallData(p^).Data := MKMethod(Self, Longint(FVar.Dta^));
StoreReg(IPointer(@TMethodCallData(p^).Data));
end;

bts64:
Expand All @@ -627,7 +629,7 @@ begin
if Address = nil then
exit; // need address
SetLength(Stack, 0);
CallData := TPSList.Create;
CallData := nil;
res := rp(res);
if res <> nil then
res.VarParam := true;
Expand Down Expand Up @@ -749,14 +751,18 @@ begin
end;
Result := True;
finally
for i := CallData.Count -1 downto 0 do
if CallData<>nil then
begin
pp := CallData[i];
case pp^ of
0: DestroyOpenArray(Self, Pointer(pp));
for i := CallData.Count -1 downto 0 do
begin
pp := CallData[i];
case pp^ of
0: DestroyOpenArray(Self, Pointer(pp));
255: FreeMem(Pointer(pp));
end;
end;
CallData.Free;
end;
CallData.Free;
end;
end;

Expand Down
19 changes: 13 additions & 6 deletions Source/x86.inc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ var
begin
p := CreateOpenArray(True, Self, FVar);
if p = nil then exit;
if CallData = nil then
CallData := TPSList.Create();
CallData.Add(p);
case RegUsage of
0: begin EAX := Longint(POpenArray(p)^.Data); Inc(RegUsage); end;
Expand Down Expand Up @@ -365,6 +367,8 @@ var
begin
p := CreateOpenArray(False, SElf, FVar);
if p =nil then exit;
if CallData = nil then
CallData := TPSList.Create();
CallData.Add(p);
case RegUsage of
0: begin EAX := Longint(POpenArray(p)^.Data); Inc(RegUsage); end;
Expand Down Expand Up @@ -526,7 +530,7 @@ begin
if Address = nil then
exit; // need address
Stack := '';
CallData := TPSList.Create;
CallData := nil;
res := rp(res);
if res <> nil then
res.VarParam := true;
Expand Down Expand Up @@ -771,14 +775,17 @@ begin
end;
end;
finally
for i := CallData.Count -1 downto 0 do
if CallData<>nil then
begin
pp := CallData[i];
case pp^ of
0: DestroyOpenArray(Self, Pointer(pp));
for i := CallData.Count -1 downto 0 do
begin
pp := CallData[i];
case pp^ of
0: DestroyOpenArray(Self, Pointer(pp));
end;
end;
CallData.Free;
end;
CallData.Free;
end;
end;