Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPU LLVM: add splat_scalar helper #9619

Merged
merged 2 commits into from Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 40 additions & 11 deletions rpcs3/Emu/Cell/SPURecompiler.cpp
Expand Up @@ -4001,6 +4001,35 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
}
}

// Splat scalar value from the preferred slot
template <typename T>
auto splat_scalar(T&& arg)
{
using VT = std::remove_extent_t<typename std::decay_t<T>::type>;

if constexpr (sizeof(VT) == 1)
{
return zshuffle(std::forward<T>(arg), 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12);
}
else if constexpr (sizeof(VT) == 2)
{
return zshuffle(std::forward<T>(arg), 6, 6, 6, 6, 6, 6, 6, 6);
}
else if constexpr (sizeof(VT) == 4)
{
return zshuffle(std::forward<T>(arg), 3, 3, 3, 3);
}
else if constexpr (sizeof(VT) == 8)
{
return zshuffle(std::forward<T>(arg), 1, 1);
}
else
{
static_assert(sizeof(VT) == 16);
return std::forward<T>(arg);
}
}

void set_reg_fixed(u32 index, llvm::Value* value, bool fixup = true)
{
llvm::StoreInst* dummy{};
Expand Down Expand Up @@ -6468,27 +6497,27 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
{
const auto as = byteswap(a);
const auto sc = build<u8[16]>(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
const auto sh = (sc + (zshuffle(get_vr<u8[16]>(op.rb), 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12) >> 3)) & 0xf;
const auto sh = (sc + (splat_scalar(get_vr<u8[16]>(op.rb)) >> 3)) & 0xf;
set_vr(op.rt, pshufb(as, sh));
return;
}

const auto sc = build<u8[16]>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
const auto sh = (sc - (zshuffle(get_vr<u8[16]>(op.rb), 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12) >> 3)) & 0xf;
const auto sh = (sc - (splat_scalar(get_vr<u8[16]>(op.rb)) >> 3)) & 0xf;
set_vr(op.rt, pshufb(a, sh));
}

void ROTQMBYBI(spu_opcode_t op)
{
const auto sc = build<u8[16]>(112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127);
const auto sh = sc + (-(zshuffle(get_vr<u8[16]>(op.rb), 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12) >> 3) & 0x1f);
const auto sh = sc + (-(splat_scalar(get_vr<u8[16]>(op.rb)) >> 3) & 0x1f);
set_vr(op.rt, pshufb(get_vr<u8[16]>(op.ra), sh));
}

void SHLQBYBI(spu_opcode_t op)
{
const auto sc = build<u8[16]>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
const auto sh = sc - (zshuffle(get_vr<u8[16]>(op.rb), 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12) >> 3);
const auto sh = sc - (splat_scalar(get_vr<u8[16]>(op.rb)) >> 3);
set_vr(op.rt, pshufb(get_vr<u8[16]>(op.ra), sh));
}

Expand Down Expand Up @@ -6556,21 +6585,21 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
void ROTQBI(spu_opcode_t op)
{
const auto a = get_vr(op.ra);
const auto b = zshuffle(get_vr(op.rb) & 0x7, 3, 3, 3, 3);
const auto b = splat_scalar(get_vr(op.rb) & 0x7);
set_vr(op.rt, fshl(a, zshuffle(a, 3, 0, 1, 2), b));
}

void ROTQMBI(spu_opcode_t op)
{
const auto a = get_vr(op.ra);
const auto b = zshuffle(-get_vr(op.rb) & 0x7, 3, 3, 3, 3);
const auto b = splat_scalar(-get_vr(op.rb) & 0x7);
set_vr(op.rt, fshr(zshuffle(a, 1, 2, 3, 4), a, b));
}

void SHLQBI(spu_opcode_t op)
{
const auto a = get_vr(op.ra);
const auto b = zshuffle(get_vr(op.rb) & 0x7, 3, 3, 3, 3);
const auto b = splat_scalar(get_vr(op.rb) & 0x7);
set_vr(op.rt, fshl(a, zshuffle(a, 4, 0, 1, 2), b));
}

Expand Down Expand Up @@ -6598,13 +6627,13 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
{
const auto as = byteswap(a);
const auto sc = build<u8[16]>(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
const auto sh = eval((sc + zshuffle(b, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12)) & 0xf);
const auto sh = eval((sc + splat_scalar(b)) & 0xf);
set_vr(op.rt, pshufb(as, sh));
return;
}

const auto sc = build<u8[16]>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
const auto sh = eval((sc - zshuffle(b, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12)) & 0xf);
const auto sh = eval((sc - splat_scalar(b)) & 0xf);
set_vr(op.rt, pshufb(a, sh));
}

Expand All @@ -6613,7 +6642,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
const auto a = get_vr<u8[16]>(op.ra);
const auto b = get_vr<u8[16]>(op.rb);
const auto sc = build<u8[16]>(112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127);
const auto sh = sc + (-zshuffle(b, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12) & 0x1f);
const auto sh = sc + (-splat_scalar(b) & 0x1f);
set_vr(op.rt, pshufb(a, sh));
}

Expand All @@ -6622,7 +6651,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
const auto a = get_vr<u8[16]>(op.ra);
const auto b = get_vr<u8[16]>(op.rb);
const auto sc = build<u8[16]>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
const auto sh = sc - (zshuffle(b, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12) & 0x1f);
const auto sh = sc - (splat_scalar(b) & 0x1f);
set_vr(op.rt, pshufb(a, sh));
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/util/vm_native.cpp
Expand Up @@ -262,7 +262,7 @@ namespace utils
m_file = -1;

// Try to use 2MB pages for 2M-aligned shm
if constexpr (c_mfd_huge_2mb)
if constexpr (c_mfd_huge_2mb != 0)
{
if (m_size % 0x200000 == 0 && flags & 2)
{
Expand Down