diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp index 6654fce81..6ff0f9248 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | |||
| @@ -29,9 +29,22 @@ void SetSignFlag(EmitContext& ctx, IR::Inst& inst, std::string_view result) { | |||
| 29 | } // Anonymous namespace | 29 | } // Anonymous namespace |
| 30 | void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { | 30 | void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { |
| 31 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; | 31 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; |
| 32 | ctx.Add("{}={}+{};", result, a, b); | 32 | if (IR::Inst* const carry{inst.GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp)}) { |
| 33 | ctx.Add("{}=uaddCarry({},{},carry);", result, a, b); | ||
| 34 | ctx.AddU1("{}=carry!=0;", *carry, result); | ||
| 35 | carry->Invalidate(); | ||
| 36 | } else { | ||
| 37 | ctx.Add("{}={}+{};", result, a, b); | ||
| 38 | } | ||
| 33 | SetZeroFlag(ctx, inst, result); | 39 | SetZeroFlag(ctx, inst, result); |
| 34 | SetSignFlag(ctx, inst, result); | 40 | SetSignFlag(ctx, inst, result); |
| 41 | if (IR::Inst * overflow{inst.GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp)}) { | ||
| 42 | // https://stackoverflow.com/questions/55468823/how-to-detect-integer-overflow-in-c | ||
| 43 | constexpr u32 s32_max{static_cast<u32>(std::numeric_limits<s32>::max())}; | ||
| 44 | ctx.AddU1("{}=int({})>=0?int({})>int({}-{}):int({})<int({}-{});", *overflow, a, b, s32_max, | ||
| 45 | a, b, s32_max, a); | ||
| 46 | overflow->Invalidate(); | ||
| 47 | } | ||
| 35 | } | 48 | } |
| 36 | 49 | ||
| 37 | void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { | 50 | void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { |
| @@ -179,7 +192,7 @@ void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std:: | |||
| 179 | } | 192 | } |
| 180 | 193 | ||
| 181 | void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { | 194 | void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { |
| 182 | ctx.AddU1("{}=uint({})<uint({)};", inst, lhs, rhs); | 195 | ctx.AddU1("{}=uint({})<uint({});", inst, lhs, rhs); |
| 183 | } | 196 | } |
| 184 | 197 | ||
| 185 | void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { | 198 | void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { |