summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-28 15:51:50 -0400
committerGravatar ameerj2021-07-22 21:51:36 -0400
commit21797efa548598692a82a25959865236bd9e7116 (patch)
tree2d5b629fbbe67ff11f908b9d019a7e653451a2a0 /src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
parentglsl: SSBO access fixes and wip SampleExplicitLod implementation. (diff)
downloadyuzu-21797efa548598692a82a25959865236bd9e7116.tar.gz
yuzu-21797efa548598692a82a25959865236bd9e7116.tar.xz
yuzu-21797efa548598692a82a25959865236bd9e7116.zip
glsl: Implement IADD CC
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp17
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
30void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { 30void 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
37void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { 50void 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
181void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { 194void 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
185void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { 198void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {