summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_instructions.h2
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_integer.cpp8
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_instructions.h2
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp8
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_instructions.h2
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp8
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.cpp4
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.h1
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.inc2
9 files changed, 37 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
index cb7232704..4f8dd8e42 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
@@ -304,6 +304,8 @@ void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, Register a, Register b);
304void EmitISub32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); 304void EmitISub32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b);
305void EmitISub64(EmitContext& ctx, IR::Inst& inst, Register a, Register b); 305void EmitISub64(EmitContext& ctx, IR::Inst& inst, Register a, Register b);
306void EmitIMul32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); 306void EmitIMul32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b);
307void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b);
308void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, ScalarU32 a, ScalarU32 b);
307void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value); 309void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value);
308void EmitINeg64(EmitContext& ctx, IR::Inst& inst, Register value); 310void EmitINeg64(EmitContext& ctx, IR::Inst& inst, Register value);
309void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value); 311void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value);
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_integer.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_integer.cpp
index f55c26b76..8aa494a4d 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_integer.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_integer.cpp
@@ -90,6 +90,14 @@ void EmitIMul32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b) {
90 ctx.Add("MUL.S {}.x,{},{};", inst, a, b); 90 ctx.Add("MUL.S {}.x,{},{};", inst, a, b);
91} 91}
92 92
93void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b) {
94 ctx.Add("DIV.S {}.x,{},{};", inst, a, b);
95}
96
97void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, ScalarU32 a, ScalarU32 b) {
98 ctx.Add("DIV.U {}.x,{},{};", inst, a, b);
99}
100
93void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value) { 101void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value) {
94 if (value.type != Type::Register && static_cast<s32>(value.imm_u32) < 0) { 102 if (value.type != Type::Register && static_cast<s32>(value.imm_u32) < 0) {
95 ctx.Add("MOV.S {},{};", inst, -static_cast<s32>(value.imm_u32)); 103 ctx.Add("MOV.S {},{};", inst, -static_cast<s32>(value.imm_u32));
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
index 6cae0b84a..159e4b770 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
@@ -363,6 +363,8 @@ void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin
363void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); 363void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
364void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); 364void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
365void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); 365void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
366void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
367void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
366void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value); 368void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
367void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value); 369void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
368void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value); 370void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
index 38419f88f..88c1d4c5e 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
@@ -78,6 +78,14 @@ void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin
78 ctx.AddU32("{}=uint({}*{});", inst, a, b); 78 ctx.AddU32("{}=uint({}*{});", inst, a, b);
79} 79}
80 80
81void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
82 ctx.AddU32("{}=uint(int({})/int({}));", inst, a, b);
83}
84
85void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
86 ctx.AddU32("{}={}/{};", inst, a, b);
87}
88
81void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { 89void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
82 ctx.AddU32("{}=uint(-({}));", inst, value); 90 ctx.AddU32("{}=uint(-({}));", inst, value);
83} 91}
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
index 3d90b2286..44eda16ca 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
@@ -284,6 +284,8 @@ Id EmitIAdd64(EmitContext& ctx, Id a, Id b);
284Id EmitISub32(EmitContext& ctx, Id a, Id b); 284Id EmitISub32(EmitContext& ctx, Id a, Id b);
285Id EmitISub64(EmitContext& ctx, Id a, Id b); 285Id EmitISub64(EmitContext& ctx, Id a, Id b);
286Id EmitIMul32(EmitContext& ctx, Id a, Id b); 286Id EmitIMul32(EmitContext& ctx, Id a, Id b);
287Id EmitSDiv32(EmitContext& ctx, Id a, Id b);
288Id EmitUDiv32(EmitContext& ctx, Id a, Id b);
287Id EmitINeg32(EmitContext& ctx, Id value); 289Id EmitINeg32(EmitContext& ctx, Id value);
288Id EmitINeg64(EmitContext& ctx, Id value); 290Id EmitINeg64(EmitContext& ctx, Id value);
289Id EmitIAbs32(EmitContext& ctx, Id value); 291Id EmitIAbs32(EmitContext& ctx, Id value);
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp
index 3501d7495..50277eec3 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp
@@ -72,6 +72,14 @@ Id EmitIMul32(EmitContext& ctx, Id a, Id b) {
72 return ctx.OpIMul(ctx.U32[1], a, b); 72 return ctx.OpIMul(ctx.U32[1], a, b);
73} 73}
74 74
75Id EmitSDiv32(EmitContext& ctx, Id a, Id b) {
76 return ctx.OpSDiv(ctx.U32[1], a, b);
77}
78
79Id EmitUDiv32(EmitContext& ctx, Id a, Id b) {
80 return ctx.OpUDiv(ctx.U32[1], a, b);
81}
82
75Id EmitINeg32(EmitContext& ctx, Id value) { 83Id EmitINeg32(EmitContext& ctx, Id value) {
76 return ctx.OpSNegate(ctx.U32[1], value); 84 return ctx.OpSNegate(ctx.U32[1], value);
77} 85}
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
index 9ae5da2a1..3dfba8e71 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
@@ -1145,6 +1145,10 @@ U32 IREmitter::IMul(const U32& a, const U32& b) {
1145 return Inst<U32>(Opcode::IMul32, a, b); 1145 return Inst<U32>(Opcode::IMul32, a, b);
1146} 1146}
1147 1147
1148U32 IREmitter::IDiv(const U32& a, const U32& b, bool is_signed) {
1149 return Inst<U32>(is_signed ? Opcode::SDiv32 : Opcode::UDiv32, a, b);
1150}
1151
1148U32U64 IREmitter::INeg(const U32U64& value) { 1152U32U64 IREmitter::INeg(const U32U64& value) {
1149 switch (value.Type()) { 1153 switch (value.Type()) {
1150 case Type::U32: 1154 case Type::U32:
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h
index 0c664d2fe..1959be42e 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.h
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.h
@@ -209,6 +209,7 @@ public:
209 [[nodiscard]] U32U64 IAdd(const U32U64& a, const U32U64& b); 209 [[nodiscard]] U32U64 IAdd(const U32U64& a, const U32U64& b);
210 [[nodiscard]] U32U64 ISub(const U32U64& a, const U32U64& b); 210 [[nodiscard]] U32U64 ISub(const U32U64& a, const U32U64& b);
211 [[nodiscard]] U32 IMul(const U32& a, const U32& b); 211 [[nodiscard]] U32 IMul(const U32& a, const U32& b);
212 [[nodiscard]] U32 IDiv(const U32& a, const U32& b, bool is_signed = false);
212 [[nodiscard]] U32U64 INeg(const U32U64& value); 213 [[nodiscard]] U32U64 INeg(const U32U64& value);
213 [[nodiscard]] U32 IAbs(const U32& value); 214 [[nodiscard]] U32 IAbs(const U32& value);
214 [[nodiscard]] U32U64 ShiftLeftLogical(const U32U64& base, const U32& shift); 215 [[nodiscard]] U32U64 ShiftLeftLogical(const U32U64& base, const U32& shift);
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc
index 72751c5a0..c05e6d312 100644
--- a/src/shader_recompiler/frontend/ir/opcodes.inc
+++ b/src/shader_recompiler/frontend/ir/opcodes.inc
@@ -287,6 +287,8 @@ OPCODE(IAdd64, U64, U64,
287OPCODE(ISub32, U32, U32, U32, ) 287OPCODE(ISub32, U32, U32, U32, )
288OPCODE(ISub64, U64, U64, U64, ) 288OPCODE(ISub64, U64, U64, U64, )
289OPCODE(IMul32, U32, U32, U32, ) 289OPCODE(IMul32, U32, U32, U32, )
290OPCODE(SDiv32, U32, U32, U32, )
291OPCODE(UDiv32, U32, U32, U32, )
290OPCODE(INeg32, U32, U32, ) 292OPCODE(INeg32, U32, U32, )
291OPCODE(INeg64, U64, U64, ) 293OPCODE(INeg64, U64, U64, )
292OPCODE(IAbs32, U32, U32, ) 294OPCODE(IAbs32, U32, U32, )