Skip to content

Commit

Permalink
add remaining altivec instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaTh-G committed Nov 24, 2024
1 parent 12cd4d0 commit 9f1062c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion PowerRecomp/recompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,16 @@ bool Recompiler::Recompile(
println("_mm_load_ps({}.f32)));", v(insn.operands[1]));
break;

case PPC_INST_VCTUXS:
case PPC_INST_VCFPUXWS128:
printSetFlushMode(true);
print("\t_mm_store_si128((__m128i*){}.u32, _mm_vctuxs(", v(insn.operands[0]));
if (insn.operands[2] != 0)
println("_mm_mul_ps(_mm_load_ps({}.f32), _mm_set1_ps({}))));", v(insn.operands[1]), 1u << insn.operands[2]);
else
println("_mm_load_ps({}.f32)));", v(insn.operands[1]));
break;

case PPC_INST_VCFSX:
case PPC_INST_VCSXWFP128:
{
Expand Down Expand Up @@ -2198,6 +2208,14 @@ bool Recompiler::Recompile(
break;
}

case PPC_INST_VRLH:
for (size_t i = 0; i < 8; i++)
{
println("\t{0}.u16[{1}] = ({2}.u16[{1}] << ({3}.u16[{1}] & 0xF)) | ({2}.u16[{1}] >> (16 - ({3}.u16[{1}] & 0xF)));", vTemp(), i, v(insn.operands[1]), v(insn.operands[2]));
}
println("{} = {};", v(insn.operands[0]), vTemp());
break;

case PPC_INST_VRSQRTEFP:
case PPC_INST_VRSQRTEFP128:
// TODO: see if we can use rsqrt safely
Expand Down Expand Up @@ -2752,7 +2770,7 @@ void Recompiler::SaveCurrentOutData(const std::string_view& name)
bool shouldWrite = true;

// Check if an identical file already exists first to not trigger recompilation
std::string filePath = std::format("{}{}/{}", config.directoryPath, config.outDirectoryPath, name.empty() ? cppName : name);
std::string filePath = std::format("{}/{}/{}", config.directoryPath, config.outDirectoryPath, name.empty() ? cppName : name);
FILE* f = fopen(filePath.c_str(), "rb");
if (f)
{
Expand Down
13 changes: 13 additions & 0 deletions PowerUtils/ppc_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,19 @@ inline __m128i _mm_vctsxs(__m128 src1)
return _mm_andnot_si128(_mm_castps_si128(xmm2), _mm_castps_si128(dest));
}

inline __m128i _mm_vctuxs(__m128 src1)
{
__m128 xmm0 = _mm_max_ps(src1, _mm_set1_epi32(0));
__m128 xmm1 = _mm_cmpge_ps(xmm0, _mm_set1_ps((float)0x80000000));
__m128 xmm2 = _mm_sub_ps(xmm0, _mm_set1_ps((float)0x80000000));
xmm0 = _mm_blendv_ps(xmm0, xmm2, xmm1);
__m128i dest = _mm_cvttps_epi32(xmm0);
xmm0 = _mm_cmpeq_epi32(dest, _mm_set1_epi32(INT_MIN));
xmm1 = _mm_and_si128(xmm1, _mm_set1_epi32(INT_MIN));
dest = _mm_add_epi32(dest, xmm1);
return _mm_or_si128(dest, xmm0);
}

inline __m128i _mm_vsr(__m128i a, __m128i b)
{
b = _mm_srli_epi64(_mm_slli_epi64(b, 61), 61);
Expand Down

0 comments on commit 9f1062c

Please sign in to comment.