WIP work on fixing CON_DIVVAR/CON_MULVAR optimization

git-svn-id: https://svn.eduke32.com/eduke32@7267 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-12-15 01:38:22 +00:00
parent cf95da82e9
commit fad17a83c0

View file

@ -3735,16 +3735,16 @@ setvar:
C_GetNextVarType(GAMEVAR_READONLY); C_GetNextVarType(GAMEVAR_READONLY);
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
#if 0
if (tw == CON_DIVVAR || tw == CON_MULVAR) if (tw == CON_DIVVAR || tw == CON_MULVAR)
{ {
int32_t const i = ins[2]; auto const i = ins[2];
if (i == -1) // replace multiplies or divides by 1 with nullop
if (i == 1)
{ {
int constexpr const opcode = CON_INV; int constexpr const opcode = CON_NULLOP;
if (g_scriptDebug > 1 && !g_errorCnt && !g_warningCnt) if (!g_errorCnt && !g_warningCnt && g_scriptDebug > 1)
{ {
initprintf("%s:%d: %s -> %s\n", g_scriptFileName, g_lineNumber, initprintf("%s:%d: %s -> %s\n", g_scriptFileName, g_lineNumber,
VM_GetKeywordForID(tw), VM_GetKeywordForID(opcode)); VM_GetKeywordForID(tw), VM_GetKeywordForID(opcode));
@ -3766,16 +3766,17 @@ setvar:
scriptWriteAtOffset(opcode | LINE_NUMBER, ins); scriptWriteAtOffset(opcode | LINE_NUMBER, ins);
g_scriptPtr--; g_scriptPtr--;
continue;
} }
// replace multiplies or divides by a power of 2 with the appropriate shift
#if 0
else if (C_IntPow2((j = klabs(i)))) else if (C_IntPow2((j = klabs(i))))
{ {
int const opcode = (tw == CON_DIVVAR) ? CON_SHIFTVARR : CON_SHIFTVARL; int const opcode = (tw == CON_DIVVAR) ? CON_SHIFTVARR : CON_SHIFTVARL;
// if (g_scriptDebug > 1 && !g_errorCnt && !g_warningCnt) // if (g_scriptDebug > 1 && !g_errorCnt && !g_warningCnt)
{ {
initprintf("%s:%d: %s -> %s\n", g_scriptFileName, g_lineNumber, initprintf("%s:%d: %s %s %d -> %s %d\n", g_scriptFileName, g_lineNumber,
VM_GetKeywordForID(tw), VM_GetKeywordForID(opcode)); VM_GetKeywordForID(tw), aGameVars[ins[1]].szLabel, (int)(ins[2]), VM_GetKeywordForID(opcode), C_Pow2IntLogBase2(j));
} }
scriptWriteAtOffset(opcode | LINE_NUMBER, ins); scriptWriteAtOffset(opcode | LINE_NUMBER, ins);
@ -3787,9 +3788,10 @@ setvar:
scriptWriteValue(ins[1]); scriptWriteValue(ins[1]);
initprintf("%s:%d: +++ CON_INV\n", g_scriptFileName, g_lineNumber); initprintf("%s:%d: +++ CON_INV\n", g_scriptFileName, g_lineNumber);
} }
// debug_break();
} }
}
#endif #endif
}
// replace instructions with special versions for specific var types // replace instructions with special versions for specific var types
scriptUpdateOpcodeForVariableType(ins); scriptUpdateOpcodeForVariableType(ins);
continue; continue;