mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-03-03 17:52:56 +00:00
ir: Add opcodes for unsigned saturating add and subtract
This commit is contained in:
@@ -521,16 +521,56 @@ ResultAndOverflow<UAny> IREmitter::SignedSaturatedSub(const UAny& a, const UAny&
|
||||
return {result, overflow};
|
||||
}
|
||||
|
||||
ResultAndOverflow<U32> IREmitter::UnsignedSaturation(const U32& a, size_t bit_size_to_saturate_to) {
|
||||
ASSERT(bit_size_to_saturate_to <= 31);
|
||||
auto result = Inst<U32>(Opcode::UnsignedSaturation, a, Imm8(static_cast<u8>(bit_size_to_saturate_to)));
|
||||
ResultAndOverflow<U32> IREmitter::SignedSaturation(const U32& a, size_t bit_size_to_saturate_to) {
|
||||
ASSERT(bit_size_to_saturate_to >= 1 && bit_size_to_saturate_to <= 32);
|
||||
auto result = Inst<U32>(Opcode::SignedSaturation, a, Imm8(static_cast<u8>(bit_size_to_saturate_to)));
|
||||
auto overflow = Inst<U1>(Opcode::GetOverflowFromOp, result);
|
||||
return {result, overflow};
|
||||
}
|
||||
|
||||
ResultAndOverflow<U32> IREmitter::SignedSaturation(const U32& a, size_t bit_size_to_saturate_to) {
|
||||
ASSERT(bit_size_to_saturate_to >= 1 && bit_size_to_saturate_to <= 32);
|
||||
auto result = Inst<U32>(Opcode::SignedSaturation, a, Imm8(static_cast<u8>(bit_size_to_saturate_to)));
|
||||
ResultAndOverflow<UAny> IREmitter::UnsignedSaturatedAdd(const UAny& a, const UAny& b) {
|
||||
ASSERT(a.GetType() == b.GetType());
|
||||
const auto result = [&]() -> IR::UAny {
|
||||
switch (a.GetType()) {
|
||||
case IR::Type::U8:
|
||||
return Inst<U8>(Opcode::UnsignedSaturatedAdd8, a, b);
|
||||
case IR::Type::U16:
|
||||
return Inst<U16>(Opcode::UnsignedSaturatedAdd16, a, b);
|
||||
case IR::Type::U32:
|
||||
return Inst<U32>(Opcode::UnsignedSaturatedAdd32, a, b);
|
||||
case IR::Type::U64:
|
||||
return Inst<U64>(Opcode::UnsignedSaturatedAdd64, a, b);
|
||||
default:
|
||||
return IR::UAny{};
|
||||
}
|
||||
}();
|
||||
const auto overflow = Inst<U1>(Opcode::GetOverflowFromOp, result);
|
||||
return {result, overflow};
|
||||
}
|
||||
|
||||
ResultAndOverflow<UAny> IREmitter::UnsignedSaturatedSub(const UAny& a, const UAny& b) {
|
||||
ASSERT(a.GetType() == b.GetType());
|
||||
const auto result = [&]() -> IR::UAny {
|
||||
switch (a.GetType()) {
|
||||
case IR::Type::U8:
|
||||
return Inst<U8>(Opcode::UnsignedSaturatedSub8, a, b);
|
||||
case IR::Type::U16:
|
||||
return Inst<U16>(Opcode::UnsignedSaturatedSub16, a, b);
|
||||
case IR::Type::U32:
|
||||
return Inst<U32>(Opcode::UnsignedSaturatedSub32, a, b);
|
||||
case IR::Type::U64:
|
||||
return Inst<U64>(Opcode::UnsignedSaturatedSub64, a, b);
|
||||
default:
|
||||
return IR::UAny{};
|
||||
}
|
||||
}();
|
||||
const auto overflow = Inst<U1>(Opcode::GetOverflowFromOp, result);
|
||||
return {result, overflow};
|
||||
}
|
||||
|
||||
ResultAndOverflow<U32> IREmitter::UnsignedSaturation(const U32& a, size_t bit_size_to_saturate_to) {
|
||||
ASSERT(bit_size_to_saturate_to <= 31);
|
||||
auto result = Inst<U32>(Opcode::UnsignedSaturation, a, Imm8(static_cast<u8>(bit_size_to_saturate_to)));
|
||||
auto overflow = Inst<U1>(Opcode::GetOverflowFromOp, result);
|
||||
return {result, overflow};
|
||||
}
|
||||
|
||||
@@ -144,8 +144,10 @@ public:
|
||||
|
||||
ResultAndOverflow<UAny> SignedSaturatedAdd(const UAny& a, const UAny& b);
|
||||
ResultAndOverflow<UAny> SignedSaturatedSub(const UAny& a, const UAny& b);
|
||||
ResultAndOverflow<U32> UnsignedSaturation(const U32& a, size_t bit_size_to_saturate_to);
|
||||
ResultAndOverflow<U32> SignedSaturation(const U32& a, size_t bit_size_to_saturate_to);
|
||||
ResultAndOverflow<UAny> UnsignedSaturatedAdd(const UAny& a, const UAny& b);
|
||||
ResultAndOverflow<UAny> UnsignedSaturatedSub(const UAny& a, const UAny& b);
|
||||
ResultAndOverflow<U32> UnsignedSaturation(const U32& a, size_t bit_size_to_saturate_to);
|
||||
|
||||
ResultAndGE<U32> PackedAddU8(const U32& a, const U32& b);
|
||||
ResultAndGE<U32> PackedAddS8(const U32& a, const U32& b);
|
||||
|
||||
@@ -164,6 +164,14 @@ OPCODE(SignedSaturatedSub16, T::U16, T::U16,
|
||||
OPCODE(SignedSaturatedSub32, T::U32, T::U32, T::U32 )
|
||||
OPCODE(SignedSaturatedSub64, T::U64, T::U64, T::U64 )
|
||||
OPCODE(SignedSaturation, T::U32, T::U32, T::U8 )
|
||||
OPCODE(UnsignedSaturatedAdd8, T::U8, T::U8, T::U8 )
|
||||
OPCODE(UnsignedSaturatedAdd16, T::U16, T::U16, T::U16 )
|
||||
OPCODE(UnsignedSaturatedAdd32, T::U32, T::U32, T::U32 )
|
||||
OPCODE(UnsignedSaturatedAdd64, T::U64, T::U64, T::U64 )
|
||||
OPCODE(UnsignedSaturatedSub8, T::U8, T::U8, T::U8 )
|
||||
OPCODE(UnsignedSaturatedSub16, T::U16, T::U16, T::U16 )
|
||||
OPCODE(UnsignedSaturatedSub32, T::U32, T::U32, T::U32 )
|
||||
OPCODE(UnsignedSaturatedSub64, T::U64, T::U64, T::U64 )
|
||||
OPCODE(UnsignedSaturation, T::U32, T::U32, T::U8 )
|
||||
|
||||
// Packed instructions
|
||||
|
||||
Reference in New Issue
Block a user