backend/arm64: Fix Sub
This commit is contained in:
parent
46f4063952
commit
95ae21bd41
1 changed files with 28 additions and 10 deletions
|
@ -493,9 +493,9 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst*
|
||||||
RegAlloc::Realize(Rresult, Ra, flags);
|
RegAlloc::Realize(Rresult, Ra, flags);
|
||||||
|
|
||||||
if (args[2].GetImmediateU1()) {
|
if (args[2].GetImmediateU1()) {
|
||||||
MaybeAddSubImm<bitsize>(code, ~imm, [&](const auto b) { sub ? code.ADDS(Rresult, *Ra, b) : code.SUBS(Rresult, *Ra, b); });
|
MaybeAddSubImm<bitsize>(code, sub ? imm : ~imm, [&](const auto b) { code.SUBS(Rresult, *Ra, b); });
|
||||||
} else {
|
} else {
|
||||||
MaybeAddSubImm<bitsize>(code, imm, [&](const auto b) { sub ? code.SUBS(Rresult, *Ra, b) : code.ADDS(Rresult, *Ra, b); });
|
MaybeAddSubImm<bitsize>(code, sub ? ~imm : imm, [&](const auto b) { code.ADDS(Rresult, *Ra, b); });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RegAlloc::Realize(Rresult, Ra);
|
RegAlloc::Realize(Rresult, Ra);
|
||||||
|
@ -512,10 +512,19 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst*
|
||||||
RegAlloc::Realize(Rresult, Ra, Rb, flags);
|
RegAlloc::Realize(Rresult, Ra, Rb, flags);
|
||||||
|
|
||||||
if (args[2].GetImmediateU1()) {
|
if (args[2].GetImmediateU1()) {
|
||||||
code.MVN(Rscratch0<bitsize>(), Rb);
|
if (sub) {
|
||||||
sub ? code.ADDS(Rresult, *Ra, Rscratch0<bitsize>()) : code.SUBS(Rresult, *Ra, Rscratch0<bitsize>());
|
code.SUBS(Rresult, *Ra, Rb);
|
||||||
|
} else {
|
||||||
|
code.MVN(Rscratch0<bitsize>(), Rb);
|
||||||
|
code.SUBS(Rresult, *Ra, Rscratch0<bitsize>());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sub ? code.SUBS(Rresult, *Ra, Rb) : code.ADDS(Rresult, *Ra, Rb);
|
if (sub) {
|
||||||
|
code.MVN(Rscratch0<bitsize>(), Rb);
|
||||||
|
code.ADDS(Rresult, *Ra, Rscratch0<bitsize>());
|
||||||
|
} else {
|
||||||
|
code.ADDS(Rresult, *Ra, Rb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RegAlloc::Realize(Rresult, Ra, Rb);
|
RegAlloc::Realize(Rresult, Ra, Rb);
|
||||||
|
@ -532,9 +541,9 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst*
|
||||||
|
|
||||||
if (args[2].IsImmediate()) {
|
if (args[2].IsImmediate()) {
|
||||||
if (args[2].GetImmediateU1()) {
|
if (args[2].GetImmediateU1()) {
|
||||||
MaybeAddSubImm<bitsize>(code, ~imm, [&](const auto b) { sub ? code.ADD(Rresult, *Ra, b) : code.SUB(Rresult, *Ra, b); });
|
MaybeAddSubImm<bitsize>(code, sub ? imm : ~imm, [&](const auto b) { code.SUB(Rresult, *Ra, b); });
|
||||||
} else {
|
} else {
|
||||||
MaybeAddSubImm<bitsize>(code, imm, [&](const auto b) { sub ? code.SUB(Rresult, *Ra, b) : code.ADD(Rresult, *Ra, b); });
|
MaybeAddSubImm<bitsize>(code, sub ? ~imm : imm, [&](const auto b) { code.ADD(Rresult, *Ra, b); });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code.MOV(Rscratch0<bitsize>(), imm);
|
code.MOV(Rscratch0<bitsize>(), imm);
|
||||||
|
@ -547,10 +556,19 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst*
|
||||||
|
|
||||||
if (args[2].IsImmediate()) {
|
if (args[2].IsImmediate()) {
|
||||||
if (args[2].GetImmediateU1()) {
|
if (args[2].GetImmediateU1()) {
|
||||||
code.MVN(Rscratch0<bitsize>(), Rb);
|
if (sub) {
|
||||||
sub ? code.ADD(Rresult, *Ra, Rscratch0<bitsize>()) : code.SUB(Rresult, *Ra, Rscratch0<bitsize>());
|
code.SUB(Rresult, *Ra, Rb);
|
||||||
|
} else {
|
||||||
|
code.MVN(Rscratch0<bitsize>(), Rb);
|
||||||
|
code.SUB(Rresult, *Ra, Rscratch0<bitsize>());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sub ? code.SUB(Rresult, *Ra, Rb) : code.ADD(Rresult, *Ra, Rb);
|
if (sub) {
|
||||||
|
code.MVN(Rscratch0<bitsize>(), Rb);
|
||||||
|
code.ADD(Rresult, *Ra, Rscratch0<bitsize>());
|
||||||
|
} else {
|
||||||
|
code.ADD(Rresult, *Ra, Rb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sub ? code.SBC(Rresult, Ra, Rb) : code.ADC(Rresult, Ra, Rb);
|
sub ? code.SBC(Rresult, Ra, Rb) : code.ADC(Rresult, Ra, Rb);
|
||||||
|
|
Loading…
Reference in a new issue