diff --git a/src/alloy/frontend/ppc/ppc_emit_control.cc b/src/alloy/frontend/ppc/ppc_emit_control.cc index 439a1f02d..5b409eaa4 100644 --- a/src/alloy/frontend/ppc/ppc_emit_control.cc +++ b/src/alloy/frontend/ppc/ppc_emit_control.cc @@ -338,43 +338,75 @@ XEEMITTER(bclrx, 0x4C000020, XL)(PPCHIRBuilder& f, InstrData& i) { // Condition register logical (A-23) XEEMITTER(crand, 0x4C000202, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- CR[ba] & CR[bb] bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.And(ba, bb); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(crandc, 0x4C000102, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- CR[ba] & ¬CR[bb] bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.And(ba, f.Not(bb)); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(creqv, 0x4C000242, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- CR[ba] == CR[bb] bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.CompareEQ(ba, bb); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(crnand, 0x4C0001C2, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- ¬(CR[ba] & CR[bb]) bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.Not(f.And(ba, bb)); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(crnor, 0x4C000042, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- ¬(CR[ba] | CR[bb]) bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.Not(f.Or(ba, bb)); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(cror, 0x4C000382, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- CR[ba] | CR[bb] bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.Or(ba, bb); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(crorc, 0x4C000342, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- CR[ba] | ¬CR[bb] bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.Or(ba, f.Not(bb)); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(crxor, 0x4C000182, XL)(PPCHIRBuilder& f, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // CR[bt] <- CR[ba] xor CR[bb] bt=bo, ba=bi, bb=bb + Value* ba = f.LoadCRField(i.XL.BI >> 2, i.XL.BI & 3); + Value* bb = f.LoadCRField(i.XL.BB >> 2, i.XL.BB & 3); + Value* bt = f.Xor(ba, bb); + f.StoreCRField(i.XL.BO >> 2, i.XL.BO & 3, bt); + return 0; } XEEMITTER(mcrf, 0x4C000000, XL)(PPCHIRBuilder& f, InstrData& i) { diff --git a/src/alloy/frontend/ppc/ppc_hir_builder.cc b/src/alloy/frontend/ppc/ppc_hir_builder.cc index da30e8971..64bf1dae4 100644 --- a/src/alloy/frontend/ppc/ppc_hir_builder.cc +++ b/src/alloy/frontend/ppc/ppc_hir_builder.cc @@ -230,6 +230,10 @@ void PPCHIRBuilder::StoreCR(uint32_t n, Value* value) { assert_always(); } +void PPCHIRBuilder::StoreCRField(uint32_t n, uint32_t bit, Value* value) { + StoreContext(offsetof(PPCContext, cr0) + (4 * n) + bit, value); +} + void PPCHIRBuilder::UpdateCR(uint32_t n, Value* lhs, bool is_signed) { UpdateCR(n, lhs, LoadZero(lhs->type), is_signed); } diff --git a/src/alloy/frontend/ppc/ppc_hir_builder.h b/src/alloy/frontend/ppc/ppc_hir_builder.h index 120bc4d3c..67aeb350b 100644 --- a/src/alloy/frontend/ppc/ppc_hir_builder.h +++ b/src/alloy/frontend/ppc/ppc_hir_builder.h @@ -46,6 +46,7 @@ class PPCHIRBuilder : public hir::HIRBuilder { Value* LoadCR(uint32_t n); Value* LoadCRField(uint32_t n, uint32_t bit); void StoreCR(uint32_t n, Value* value); + void StoreCRField(uint32_t n, uint32_t bit, Value* value); void UpdateCR(uint32_t n, Value* lhs, bool is_signed = true); void UpdateCR(uint32_t n, Value* lhs, Value* rhs, bool is_signed = true); void UpdateCR6(Value* src_value);