Index: src/ppc/simulator-ppc.cc |
diff --git a/src/ppc/simulator-ppc.cc b/src/ppc/simulator-ppc.cc |
index 817e75626282ce9595d4814086844264777c98b5..123ceb8838d574a5e0d43352920640e587af59b9 100644 |
--- a/src/ppc/simulator-ppc.cc |
+++ b/src/ppc/simulator-ppc.cc |
@@ -2025,19 +2025,37 @@ bool Simulator::ExecuteExt2_9bit_part1(Instruction* instr) { |
uintptr_t ra_val = get_register(ra); |
uintptr_t rb_val = get_register(rb); |
uintptr_t alu_out = ~ra_val + rb_val + 1; |
- set_register(rt, alu_out); |
- // If the sign of rb and alu_out don't match, carry = 0 |
- if ((alu_out ^ rb_val) & 0x80000000) { |
- special_reg_xer_ &= ~0xF0000000; |
- } else { |
+ // Set carry |
+ if (ra_val <= rb_val) { |
special_reg_xer_ = (special_reg_xer_ & ~0xF0000000) | 0x20000000; |
+ } else { |
+ special_reg_xer_ &= ~0xF0000000; |
} |
+ set_register(rt, alu_out); |
if (instr->Bit(0)) { // RC bit set |
SetCR0(alu_out); |
} |
// todo - handle OE bit |
break; |
} |
+ case SUBFEX: { |
+ int rt = instr->RTValue(); |
+ int ra = instr->RAValue(); |
+ int rb = instr->RBValue(); |
+ // int oe = instr->Bit(10); |
+ uintptr_t ra_val = get_register(ra); |
+ uintptr_t rb_val = get_register(rb); |
+ uintptr_t alu_out = ~ra_val + rb_val; |
+ if (special_reg_xer_ & 0x20000000) { |
+ alu_out += 1; |
+ } |
+ set_register(rt, alu_out); |
+ if (instr->Bit(0)) { // RC bit set |
+ SetCR0(static_cast<intptr_t>(alu_out)); |
+ } |
+ // todo - handle OE bit |
+ break; |
+ } |
case ADDCX: { |
int rt = instr->RTValue(); |
int ra = instr->RAValue(); |