mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 04:47:53 +00:00
glsl: Fix IADD CC
This commit is contained in:
parent
a7536825df
commit
bc6e399ae3
2 changed files with 7 additions and 5 deletions
|
@ -227,7 +227,7 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR
|
||||||
ctx.header += "void main(){\n";
|
ctx.header += "void main(){\n";
|
||||||
DefineVariables(ctx, ctx.header);
|
DefineVariables(ctx, ctx.header);
|
||||||
if (ctx.uses_cc_carry) {
|
if (ctx.uses_cc_carry) {
|
||||||
ctx.header += "uint carry;";
|
ctx.header += "uint carry;uint iadd_op_b;";
|
||||||
}
|
}
|
||||||
if (program.info.uses_subgroup_shuffles) {
|
if (program.info.uses_subgroup_shuffles) {
|
||||||
ctx.header += "bool shfl_in_bounds;";
|
ctx.header += "bool shfl_in_bounds;";
|
||||||
|
|
|
@ -33,8 +33,8 @@ void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin
|
||||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||||
if (IR::Inst* const carry{inst.GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp)}) {
|
if (IR::Inst* const carry{inst.GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp)}) {
|
||||||
ctx.uses_cc_carry = true;
|
ctx.uses_cc_carry = true;
|
||||||
ctx.Add("{}=uaddCarry({},{},carry);", result, a, b);
|
ctx.Add("iadd_op_b={};{}=uaddCarry({},{},carry);", b, result, a, b);
|
||||||
ctx.AddU1("{}=carry!=0;", *carry, result);
|
ctx.AddU1("{}=carry!=0;", *carry);
|
||||||
carry->Invalidate();
|
carry->Invalidate();
|
||||||
} else {
|
} else {
|
||||||
ctx.Add("{}={}+{};", result, a, b);
|
ctx.Add("{}={}+{};", result, a, b);
|
||||||
|
@ -44,8 +44,10 @@ void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin
|
||||||
if (IR::Inst * overflow{inst.GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp)}) {
|
if (IR::Inst * overflow{inst.GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp)}) {
|
||||||
// https://stackoverflow.com/questions/55468823/how-to-detect-integer-overflow-in-c
|
// https://stackoverflow.com/questions/55468823/how-to-detect-integer-overflow-in-c
|
||||||
constexpr u32 s32_max{static_cast<u32>(std::numeric_limits<s32>::max())};
|
constexpr u32 s32_max{static_cast<u32>(std::numeric_limits<s32>::max())};
|
||||||
ctx.AddU1("{}=int({})>=0?int({})>int({}-{}):int({})<int({}-{});", *overflow, a, b, s32_max,
|
const auto sub_a{fmt::format("{}u-{}", s32_max, a)};
|
||||||
a, b, s32_max, a);
|
const auto op_b{ctx.uses_cc_carry ? "iadd_op_b" : b};
|
||||||
|
ctx.AddU1("{}=int({})>=0?int({})>int({}):int({})<int({});", *overflow, a, op_b, sub_a, op_b,
|
||||||
|
sub_a);
|
||||||
overflow->Invalidate();
|
overflow->Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue