Skip to content

Commit bd49c6b

Browse files
Whatcookieelad335
authored andcommitted
SPU LLVM: Small FCGT optimization
1 parent 86a832d commit bd49c6b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

rpcs3/Emu/Cell/SPULLVMRecompiler.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -6234,14 +6234,14 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
62346234
const value_t<f32[4]> ab[2]{a, b};
62356235

62366236
std::bitset<2> safe_int_compare(0);
6237-
std::bitset<2> safe_nonzero_compare(0);
6237+
std::bitset<2> safe_finite_compare(0);
62386238

62396239
for (u32 i = 0; i < 2; i++)
62406240
{
62416241
if (auto [ok, data] = get_const_vector(ab[i].value, m_pos, __LINE__ + i); ok)
62426242
{
62436243
safe_int_compare.set(i);
6244-
safe_nonzero_compare.set(i);
6244+
safe_finite_compare.set(i);
62456245

62466246
for (u32 j = 0; j < 4; j++)
62476247
{
@@ -6256,7 +6256,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
62566256
// we don't produce "extended range" values the same way as real hardware, it's not safe to apply
62576257
// this optimization for values outside of the range of x86 floating point hardware.
62586258
safe_int_compare.reset(i);
6259-
if (!exponent) safe_nonzero_compare.reset(i);
6259+
if ((value & 0x7fffffffu) >= 0x7f7ffffeu) safe_finite_compare.reset(i);
62606260
}
62616261
}
62626262
}
@@ -6267,17 +6267,20 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
62676267
return eval(sext<s32[4]>(bitcast<s32[4]>(a) > bitcast<s32[4]>(b)));
62686268
}
62696269

6270-
const auto ai = eval(bitcast<s32[4]>(a));
6271-
const auto bi = eval(bitcast<s32[4]>(b));
6272-
6273-
if (!safe_nonzero_compare.any())
6270+
if (safe_finite_compare.test(1))
62746271
{
6275-
return eval(sext<s32[4]>(fcmp_uno(a != b) & select((ai & bi) >= 0, ai > bi, ai < bi)));
6272+
return eval(sext<s32[4]>(fcmp_uno(clamp_negative_smax(a) > b)));
62766273
}
6277-
else
6274+
6275+
if (safe_finite_compare.test(0))
62786276
{
6279-
return eval(sext<s32[4]>(select((ai & bi) >= 0, ai > bi, ai < bi)));
6277+
return eval(sext<s32[4]>(fcmp_ord(a > clamp_smax(b))));
62806278
}
6279+
6280+
const auto ai = eval(bitcast<s32[4]>(a));
6281+
const auto bi = eval(bitcast<s32[4]>(b));
6282+
6283+
return eval(sext<s32[4]>(fcmp_uno(a != b) & select((ai & bi) >= 0, ai > bi, ai < bi)));
62816284
});
62826285

62836286
set_vr(op.rt, fcgt(get_vr<f32[4]>(op.ra), get_vr<f32[4]>(op.rb)));

0 commit comments

Comments
 (0)