Skip to content

Commit

Permalink
Add alternative reciprocal pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
RipleyTom committed Feb 15, 2024
1 parent 433ea8c commit b42ff71
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion rpcs3/Emu/Cell/SPULLVMRecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6018,7 +6018,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator

// From ps3 hardware testing: Inf => NaN and NaN => Zero, Signed Zero => Zero
// This results in full accuracy within 1ulp(Currently x86 seems to be rounding up?)
const auto result_and = bitcast<u32[4]>(div_result) & 0x7fffffffu;
const auto result_and = bitcast<u32[4]>(div_result) & 0x7FFFFFFFu;
const auto result_cmp_inf = sext<s32[4]>(result_and == splat<u32[4]>(0x7F800000u));
const auto result_cmp_nan = sext<s32[4]>(result_and <= splat<u32[4]>(0x7F800000u));

Expand Down Expand Up @@ -6113,6 +6113,27 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
if (check_accurate_reciprocal_pattern_for_float(std::bit_cast<f32>(std::bit_cast<u32>(1.0f) + 1)))
return;

// GOW 3(uses 1.0f * spu_re(div) instead of just spu_re(div) in the pattern)
auto check_alternative_reciprocal_pattern_for_float = [&](f32 float_value) -> bool
{
if (auto [ok_fm, div] = match_expr(c, fm(spu_re(MT), fsplat<f32[4]>(1.0f))); ok_fm)
{
if (auto [ok_fnms] = match_expr(a, fnms(c, div, fsplat<f32[4]>(1.0f))); ok_fnms)
{
if (auto [ok_spure] = match_expr(b, spu_re(div)); ok_spure)
{
erase_stores(a, b, c);
set_vr(op.rt4, re_accurate(div, fsplat<f32[4]>(float_value)));
return true;
}
}
}
return false;
};

if (check_alternative_reciprocal_pattern_for_float())
return;

// NFS Most Wanted doesn't like this
if (g_cfg.core.spu_xfloat_accuracy == xfloat_accuracy::relaxed)
{
Expand Down

0 comments on commit b42ff71

Please sign in to comment.