Skip to content

Commit 49ee1dd

Browse files
committed
make function parameters fast again
1 parent 6cab59a commit 49ee1dd

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

examples/tak.cal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include "cores/select.cal"
22
include "std/io.cal"
33

4-
func tak cell x cell y cell z begin
4+
func tak cell x cell y cell z -> cell res begin
55
if y x < then
66
x 1 - y z tak
77
y 1 - z x tak

source/backends/arm64.d

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,16 +582,25 @@ class BackendARM64 : CompilerBackend {
582582
}
583583

584584
// copy data to parameters
585-
output ~= format("sub x19, x19, #%d\n", paramSize);
586-
//output ~= format("sub x9, x19, #%d\n", paramSize);
587-
output ~= "mov x9, x19\n";
588-
output ~= "mov x10, x20\n";
589-
output ~= format("mov x11, #%d\n", paramSize);
590-
output ~= "1:\n";
591-
output ~= "ldrb w12, [x9], #1\n";
592-
output ~= "strb w12, [x10], #1\n";
593-
output ~= "subs x11, x11, #1\n";
594-
output ~= "bne 1b\n";
585+
if (node.params.length > 10) {
586+
output ~= format("sub x19, x19, #%d\n", paramSize);
587+
//output ~= format("sub x9, x19, #%d\n", paramSize);
588+
output ~= "mov x9, x19\n";
589+
output ~= "mov x10, x20\n";
590+
output ~= format("mov x11, #%d\n", paramSize);
591+
output ~= "1:\n";
592+
output ~= "ldrb w12, [x9], #1\n";
593+
output ~= "strb w12, [x10], #1\n";
594+
output ~= "subs x11, x11, #1\n";
595+
output ~= "bne 1b\n";
596+
}
597+
else {
598+
foreach_reverse (ref param ; node.params) {
599+
auto setNode = new SetNode(node.error);
600+
setNode.var = param;
601+
CompileSet(setNode);
602+
}
603+
}
595604
}
596605

597606
foreach (ref inode ; node.nodes) {
@@ -774,6 +783,10 @@ class BackendARM64 : CompilerBackend {
774783
}
775784
}
776785
else {
786+
if (GlobalExists(node.name)) {
787+
Error(node.error, "Global '%s' already exists", node.name);
788+
}
789+
777790
Global global;
778791
global.type = GetType(node.varType);
779792
global.array = node.array;

source/backends/lua.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ class BackendLua : CompilerBackend {
519519
}
520520
}
521521
else {
522+
if (GlobalExists(node.name)) {
523+
Error(node.error, "Global '%s' already exists", node.name);
524+
}
525+
522526
GlobalExtra* extra = new GlobalExtra();
523527
extra.addr = globalStack;
524528

source/backends/rm86.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ class BackendRM86 : CompilerBackend {
615615
}
616616
}
617617
else {
618+
if (GlobalExists(node.name)) {
619+
Error(node.error, "Global '%s' already exists", node.name);
620+
}
621+
618622
Global global;
619623
global.type = GetType(node.varType);
620624
global.array = node.array;

source/backends/x86_64.d

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,20 @@ class BackendX86_64 : CompilerBackend {
670670
}
671671

672672
// copy data to parameters
673-
output ~= format("sub r15, %d\n", paramSize);
674-
output ~= "mov rsi, r15\n";
675-
output ~= "mov rdi, rsp\n";
676-
output ~= format("mov rcx, %d\n", paramSize);
677-
output ~= "rep movsb\n";
673+
if (node.params.length > 10) {
674+
output ~= format("sub r15, %d\n", paramSize);
675+
output ~= "mov rsi, r15\n";
676+
output ~= "mov rdi, rsp\n";
677+
output ~= format("mov rcx, %d\n", paramSize / 8);
678+
output ~= "rep movsq\n";
679+
}
680+
else {
681+
foreach_reverse (ref param ; node.params) {
682+
auto setNode = new SetNode(node.error);
683+
setNode.var = param;
684+
CompileSet(setNode);
685+
}
686+
}
678687
}
679688

680689
foreach (ref inode ; node.nodes) {
@@ -868,6 +877,10 @@ class BackendX86_64 : CompilerBackend {
868877
}
869878
}
870879
else {
880+
if (GlobalExists(node.name)) {
881+
Error(node.error, "Global '%s' already exists", node.name);
882+
}
883+
871884
Global global;
872885
global.type = GetType(node.varType);
873886
global.array = node.array;

0 commit comments

Comments
 (0)