mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-09-26 08:51:05 -04:00
fix portability issue (#41)
* refactor: update function name checks to use contains method * refactor: update code generation to use static_cast * refactor: made member methods const * refactor: made range-based loop * refactor: make one variable constructor explicit * refactor: remove redundant else * refactor: turn includes to forward declarations * refactor: brace placements turned into allman style * refactor: structed binding for readability and clarity, used emplace_back to prevent extra-copied object * fix: add dwarf_private.h include * fix: update GPR_U32 and GPR_S32 macros to use _mm_extract_epi32 for SSE/AVX intrinsics
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "libdwarf_private.h"
|
||||
#include <libdwarf.h>
|
||||
#include <dwarf.h>
|
||||
#include <fstream>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <immintrin.h> // For SSE/AVX instructions
|
||||
#include <smmintrin.h>
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
@@ -225,8 +226,10 @@ struct alignas(16) R5900Context
|
||||
for (int i = 0; i < 32; ++i)
|
||||
{
|
||||
std::cout << "R" << std::setw(2) << std::dec << i << ": 0x" << std::hex
|
||||
<< std::setw(8) << r[i].m128i_u32[3] << std::setw(8) << r[i].m128i_u32[2] << "_"
|
||||
<< std::setw(8) << r[i].m128i_u32[1] << std::setw(8) << r[i].m128i_u32[0] << "\n";
|
||||
<< std::setw(8) << static_cast<uint32_t>(_mm_extract_epi32(r[i], 3))
|
||||
<< std::setw(8) << static_cast<uint32_t>(_mm_extract_epi32(r[i], 2)) << "_"
|
||||
<< std::setw(8) << static_cast<uint32_t>(_mm_extract_epi32(r[i], 1))
|
||||
<< std::setw(8) << static_cast<uint32_t>(_mm_extract_epi32(r[i], 0)) << "\n";
|
||||
}
|
||||
std::cout << "Status: 0x" << std::setw(8) << cop0_status
|
||||
<< " Cause: 0x" << std::setw(8) << cop0_cause
|
||||
@@ -243,7 +246,7 @@ inline uint32_t getRegU32(const R5900Context *ctx, int reg)
|
||||
// Check if reg is valid (0-31)
|
||||
if (reg < 0 || reg > 31)
|
||||
return 0;
|
||||
return ctx->r[reg].m128i_u32[0];
|
||||
return static_cast<uint32_t>(_mm_extract_epi32(ctx->r[reg], 0));
|
||||
}
|
||||
|
||||
inline void setReturnU32(R5900Context *ctx, uint32_t value)
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef PS2_RUNTIME_MACROS_H
|
||||
#define PS2_RUNTIME_MACROS_H
|
||||
#include <cstdint>
|
||||
#include <immintrin.h> // For SSE/AVX intrinsics
|
||||
#include <intrin.h>
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <immintrin.h> // For SSE/AVX intrinsics
|
||||
#endif
|
||||
inline uint32_t ps2_clz32(uint32_t val) {
|
||||
#if defined(_MSC_VER)
|
||||
unsigned long idx;
|
||||
@@ -207,10 +210,10 @@ inline __m128i _mm_custom_srav_epi32(__m128i a, __m128i count) {
|
||||
#define PS2_VCALLMS(addr) // VU0 microprogram calls not supported directly
|
||||
#define PS2_VCALLMSR(reg) // VU0 microprogram calls not supported directly
|
||||
|
||||
#define GPR_U32(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0U : ctx_ptr->r[reg_idx].m128i_u32[0])
|
||||
#define GPR_S32(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0 : ctx_ptr->r[reg_idx].m128i_i32[0])
|
||||
#define GPR_U64(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0ULL : ctx_ptr->r[reg_idx].m128i_u64[0])
|
||||
#define GPR_S64(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0LL : ctx_ptr->r[reg_idx].m128i_i64[0])
|
||||
#define GPR_U32(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0U : static_cast<uint32_t>(_mm_extract_epi32(ctx_ptr->r[reg_idx], 0)))
|
||||
#define GPR_S32(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0 : _mm_extract_epi32(ctx_ptr->r[reg_idx], 0))
|
||||
#define GPR_U64(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0ULL : static_cast<uint32_t>(_mm_extract_epi64(ctx_ptr->r[reg_idx], 0)))
|
||||
#define GPR_S64(ctx_ptr, reg_idx) ((reg_idx == 0) ? 0LL : _mm_extract_epi64(ctx_ptr->r[reg_idx], 0))
|
||||
#define GPR_VEC(ctx_ptr, reg_idx) ((reg_idx == 0) ? _mm_setzero_si128() : ctx_ptr->r[reg_idx])
|
||||
|
||||
#define SET_GPR_U32(ctx_ptr, reg_idx, val) \
|
||||
|
||||
@@ -331,7 +331,7 @@ void PS2Runtime::executeVU0Microprogram(uint8_t *rdram, R5900Context *ctx, uint3
|
||||
{
|
||||
std::cout << "[VU0] microprogram @0x" << std::hex << address
|
||||
<< " pc=0x" << ctx->pc
|
||||
<< " ra=0x" << ctx->r[31].m128i_u32[0]
|
||||
<< " ra=0x" << static_cast<uint32_t>(_mm_extract_epi32(ctx->r[31], 0))
|
||||
<< std::dec << std::endl;
|
||||
}
|
||||
++count;
|
||||
@@ -430,7 +430,7 @@ void PS2Runtime::run()
|
||||
{
|
||||
entryPoint(m_memory.getRDRAM(), &m_cpuContext, this);
|
||||
std::cout << "Game thread returned. PC=0x" << std::hex << m_cpuContext.pc
|
||||
<< " RA=0x" << m_cpuContext.r[31].m128i_u32[0] << std::dec << std::endl;
|
||||
<< " RA=0x" << static_cast<uint32_t>(_mm_extract_epi32(m_cpuContext.r[31], 0)) << std::dec << std::endl;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -445,9 +445,9 @@ void PS2Runtime::run()
|
||||
{
|
||||
std::cout << "[run] activeThreads=" << g_activeThreads.load(std::memory_order_relaxed);
|
||||
std::cout << " pc=0x" << std::hex << m_cpuContext.pc
|
||||
<< " ra=0x" << m_cpuContext.r[31].m128i_u32[0]
|
||||
<< " sp=0x" << m_cpuContext.r[29].m128i_u32[0]
|
||||
<< " gp=0x" << m_cpuContext.r[28].m128i_u32[0] << std::dec << std::endl;
|
||||
<< " ra=0x" << static_cast<uint32_t>(_mm_extract_epi32(m_cpuContext.r[31], 0))
|
||||
<< " sp=0x" << static_cast<uint32_t>(_mm_extract_epi32(m_cpuContext.r[29], 0))
|
||||
<< " gp=0x" << static_cast<uint32_t>(_mm_extract_epi32(m_cpuContext.r[28], 0)) << std::dec << std::endl;
|
||||
}
|
||||
if ((tick % 600) == 0)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "ps2_syscalls.h"
|
||||
#include "ps2_runtime.h"
|
||||
#include "ps2_runtime_macros.h"
|
||||
@@ -15,6 +14,12 @@
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h> // for unlink,rmdir,chdir
|
||||
#include <sys/stat.h> // for mkdir
|
||||
#endif
|
||||
|
||||
|
||||
std::unordered_map<int, FILE *> g_fileDescriptors;
|
||||
int g_nextFd = 3; // Start after stdin, stdout, stderr
|
||||
|
||||
|
||||
Reference in New Issue
Block a user