PPU/LLVM: Fix SUBFIC instruction

Fixes sprites in Disgaea 3
This commit is contained in:
Danila Malyutin 2015-08-26 01:39:24 +03:00 committed by Nekotekina
parent 4bf0deecb6
commit 8ea7da56ec
1 changed files with 3 additions and 1 deletions

View File

@ -1676,10 +1676,12 @@ void Compiler::MULLI(u32 rd, u32 ra, s32 simm16) {
void Compiler::SUBFIC(u32 rd, u32 ra, s32 simm16) {
auto ra_i64 = GetGpr(ra);
ra_i64 = m_ir_builder->CreateNeg(ra_i64);
ra_i64 = m_ir_builder->CreateNeg(ra_i64); // simpler way of doing ~ra + 1
auto res_s = m_ir_builder->CreateCall2(Intrinsic::getDeclaration(m_module, Intrinsic::uadd_with_overflow, m_ir_builder->getInt64Ty()), ra_i64, m_ir_builder->getInt64((s64)simm16));
auto diff_i64 = m_ir_builder->CreateExtractValue(res_s, { 0 });
auto carry_i1 = m_ir_builder->CreateExtractValue(res_s, { 1 });
auto is_zero = m_ir_builder->CreateICmpEQ(ra_i64, m_ir_builder->getInt64(0)); // if ra is zero when ~ra + 1 = 0 sets overflow bit
carry_i1 = m_ir_builder->CreateOr(is_zero, carry_i1);
SetGpr(rd, diff_i64);
SetXerCa(carry_i1);
}