Skip to content

Commit

Permalink
make function parameters fast again
Browse files Browse the repository at this point in the history
  • Loading branch information
yeti0904 committed Oct 22, 2024
1 parent 6cab59a commit 49ee1dd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/tak.cal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include "cores/select.cal"
include "std/io.cal"

func tak cell x cell y cell z begin
func tak cell x cell y cell z -> cell res begin
if y x < then
x 1 - y z tak
y 1 - z x tak
Expand Down
33 changes: 23 additions & 10 deletions source/backends/arm64.d
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,25 @@ class BackendARM64 : CompilerBackend {
}

// copy data to parameters
output ~= format("sub x19, x19, #%d\n", paramSize);
//output ~= format("sub x9, x19, #%d\n", paramSize);
output ~= "mov x9, x19\n";
output ~= "mov x10, x20\n";
output ~= format("mov x11, #%d\n", paramSize);
output ~= "1:\n";
output ~= "ldrb w12, [x9], #1\n";
output ~= "strb w12, [x10], #1\n";
output ~= "subs x11, x11, #1\n";
output ~= "bne 1b\n";
if (node.params.length > 10) {
output ~= format("sub x19, x19, #%d\n", paramSize);
//output ~= format("sub x9, x19, #%d\n", paramSize);
output ~= "mov x9, x19\n";
output ~= "mov x10, x20\n";
output ~= format("mov x11, #%d\n", paramSize);
output ~= "1:\n";
output ~= "ldrb w12, [x9], #1\n";
output ~= "strb w12, [x10], #1\n";
output ~= "subs x11, x11, #1\n";
output ~= "bne 1b\n";
}
else {
foreach_reverse (ref param ; node.params) {
auto setNode = new SetNode(node.error);
setNode.var = param;
CompileSet(setNode);
}
}
}

foreach (ref inode ; node.nodes) {
Expand Down Expand Up @@ -774,6 +783,10 @@ class BackendARM64 : CompilerBackend {
}
}
else {
if (GlobalExists(node.name)) {
Error(node.error, "Global '%s' already exists", node.name);
}

Global global;
global.type = GetType(node.varType);
global.array = node.array;
Expand Down
4 changes: 4 additions & 0 deletions source/backends/lua.d
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ class BackendLua : CompilerBackend {
}
}
else {
if (GlobalExists(node.name)) {
Error(node.error, "Global '%s' already exists", node.name);
}

GlobalExtra* extra = new GlobalExtra();
extra.addr = globalStack;

Expand Down
4 changes: 4 additions & 0 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ class BackendRM86 : CompilerBackend {
}
}
else {
if (GlobalExists(node.name)) {
Error(node.error, "Global '%s' already exists", node.name);
}

Global global;
global.type = GetType(node.varType);
global.array = node.array;
Expand Down
23 changes: 18 additions & 5 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,20 @@ class BackendX86_64 : CompilerBackend {
}

// copy data to parameters
output ~= format("sub r15, %d\n", paramSize);
output ~= "mov rsi, r15\n";
output ~= "mov rdi, rsp\n";
output ~= format("mov rcx, %d\n", paramSize);
output ~= "rep movsb\n";
if (node.params.length > 10) {
output ~= format("sub r15, %d\n", paramSize);
output ~= "mov rsi, r15\n";
output ~= "mov rdi, rsp\n";
output ~= format("mov rcx, %d\n", paramSize / 8);
output ~= "rep movsq\n";
}
else {
foreach_reverse (ref param ; node.params) {
auto setNode = new SetNode(node.error);
setNode.var = param;
CompileSet(setNode);
}
}
}

foreach (ref inode ; node.nodes) {
Expand Down Expand Up @@ -868,6 +877,10 @@ class BackendX86_64 : CompilerBackend {
}
}
else {
if (GlobalExists(node.name)) {
Error(node.error, "Global '%s' already exists", node.name);
}

Global global;
global.type = GetType(node.varType);
global.array = node.array;
Expand Down

0 comments on commit 49ee1dd

Please sign in to comment.