From 6fd7e35deb688ec995541b5218db0c3fdb5923f6 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Wed, 13 May 2015 00:15:35 -0700 Subject: [PATCH] Fixing subfme. --- .../passes/constant_propagation_pass.cc | 24 ++++++++++++++----- src/xenia/cpu/frontend/ppc_emit_alu.cc | 5 ++-- src/xenia/cpu/frontend/test/instr_subfme.s | 6 ++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc b/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc index 54d9ac836..b9dc393c7 100644 --- a/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc +++ b/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc @@ -318,12 +318,19 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder) { } } } - if (i->dest->type == ca->type) { - i->Replace(&OPCODE_ASSIGN_info, 0); - i->set_src1(ca); + if (ca->IsConstant()) { + TypeName target_type = v->type; + v->set_from(ca); + v->ZeroExtend(target_type); + i->Remove(); } else { - i->Replace(&OPCODE_ZERO_EXTEND_info, 0); - i->set_src1(ca); + if (i->dest->type == ca->type) { + i->Replace(&OPCODE_ASSIGN_info, 0); + i->set_src1(ca); + } else { + i->Replace(&OPCODE_ZERO_EXTEND_info, 0); + i->set_src1(ca); + } } } break; @@ -404,6 +411,11 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder) { v->set_from(i->src1.value); v->Xor(i->src2.value); i->Remove(); + } else if (!i->src1.value->IsConstant() && + !i->src2.value->IsConstant() && + i->src1.value == i->src2.value) { + v->set_zero(v->type); + i->Remove(); } break; case OPCODE_NOT: @@ -478,7 +490,7 @@ void ConstantPropagationPass::PropagateCarry(Value* v, bool did_carry) { next = use->next; if (use->instr->opcode == &OPCODE_DID_CARRY_info) { // Replace carry value. - use->instr->dest->set_constant(did_carry ? 1 : 0); + use->instr->dest->set_constant(int8_t(did_carry ? 1 : 0)); use->instr->Remove(); } } diff --git a/src/xenia/cpu/frontend/ppc_emit_alu.cc b/src/xenia/cpu/frontend/ppc_emit_alu.cc index 37506f014..c5f07b572 100644 --- a/src/xenia/cpu/frontend/ppc_emit_alu.cc +++ b/src/xenia/cpu/frontend/ppc_emit_alu.cc @@ -466,8 +466,9 @@ XEEMITTER(subfex, 0x7C000110, XO)(PPCHIRBuilder& f, InstrData& i) { XEEMITTER(subfmex, 0x7C0001D0, XO)(PPCHIRBuilder& f, InstrData& i) { // RT <- ¬(RA) + CA - 1 - Value* v = f.AddWithCarry(f.Not(f.LoadGPR(i.XO.RA)), - f.LoadConstant((int64_t)-1), f.LoadCA()); + Value* v = + f.AddWithCarry(f.Not(f.LoadGPR(i.XO.RA)), f.LoadConstant((int64_t)-1), + f.LoadCA(), ARITHMETIC_SET_CARRY); if (i.XO.OE) { assert_always(); // e.update_xer_with_overflow_and_carry(b.CreateExtractValue(v, 1)); diff --git a/src/xenia/cpu/frontend/test/instr_subfme.s b/src/xenia/cpu/frontend/test/instr_subfme.s index 14dd6567b..37cce8886 100644 --- a/src/xenia/cpu/frontend/test/instr_subfme.s +++ b/src/xenia/cpu/frontend/test/instr_subfme.s @@ -55,7 +55,7 @@ test_subfme_zero_ca_1: blr #_ REGISTER_OUT r10 0x00000000000103BF #_ REGISTER_OUT r3 0xfffffffffffefc3f - #_ REGISTER_OUT r4 0 + #_ REGISTER_OUT r4 1 test_subfme_zero_ca_2: #_ REGISTER_IN r10 0 @@ -66,7 +66,7 @@ test_subfme_zero_ca_2: blr #_ REGISTER_OUT r10 0 #_ REGISTER_OUT r3 0xfffffffffffffffe - #_ REGISTER_OUT r4 0 + #_ REGISTER_OUT r4 1 test_subfme_zero_ca_3: #_ REGISTER_IN r10 1 @@ -77,7 +77,7 @@ test_subfme_zero_ca_3: blr #_ REGISTER_OUT r10 1 #_ REGISTER_OUT r3 0xfffffffffffffffd - #_ REGISTER_OUT r4 0 + #_ REGISTER_OUT r4 1 test_subfme_zero_ca_4: #_ REGISTER_IN r10 0xFFFFFFFFFFFFFFFF