diff options
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp index e8f35552c..98b7f59f7 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp | |||
| @@ -30,16 +30,33 @@ enum class IntegerWidth : u64 { | |||
| 30 | [[nodiscard]] IR::U32 ConvertInteger(IR::IREmitter& ir, const IR::U32& src, | 30 | [[nodiscard]] IR::U32 ConvertInteger(IR::IREmitter& ir, const IR::U32& src, |
| 31 | IntegerWidth dst_width) { | 31 | IntegerWidth dst_width) { |
| 32 | const IR::U32 zero{ir.Imm32(0)}; | 32 | const IR::U32 zero{ir.Imm32(0)}; |
| 33 | const IR::U32 count{WidthSize(ir, dst_width)}; | ||
| 34 | return ir.BitFieldExtract(src, zero, count, false); | ||
| 35 | } | ||
| 36 | |||
| 37 | [[nodiscard]] IR::U32 SaturateInteger(IR::IREmitter& ir, const IR::U32& src, IntegerWidth dst_width, | ||
| 38 | bool dst_signed, bool src_signed) { | ||
| 39 | IR::U32 min{}; | ||
| 40 | IR::U32 max{}; | ||
| 41 | const IR::U32 zero{ir.Imm32(0)}; | ||
| 33 | switch (dst_width) { | 42 | switch (dst_width) { |
| 34 | case IntegerWidth::Byte: | 43 | case IntegerWidth::Byte: |
| 35 | return ir.BitFieldExtract(src, zero, ir.Imm32(8), false); | 44 | min = dst_signed && src_signed ? ir.Imm32(0xffffff80) : zero; |
| 45 | max = dst_signed ? ir.Imm32(0x7f) : ir.Imm32(0xff); | ||
| 46 | break; | ||
| 36 | case IntegerWidth::Short: | 47 | case IntegerWidth::Short: |
| 37 | return ir.BitFieldExtract(src, zero, ir.Imm32(16), false); | 48 | min = dst_signed && src_signed ? ir.Imm32(0xffff8000) : zero; |
| 49 | max = dst_signed ? ir.Imm32(0x7fff) : ir.Imm32(0xffff); | ||
| 50 | break; | ||
| 38 | case IntegerWidth::Word: | 51 | case IntegerWidth::Word: |
| 39 | return ir.BitFieldExtract(src, zero, ir.Imm32(32), false); | 52 | min = dst_signed && src_signed ? ir.Imm32(0x80000000) : zero; |
| 53 | max = dst_signed ? ir.Imm32(0x7fffffff) : ir.Imm32(0xffffffff); | ||
| 54 | break; | ||
| 40 | default: | 55 | default: |
| 41 | throw NotImplementedException("Invalid width {}", dst_width); | 56 | throw NotImplementedException("Invalid width {}", dst_width); |
| 42 | } | 57 | } |
| 58 | const IR::U32 value{!dst_signed && src_signed ? ir.SMax(zero, src) : src}; | ||
| 59 | return dst_signed && src_signed ? ir.SClamp(value, min, max) : ir.UClamp(value, min, max); | ||
| 43 | } | 60 | } |
| 44 | 61 | ||
| 45 | void I2I(TranslatorVisitor& v, u64 insn, const IR::U32& src_a) { | 62 | void I2I(TranslatorVisitor& v, u64 insn, const IR::U32& src_a) { |
| @@ -60,9 +77,6 @@ void I2I(TranslatorVisitor& v, u64 insn, const IR::U32& src_a) { | |||
| 60 | if (i2i.cc != 0) { | 77 | if (i2i.cc != 0) { |
| 61 | throw NotImplementedException("I2I CC"); | 78 | throw NotImplementedException("I2I CC"); |
| 62 | } | 79 | } |
| 63 | if (i2i.sat != 0) { | ||
| 64 | throw NotImplementedException("I2I SAT"); | ||
| 65 | } | ||
| 66 | if (i2i.src_fmt == IntegerWidth::Short && (i2i.selector == 1 || i2i.selector == 3)) { | 80 | if (i2i.src_fmt == IntegerWidth::Short && (i2i.selector == 1 || i2i.selector == 3)) { |
| 67 | throw NotImplementedException("16-bit source format incompatible with selector {}", | 81 | throw NotImplementedException("16-bit source format incompatible with selector {}", |
| 68 | i2i.selector); | 82 | i2i.selector); |
| @@ -75,15 +89,21 @@ void I2I(TranslatorVisitor& v, u64 insn, const IR::U32& src_a) { | |||
| 75 | const s32 selector{static_cast<s32>(i2i.selector)}; | 89 | const s32 selector{static_cast<s32>(i2i.selector)}; |
| 76 | const IR::U32 offset{v.ir.Imm32(selector * 8)}; | 90 | const IR::U32 offset{v.ir.Imm32(selector * 8)}; |
| 77 | const IR::U32 count{WidthSize(v.ir, i2i.src_fmt)}; | 91 | const IR::U32 count{WidthSize(v.ir, i2i.src_fmt)}; |
| 78 | IR::U32 src_values{v.ir.BitFieldExtract(src_a, offset, count, i2i.src_fmt_sign != 0)}; | 92 | const bool src_signed{i2i.src_fmt_sign != 0}; |
| 79 | if (i2i.abs) { | 93 | const bool dst_signed{i2i.dst_fmt_sign != 0}; |
| 94 | const bool sat{i2i.sat != 0}; | ||
| 95 | |||
| 96 | IR::U32 src_values{v.ir.BitFieldExtract(src_a, offset, count, src_signed)}; | ||
| 97 | if (i2i.abs != 0) { | ||
| 80 | src_values = v.ir.IAbs(src_values); | 98 | src_values = v.ir.IAbs(src_values); |
| 81 | } | 99 | } |
| 82 | if (i2i.neg) { | 100 | if (i2i.neg != 0) { |
| 83 | src_values = v.ir.INeg(src_values); | 101 | src_values = v.ir.INeg(src_values); |
| 84 | } | 102 | } |
| 103 | const IR::U32 result{ | ||
| 104 | sat ? SaturateInteger(v.ir, src_values, i2i.dst_fmt, dst_signed, src_signed) | ||
| 105 | : ConvertInteger(v.ir, src_values, i2i.dst_fmt)}; | ||
| 85 | 106 | ||
| 86 | const IR::U32 result{ConvertInteger(v.ir, src_values, i2i.dst_fmt)}; | ||
| 87 | v.X(i2i.dest_reg, result); | 107 | v.X(i2i.dest_reg, result); |
| 88 | } | 108 | } |
| 89 | } // Anonymous namespace | 109 | } // Anonymous namespace |