Hacky ALU ops. Need overflow checks.

This commit is contained in:
Ben Vanik 2013-05-22 21:14:16 -07:00
parent 9ed911cdad
commit 5cb8cf2630
1 changed files with 66 additions and 65 deletions

View File

@ -82,18 +82,18 @@ XEEMITTER(addi, 0x38000000, D )(LibjitEmitter& e, jit_function_t f, Ins
return 0; return 0;
} }
// XEEMITTER(addic, 0x30000000, D )(LibjitEmitter& e, jit_function_t f, InstrData& i) { XEEMITTER(addic, 0x30000000, D )(LibjitEmitter& e, jit_function_t f, InstrData& i) {
// // RT <- (RA) + EXTS(SI) // RT <- (RA) + EXTS(SI)
// Function* sadd_with_overflow = Intrinsic::getDeclaration( // TODO(benvanik): track exception
// e.gen_module(), Intrinsic::sadd_with_overflow, jit_type_nint); jit_value_t v = jit_insn_add_ovf(f, e.make_signed(e.gpr_value(i.D.RA)),
// jit_value_t v = b.CreateCall2(sadd_with_overflow, e.get_int64(XEEXTS16(i.D.DS)));
// e.gpr_value(i.D.RA), e.get_int64(XEEXTS16(i.D.DS)));
// e.update_gpr_value(i.D.RT, b.CreateExtractValue(v, 0));
// e.update_xer_with_carry(b.CreateExtractValue(v, 1));
// return 0; e.update_gpr_value(i.D.RT, v);
// } // e.update_xer_with_carry(b.CreateExtractValue(v, 1));
return 0;
}
XEEMITTER(addicx, 0x34000000, D )(LibjitEmitter& e, jit_function_t f, InstrData& i) { XEEMITTER(addicx, 0x34000000, D )(LibjitEmitter& e, jit_function_t f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
@ -362,40 +362,41 @@ XEEMITTER(mullwx, 0x7C0001D6, XO )(LibjitEmitter& e, jit_function_t f, Ins
// } // }
// } // }
// XEEMITTER(subfx, 0x7C000050, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) { XEEMITTER(subfx, 0x7C000050, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) {
// // RT <- ¬(RA) + (RB) + 1 // RT <- ¬(RA) + (RB) + 1
// if (i.XO.OE) { if (i.XO.OE) {
// // With XER update. // With XER update.
// // This is a different codepath as we need to use llvm.ssub.with.overflow. // This is a different codepath as we need to use llvm.ssub.with.overflow.
// Function* ssub_with_overflow = Intrinsic::getDeclaration( // TODO(benvanik): handle overflow exceptions.
// e.gen_module(), Intrinsic::ssub_with_overflow, jit_type_nint); jit_value_t v = jit_insn_sub_ovf(f,
// jit_value_t v = b.CreateCall2(ssub_with_overflow, e.make_signed(e.gpr_value(i.XO.RB)),
// e.gpr_value(i.XO.RB), e.gpr_value(i.XO.RA)); e.make_signed(e.gpr_value(i.XO.RA)));
// jit_value_t v0 = b.CreateExtractValue(v, 0); e.update_gpr_value(i.XO.RT, v);
// e.update_gpr_value(i.XO.RT, v0); //e.update_xer_with_overflow(b.CreateExtractValue(v, 1));
// e.update_xer_with_overflow(b.CreateExtractValue(v, 1));
// if (i.XO.Rc) { if (i.XO.Rc) {
// // With cr0 update. // With cr0 update.
// e.update_cr_with_cond(0, v0, e.get_int64(0), true); e.update_cr_with_cond(0, v, e.get_int64(0), true);
// } }
// return 0; return 0;
// } else { } else {
// // No OE bit setting. // No OE bit setting.
// jit_value_t v = b.CreateSub(e.gpr_value(i.XO.RB), e.gpr_value(i.XO.RA)); jit_value_t v = jit_insn_sub(f,
// e.update_gpr_value(i.XO.RT, v); e.make_signed(e.gpr_value(i.XO.RB)),
e.make_signed(e.gpr_value(i.XO.RA)));
e.update_gpr_value(i.XO.RT, v);
// if (i.XO.Rc) { if (i.XO.Rc) {
// // With cr0 update. // With cr0 update.
// e.update_cr_with_cond(0, v, e.get_int64(0), true); e.update_cr_with_cond(0, v, e.get_int64(0), true);
// } }
// return 0; return 0;
// } }
// } }
XEEMITTER(subfcx, 0x7C000010, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) { XEEMITTER(subfcx, 0x7C000010, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
@ -415,35 +416,35 @@ XEEMITTER(subfcx, 0x7C000010, XO )(LibjitEmitter& e, jit_function_t f, Ins
// return 0; // return 0;
// } // }
// XEEMITTER(subfex, 0x7C000110, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) { XEEMITTER(subfex, 0x7C000110, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) {
// // RT <- ¬(RA) + (RB) + CA // RT <- ¬(RA) + (RB) + CA
// // TODO(benvanik): possible that the add of rb+ca needs to also check for // TODO(benvanik): possible that the add of rb+ca needs to also check for
// // overflow! // overflow!
// jit_value_t ca = jit_insn_and(f, jit_insn_ushr(f, e.xer_value(), 29), 0x1); // TODO(benvanik): handle overflow exception
// Function* uadd_with_overflow = Intrinsic::getDeclaration( jit_value_t ca = jit_insn_and(f, jit_insn_ushr(f, e.xer_value(),
// e.gen_module(), Intrinsic::uadd_with_overflow, jit_type_nint); e.get_uint32(29)),
// jit_value_t v = b.CreateCall2(uadd_with_overflow, e.get_uint64(0x1));
// b.CreateNeg(e.gpr_value(i.XO.RA)), jit_value_t v = jit_insn_add_ovf(f,
// b.CreateAdd(e.gpr_value(i.XO.RB), ca)); e.make_unsigned(jit_insn_neg(f, e.gpr_value(i.XO.RA))),
// jit_value_t v0 = b.CreateExtractValue(v, 0); e.make_unsigned(jit_insn_add(f, e.gpr_value(i.XO.RB), ca)));
// e.update_gpr_value(i.XO.RT, v0); e.update_gpr_value(i.XO.RT, v);
// if (i.XO.OE) { // if (i.XO.OE) {
// // With XER update. // // With XER update.
// e.update_xer_with_overflow_and_carry(b.CreateExtractValue(v, 1)); // e.update_xer_with_overflow_and_carry(b.CreateExtractValue(v, 1));
// } else { // } else {
// e.update_xer_with_carry(b.CreateExtractValue(v, 1)); // e.update_xer_with_carry(b.CreateExtractValue(v, 1));
// } // }
// if (i.XO.Rc) { if (i.XO.Rc) {
// // With cr0 update. // With cr0 update.
// e.update_cr_with_cond(0, v0, e.get_int64(0), true); e.update_cr_with_cond(0, v, e.get_int64(0), true);
// } }
// return 0; return 0;
// } }
XEEMITTER(subfmex, 0x7C0001D0, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) { XEEMITTER(subfmex, 0x7C0001D0, XO )(LibjitEmitter& e, jit_function_t f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
@ -1022,7 +1023,7 @@ void LibjitRegisterEmitCategoryALU() {
XEREGISTERINSTR(addcx, 0X7C000014); XEREGISTERINSTR(addcx, 0X7C000014);
XEREGISTERINSTR(addex, 0x7C000114); XEREGISTERINSTR(addex, 0x7C000114);
XEREGISTERINSTR(addi, 0x38000000); XEREGISTERINSTR(addi, 0x38000000);
//XEREGISTERINSTR(addic, 0x30000000); XEREGISTERINSTR(addic, 0x30000000);
XEREGISTERINSTR(addicx, 0x34000000); XEREGISTERINSTR(addicx, 0x34000000);
XEREGISTERINSTR(addis, 0x3C000000); XEREGISTERINSTR(addis, 0x3C000000);
XEREGISTERINSTR(addmex, 0x7C0001D4); XEREGISTERINSTR(addmex, 0x7C0001D4);
@ -1039,10 +1040,10 @@ void LibjitRegisterEmitCategoryALU() {
XEREGISTERINSTR(mulli, 0x1C000000); XEREGISTERINSTR(mulli, 0x1C000000);
XEREGISTERINSTR(mullwx, 0x7C0001D6); XEREGISTERINSTR(mullwx, 0x7C0001D6);
//XEREGISTERINSTR(negx, 0x7C0000D0); //XEREGISTERINSTR(negx, 0x7C0000D0);
//XEREGISTERINSTR(subfx, 0x7C000050); XEREGISTERINSTR(subfx, 0x7C000050);
XEREGISTERINSTR(subfcx, 0x7C000010); XEREGISTERINSTR(subfcx, 0x7C000010);
//XEREGISTERINSTR(subficx, 0x20000000); //XEREGISTERINSTR(subficx, 0x20000000);
//XEREGISTERINSTR(subfex, 0x7C000110); XEREGISTERINSTR(subfex, 0x7C000110);
XEREGISTERINSTR(subfmex, 0x7C0001D0); XEREGISTERINSTR(subfmex, 0x7C0001D0);
XEREGISTERINSTR(subfzex, 0x7C000190); XEREGISTERINSTR(subfzex, 0x7C000190);
XEREGISTERINSTR(cmp, 0x7C000000); XEREGISTERINSTR(cmp, 0x7C000000);