VarAction2: Allow DSGA_OP_STO_NC to be used with DSGA_TYPE_EQ/NEQ

pull/393/head
Jonathan G Rennison 2 years ago
parent d3dce79d73
commit 65407210a6

@ -6394,13 +6394,13 @@ static bool CheckDeterministicSpriteGroupOutputVarBits(const DeterministicSprite
bits.set(adjust.and_mask, false);
}
}
if (adjust.operation == DSGA_OP_STO_NC && adjust.add_val < 0x100) {
if (!bits[adjust.add_val]) {
if (adjust.operation == DSGA_OP_STO_NC && adjust.divmod_val < 0x100) {
if (!bits[adjust.divmod_val]) {
/* Possibly redundant store */
dse = true;
if (quick_exit) break;
}
bits.set(adjust.add_val, false);
bits.set(adjust.divmod_val, false);
}
if (adjust.variable == 0x7B && adjust.parameter == 0x7D) {
/* Unpredictable load */
@ -6500,7 +6500,7 @@ static bool OptimiseVarAction2DeterministicSpriteGroupExpensiveVarsInner(const G
load.shift_num = 0;
load.parameter = target_param;
load.and_mask = and_mask;
load.add_val = bit;
load.divmod_val = bit;
group->adjusts.insert(group->adjusts.begin() + insert_pos, load);
};
@ -6510,8 +6510,8 @@ static bool OptimiseVarAction2DeterministicSpriteGroupExpensiveVarsInner(const G
const DeterministicSpriteGroupAdjust &adjust = group->adjusts[i];
if (adjust.operation == DSGA_OP_STO && (adjust.type != DSGA_TYPE_NONE || adjust.variable != 0x1A || adjust.shift_num != 0)) return false;
if (adjust.variable == 0x7B && adjust.parameter == 0x7D) return false;
if (adjust.operation == DSGA_OP_STO_NC && adjust.add_val < 0x100) {
usable_vars.set(adjust.add_val, false);
if (adjust.operation == DSGA_OP_STO_NC && adjust.divmod_val < 0x100) {
usable_vars.set(adjust.divmod_val, false);
}
if (adjust.operation == DSGA_OP_STO && adjust.and_mask < 0x100) {
usable_vars.set(adjust.and_mask, false);
@ -6522,7 +6522,7 @@ static bool OptimiseVarAction2DeterministicSpriteGroupExpensiveVarsInner(const G
} else if (feature == GSF_INDUSTRYTILES && group->var_scope == VSG_SCOPE_SELF && IsExpensiveIndustryTileVariable(adjust.variable)) {
seen_expensive_variables[(((uint64)adjust.variable) << 32) | adjust.parameter]++;
}
if (adjust.variable == 0x7E || (adjust.operation == DSGA_OP_STO && adjust.and_mask >= 0x100) || (adjust.operation == DSGA_OP_STO_NC && adjust.add_val >= 0x100)) {
if (adjust.variable == 0x7E || (adjust.operation == DSGA_OP_STO && adjust.and_mask >= 0x100) || (adjust.operation == DSGA_OP_STO_NC && adjust.divmod_val >= 0x100)) {
/* Can't cross this barrier, stop here */
if (usable_vars.none()) return false;
if (found_target()) {
@ -6577,7 +6577,7 @@ static void OptimiseVarAction2DeterministicSpriteGroupSimplifyStores(Determinist
DeterministicSpriteGroupAdjust &adjust = group->adjusts[i];
if (adjust.type == DSGA_TYPE_NONE && adjust.operation == DSGA_OP_RST && adjust.variable != 0x7E) {
if ((adjust.type == DSGA_TYPE_NONE || adjust.type == DSGA_TYPE_EQ || adjust.type == DSGA_TYPE_NEQ) && adjust.operation == DSGA_OP_RST && adjust.variable != 0x7E) {
src_adjust = (int)i;
is_constant = (adjust.variable == 0x1A);
continue;
@ -6610,8 +6610,10 @@ static void OptimiseVarAction2DeterministicSpriteGroupSimplifyStores(Determinist
if (ok) {
const DeterministicSpriteGroupAdjust &src = group->adjusts[src_adjust];
adjust.operation = DSGA_OP_STO_NC;
adjust.type = src.type;
adjust.adjust_flags = DSGAF_NONE;
adjust.add_val = adjust.and_mask;
adjust.divmod_val = adjust.and_mask;
adjust.add_val = src.add_val;
adjust.variable = src.variable;
adjust.parameter = src.parameter;
adjust.shift_num = src.shift_num;

@ -199,7 +199,7 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust &adjust, ScopeResolver
case DSGA_OP_SLE: return ((S)last_value <= (S)value) ? 1 : 0;
case DSGA_OP_SGT: return ((S)last_value > (S)value) ? 1 : 0;
case DSGA_OP_RSUB: return value - last_value;
case DSGA_OP_STO_NC: _temp_store.StoreValue(adjust.add_val, (S)value); return last_value;
case DSGA_OP_STO_NC: _temp_store.StoreValue(adjust.divmod_val, (S)value); return last_value;
default: return value;
}
}
@ -837,8 +837,8 @@ void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, int padding, uint
case DSGA_TYPE_NONE: break;
}
if (adjust.operation == DSGA_OP_STO_NC) {
p += seprintf(p, lastof(this->buffer), ", store to: %X", adjust.add_val);
highlight_tag = (1 << 16) | adjust.add_val;
p += seprintf(p, lastof(this->buffer), ", store to: %X", adjust.divmod_val);
highlight_tag = (1 << 16) | adjust.divmod_val;
}
p += seprintf(p, lastof(this->buffer), ", op: ");
p = GetAdjustOperationName(p, lastof(this->buffer), adjust.operation);

@ -345,8 +345,8 @@ struct DeterministicSpriteGroupAdjust {
DeterministicSpriteGroupAdjustFlags adjust_flags = DSGAF_NONE;
uint32 parameter; ///< Used for variables between 0x60 and 0x7F inclusive.
uint32 and_mask;
uint32 add_val;
uint32 divmod_val;
uint32 add_val; ///< Also used for DSGA_TYPE_EQ/DSGA_TYPE_NEQ constants and DSGA_OP_TERNARY false value
uint32 divmod_val; ///< Also used for DSGA_OP_STO_NC
const SpriteGroup *subroutine;
};

Loading…
Cancel
Save