- branch optimization for for loops.

This commit is contained in:
Christoph Oelckers 2016-12-02 00:56:54 +01:00
parent 719be058e5
commit fb7a8fb553
1 changed files with 4 additions and 9 deletions

View File

@ -9279,7 +9279,7 @@ ExpEmit FxForLoop::Emit(VMFunctionBuilder *build)
size_t loopstart, loopend; size_t loopstart, loopend;
size_t codestart; size_t codestart;
size_t jumpspot; TArray<size_t> yes, no;
// Init statement (only used by DECORATE. ZScript is pulling it before the loop statement and enclosing the entire loop in a compound statement so that Init can have local variables.) // Init statement (only used by DECORATE. ZScript is pulling it before the loop statement and enclosing the entire loop in a compound statement so that Init can have local variables.)
if (Init != nullptr) if (Init != nullptr)
@ -9292,12 +9292,10 @@ ExpEmit FxForLoop::Emit(VMFunctionBuilder *build)
codestart = build->GetAddress(); codestart = build->GetAddress();
if (Condition != nullptr) if (Condition != nullptr)
{ {
ExpEmit cond = Condition->Emit(build); Condition->EmitCompare(build, false, yes, no);
build->Emit(OP_TEST, cond.RegNum, 0);
cond.Free(build);
jumpspot = build->Emit(OP_JMP, 0);
} }
build->BackpatchListToHere(yes);
// Execute the loop's content. // Execute the loop's content.
if (Code != nullptr) if (Code != nullptr)
{ {
@ -9316,10 +9314,7 @@ ExpEmit FxForLoop::Emit(VMFunctionBuilder *build)
// End of loop. // End of loop.
loopend = build->GetAddress(); loopend = build->GetAddress();
if (Condition != nullptr) build->BackpatchListToHere(no);
{
build->Backpatch(jumpspot, loopend);
}
Backpatch(build, loopstart, loopend); Backpatch(build, loopstart, loopend);
return ExpEmit(); return ExpEmit();