Global var opcodes for common conditional statements. Decent performance gain!

git-svn-id: https://svn.eduke32.com/eduke32@7265 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-12-15 01:38:10 +00:00
parent 6dfafc49b1
commit ace77922b1
3 changed files with 135 additions and 14 deletions

View file

@ -676,20 +676,36 @@ static const vec2_t varvartable[] =
static const vec2_t globalvartable[] =
{
{ CON_IFVARA, CON_IFGLOBALVARA },
{ CON_IFVARAE, CON_IFGLOBALVARAE },
{ CON_IFVARAND, CON_IFGLOBALVARAND },
{ CON_IFVARB, CON_IFGLOBALVARB },
{ CON_IFVARBE, CON_IFGLOBALVARBE },
{ CON_IFVARBOTH, CON_IFGLOBALVARBOTH },
{ CON_IFVARE, CON_IFGLOBALVARE },
{ CON_IFVAREITHER, CON_IFGLOBALVAREITHER },
{ CON_IFVARG, CON_IFGLOBALVARG },
{ CON_IFVARGE, CON_IFGLOBALVARGE },
{ CON_IFVARL, CON_IFGLOBALVARL },
{ CON_IFVARLE, CON_IFGLOBALVARLE },
{ CON_IFVARN, CON_IFGLOBALVARN },
{ CON_IFVAROR, CON_IFGLOBALVAROR },
{ CON_IFVARXOR, CON_IFGLOBALVARXOR },
{ CON_ADDVAR, CON_ADDGLOBALVAR },
{ CON_ANDVAR, CON_ANDGLOBALVAR },
{ CON_DIVVAR, CON_DIVGLOBALVAR },
{ CON_MODVAR, CON_MODGLOBALVAR },
{ CON_MULVAR, CON_MULGLOBALVAR },
{ CON_ORVAR, CON_ORGLOBALVAR },
{ CON_RANDVAR, CON_RANDGLOBALVAR },
{ CON_SETVAR, CON_SETGLOBALVAR },
{ CON_SHIFTVARL, CON_SHIFTGLOBALVARL },
{ CON_SHIFTVARR, CON_SHIFTGLOBALVARR },
{ CON_RANDVAR, CON_RANDGLOBALVAR },
{ CON_MODVAR, CON_MODGLOBALVAR },
{ CON_ANDVAR, CON_ANDGLOBALVAR },
{ CON_ADDVAR, CON_ADDGLOBALVAR },
{ CON_ORVAR, CON_ORGLOBALVAR },
{ CON_SETVAR, CON_SETGLOBALVAR },
{ CON_SUBVAR, CON_SUBGLOBALVAR },
{ CON_XORVAR, CON_XORGLOBALVAR },
{ CON_MULVAR, CON_MULGLOBALVAR },
{ CON_DIVVAR, CON_DIVGLOBALVAR },
{ CON_WHILEVARL, CON_WHILEGLOBALVARL },
{ CON_WHILEVARN, CON_WHILEGLOBALVARN },
{ CON_XORVAR, CON_XORGLOBALVAR },
};
static inthashtable_t h_varvar = { NULL, INTHASH_SIZE(ARRAY_SIZE(varvartable)) };
@ -3713,7 +3729,6 @@ setvar:
VM_GetKeywordForID(*ins & VM_INSTMASK), VM_GetKeywordForID(opcode));
}
tw = opcode;
scriptWriteAtOffset(opcode | LINE_NUMBER, ins);
}
}
@ -4336,16 +4351,17 @@ singlevar:
if (C_CheckMalformedBranch(lastScriptPtr))
continue;
if (aGameVars[ins[1]].flags == 0)
// substitute instructions that operate on global vars directly if appropriate
if (aGameVars[ins[1] & (MAXGAMEVARS-1)].flags == 0)
{
int const opcode = inthash_find(&h_globalvar, *ins & VM_INSTMASK);
if (opcode != -1)
{
if (!g_errorCnt && !g_warningCnt && g_scriptDebug > 1)
//if (!g_errorCnt && !g_warningCnt && g_scriptDebug > 1)
{
initprintf("%s:%d: %s -> %s\n", g_scriptFileName, g_lineNumber,
VM_GetKeywordForID(*ins & VM_INSTMASK), VM_GetKeywordForID(opcode));
initprintf("%s:%d: %s -> %s for var %s(%d)\n", g_scriptFileName, g_lineNumber,
VM_GetKeywordForID(*ins & VM_INSTMASK), VM_GetKeywordForID(opcode), aGameVars[ins[1] & (MAXGAMEVARS-1)].szLabel, (int)(ins[1]));
}
tw = opcode;

View file

@ -982,6 +982,21 @@ enum ScriptKeywords_t
CON_IFDEAD,
CON_IFFLOORDISTL,
CON_IFGAPZL,
CON_IFGLOBALVARA,
CON_IFGLOBALVARAE,
CON_IFGLOBALVARAND,
CON_IFGLOBALVARB,
CON_IFGLOBALVARBE,
CON_IFGLOBALVARBOTH,
CON_IFGLOBALVARE,
CON_IFGLOBALVAREITHER,
CON_IFGLOBALVARG,
CON_IFGLOBALVARGE,
CON_IFGLOBALVARL,
CON_IFGLOBALVARLE,
CON_IFGLOBALVARN,
CON_IFGLOBALVAROR,
CON_IFGLOBALVARXOR,
CON_IFGOTWEAPONCE,
CON_IFHITSPACE,
CON_IFHITWEAPON,

View file

@ -1442,12 +1442,24 @@ next_instruction:
VM_CONDITIONAL(tw == *insptr);
continue;
case CON_IFGLOBALVARE:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw == *insptr);
continue;
case CON_IFVARN:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw != *insptr);
continue;
case CON_IFGLOBALVARN:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw != *insptr);
continue;
case CON_IFVARVARG:
insptr++;
tw = Gv_GetVarX(*insptr++);
@ -1536,30 +1548,60 @@ next_instruction:
VM_CONDITIONAL(tw);
continue;
case CON_IFGLOBALVARAND:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw & *insptr);
continue;
case CON_IFVARAND:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw & *insptr);
continue;
case CON_IFGLOBALVAROR:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw | *insptr);
continue;
case CON_IFVAROR:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw | *insptr);
continue;
case CON_IFGLOBALVARXOR:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw ^ *insptr);
continue;
case CON_IFVARXOR:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw ^ *insptr);
continue;
case CON_IFGLOBALVAREITHER:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw || *insptr);
continue;
case CON_IFVAREITHER:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw || *insptr);
continue;
case CON_IFGLOBALVARBOTH:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw && *insptr);
continue;
case CON_IFVARBOTH:
insptr++;
tw = Gv_GetVarX(*insptr++);
@ -1570,48 +1612,96 @@ next_instruction:
VM_CONDITIONAL(rnd(*(++insptr)));
continue;
case CON_IFGLOBALVARG:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw > *insptr);
continue;
case CON_IFVARG:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw > *insptr);
continue;
case CON_IFGLOBALVARGE:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw >= *insptr);
continue;
case CON_IFVARGE:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw >= *insptr);
continue;
case CON_IFGLOBALVARL:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw < *insptr);
continue;
case CON_IFVARL:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw < *insptr);
continue;
case CON_IFGLOBALVARLE:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL(tw <= *insptr);
continue;
case CON_IFVARLE:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL(tw <= *insptr);
continue;
case CON_IFGLOBALVARA:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr);
continue;
case CON_IFVARA:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr);
continue;
case CON_IFGLOBALVARAE:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr);
continue;
case CON_IFVARAE:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr);
continue;
case CON_IFGLOBALVARB:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr);
continue;
case CON_IFVARB:
insptr++;
tw = Gv_GetVarX(*insptr++);
VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr);
continue;
case CON_IFGLOBALVARBE:
insptr++;
tw = aGameVars[*insptr++].global;
VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr);
continue;
case CON_IFVARBE:
insptr++;
tw = Gv_GetVarX(*insptr++);