Skip to content

Commit

Permalink
Reduce register spilling on function entry/exit
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Oct 23, 2021
1 parent e057e24 commit 42e4f48
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 160 deletions.
38 changes: 37 additions & 1 deletion autotest/asmtest.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <assert.h>

int asum(int a, int b)
{
Expand Down Expand Up @@ -30,11 +31,46 @@ int bsum(int a, int b)
}
}

int b, t[10];

int bsome(int x)
{
return x;
}


int qsum(int a, int (* c)(int))
{
char n = 0;
b = 0;
for(int i=0; i<a; i++)
{
int j = c((char)i);
__asm
{
clc
lda j
adc b
sta b
lda j + 1
adc b + 1
sta b + 1
}
t[n] += i;
n = (n + 1) & 7;
}
return b;
}

int main(void)
{
int x = asum(7007, 8008);
int y = bsum(4004, 9009);

return (x == 7007 + 8008 && y == 4004 + 9009) ? 0 : -1;
assert(x == 7007 + 8008 && y == 4004 + 9009);
assert(qsum(10, bsome) == 45);
assert(qsum(200, bsome) == 19900);

return 0;
}

1 change: 1 addition & 0 deletions oscar64/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ bool Compiler::GenerateCode(void)
mGlobalAnalyzer->DumpCallGraph();

mInterCodeGenerator->mCompilerOptions = mCompilerOptions;
mNativeCodeGenerator->mCompilerOptions = mCompilerOptions;

mInterCodeGenerator->TranslateAssembler(mInterCodeModule, dcrtstart->mValue, nullptr);

Expand Down
7 changes: 7 additions & 0 deletions oscar64/InterCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,13 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vins->mConst.mOperandSize = vdec->mSize;
vins->mConst.mIntConst = vdec->mOffset;
}
else if (vdec->mType == DT_VARIABLE)
{
vins->mConst.mMemory = IM_LOCAL;
vins->mConst.mVarIndex = vdec->mVarIndex;
vins->mConst.mOperandSize = vdec->mSize;
vins->mConst.mIntConst = vdec->mOffset;
}

block->Append(vins);

Expand Down
Loading

0 comments on commit 42e4f48

Please sign in to comment.