Skip to content

Commit

Permalink
Fixed switches in the JIT.
Browse files Browse the repository at this point in the history
Switches were not actually using native jumps.
Switches of more than 12 items were unstable.
  • Loading branch information
ThyReaper committed Sep 25, 2013
1 parent c1d525b commit bdd7ce2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion as_jit.cpp
Expand Up @@ -1475,12 +1475,26 @@ int asCJITCompiler::CompileFunction(asIScriptFunction *function, asJITFunction *
} break;
case asBC_JMPP:
if((flags & JIT_NO_SWITCHES) == 0) {
unsigned cases = 1;
{
//This information isn't stored for us to recover, so we rely on the format of switch cases
//Each one is a series of asBC_JMP ops and a single remaining case at the end (default)
asDWORD* pNextOp = pOp + toSize(op);
asEBCInstr nextOp = asEBCInstr(*(asBYTE*)pNextOp);
while(nextOp == asBC_JMP) {
++cases;
pNextOp += toSize(asBC_JMP);
nextOp = asEBCInstr(*(asBYTE*)pNextOp);
}
}

SwitchRegion region;
region.count = asBC_DWORDARG(pOp) + 1;
region.count = cases;
region.remaining = region.count;
region.buffer = new unsigned char*[region.count];
memset(region.buffer, 0, region.count * sizeof(void*));
switches.push_back(region);
activeSwitch = &switches.back();

pax = (void*)(region.buffer);

Expand Down

0 comments on commit bdd7ce2

Please sign in to comment.