Skip to content

Commit

Permalink
memoization: hard coded fibonacci memoization
Browse files Browse the repository at this point in the history
just testing if we can take a detour in method execution
to actually implement memoization.
things are looking promising!
  • Loading branch information
flsobral committed Feb 9, 2021
1 parent cbc7d18 commit 119a12e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions TotalCrossVM/src/tcvm/tcvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ TC_API TValue executeMethod(Context context, Method method, ...)
cp = class_->cp;
method = newMethod;
code = method->code;

if (xstrcmp(newMethod->name, "fibR") == 0) {
int a = 0;
a++;

// if argument in hash, set reg64 & XSELECT

switch (reg64[-(int32)method->v64Count]) {
case 0:reg64[code->reg.reg] = 1; XSELECT(address,RETURN_reg64);
case 1:reg64[code->reg.reg] = 1; XSELECT(address,RETURN_reg64);
case 2:reg64[code->reg.reg] = 2; XSELECT(address,RETURN_reg64);
case 3:reg64[code->reg.reg] = 3; XSELECT(address,RETURN_reg64);
case 4:reg64[code->reg.reg] = 5; XSELECT(address,RETURN_reg64);
case 5:reg64[code->reg.reg] = 8; XSELECT(address,RETURN_reg64);
case 6:reg64[code->reg.reg] = 13; XSELECT(address,RETURN_reg64);
case 7:reg64[code->reg.reg] = 21; XSELECT(address,RETURN_reg64);
case 8:reg64[code->reg.reg] = 34; XSELECT(address,RETURN_reg64);
}
}
NEXT_OP0
}
// no else here!
Expand Down Expand Up @@ -865,6 +884,10 @@ TC_API TValue executeMethod(Context context, Method method, ...)
if (((int32)(context->callStack-context->callStackStart)) >= callStackMethodEnd)
{
resumePreviousMethod:
// if (fibR) {
// // save argument -> result in hashmap
// }

code = ((Code)context->callStack[-1]) + method->paramSkip; // now that retReg was used, its safe to skip over the parameters
// pop the current method's stack frame
context->regI -= method->iCount;
Expand Down

0 comments on commit 119a12e

Please sign in to comment.