diff options
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); | |||
| 304 | void EmitISub32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); | 304 | void EmitISub32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); |
| 305 | void EmitISub64(EmitContext& ctx, IR::Inst& inst, Register a, Register b); | 305 | void EmitISub64(EmitContext& ctx, IR::Inst& inst, Register a, Register b); |
| 306 | void EmitIMul32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); | 306 | void EmitIMul32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); |
| 307 | void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b); | ||
| 308 | void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, ScalarU32 a, ScalarU32 b); | ||
| 307 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value); | 309 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value); |
| 308 | void EmitINeg64(EmitContext& ctx, IR::Inst& inst, Register value); | 310 | void EmitINeg64(EmitContext& ctx, IR::Inst& inst, Register value); |
| 309 | void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value); | 311 | void 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 | ||
| 93 | void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b) { | ||
| 94 | ctx.Add("DIV.S {}.x,{},{};", inst, a, b); | ||
| 95 | } | ||
| 96 | |||
| 97 | void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, ScalarU32 a, ScalarU32 b) { | ||
| 98 | ctx.Add("DIV.U {}.x,{},{};", inst, a, b); | ||
| 99 | } | ||
| 100 | |||
| 93 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, ScalarS32 value) { | 101 | void 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 | |||
| 363 | void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); | 363 | void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); |
| 364 | void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); | 364 | void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); |
| 365 | void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); | 365 | void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); |
| 366 | void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); | ||
| 367 | void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b); | ||
| 366 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 368 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 367 | void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 369 | void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 368 | void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 370 | void 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 | ||
| 81 | void 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 | |||
| 85 | void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { | ||
| 86 | ctx.AddU32("{}={}/{};", inst, a, b); | ||
| 87 | } | ||
| 88 | |||
| 81 | void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 89 | void 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); | |||
| 284 | Id EmitISub32(EmitContext& ctx, Id a, Id b); | 284 | Id EmitISub32(EmitContext& ctx, Id a, Id b); |
| 285 | Id EmitISub64(EmitContext& ctx, Id a, Id b); | 285 | Id EmitISub64(EmitContext& ctx, Id a, Id b); |
| 286 | Id EmitIMul32(EmitContext& ctx, Id a, Id b); | 286 | Id EmitIMul32(EmitContext& ctx, Id a, Id b); |
| 287 | Id EmitSDiv32(EmitContext& ctx, Id a, Id b); | ||
| 288 | Id EmitUDiv32(EmitContext& ctx, Id a, Id b); | ||
| 287 | Id EmitINeg32(EmitContext& ctx, Id value); | 289 | Id EmitINeg32(EmitContext& ctx, Id value); |
| 288 | Id EmitINeg64(EmitContext& ctx, Id value); | 290 | Id EmitINeg64(EmitContext& ctx, Id value); |
| 289 | Id EmitIAbs32(EmitContext& ctx, Id value); | 291 | Id 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 | ||
| 75 | Id EmitSDiv32(EmitContext& ctx, Id a, Id b) { | ||
| 76 | return ctx.OpSDiv(ctx.U32[1], a, b); | ||
| 77 | } | ||
| 78 | |||
| 79 | Id EmitUDiv32(EmitContext& ctx, Id a, Id b) { | ||
| 80 | return ctx.OpUDiv(ctx.U32[1], a, b); | ||
| 81 | } | ||
| 82 | |||
| 75 | Id EmitINeg32(EmitContext& ctx, Id value) { | 83 | Id 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 | ||
| 1148 | U32 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 | |||
| 1148 | U32U64 IREmitter::INeg(const U32U64& value) { | 1152 | U32U64 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, | |||
| 287 | OPCODE(ISub32, U32, U32, U32, ) | 287 | OPCODE(ISub32, U32, U32, U32, ) |
| 288 | OPCODE(ISub64, U64, U64, U64, ) | 288 | OPCODE(ISub64, U64, U64, U64, ) |
| 289 | OPCODE(IMul32, U32, U32, U32, ) | 289 | OPCODE(IMul32, U32, U32, U32, ) |
| 290 | OPCODE(SDiv32, U32, U32, U32, ) | ||
| 291 | OPCODE(UDiv32, U32, U32, U32, ) | ||
| 290 | OPCODE(INeg32, U32, U32, ) | 292 | OPCODE(INeg32, U32, U32, ) |
| 291 | OPCODE(INeg64, U64, U64, ) | 293 | OPCODE(INeg64, U64, U64, ) |
| 292 | OPCODE(IAbs32, U32, U32, ) | 294 | OPCODE(IAbs32, U32, U32, ) |