mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 03:25:16 +00:00
cpu_thread compressed
This commit is contained in:
parent
9db7de29fb
commit
7a921cbdf9
10 changed files with 52 additions and 39 deletions
|
@ -10,6 +10,7 @@ struct bitset_t
|
|||
{
|
||||
using type = simple_t<T>;
|
||||
using under = std::underlying_type_t<type>;
|
||||
enum class raw_type : under {};
|
||||
|
||||
static constexpr auto bitsize = BitSize;
|
||||
|
||||
|
@ -20,8 +21,8 @@ struct bitset_t
|
|||
{
|
||||
}
|
||||
|
||||
constexpr bitset_t(under raw_value, const std::nothrow_t&)
|
||||
: m_value(static_cast<T>(raw_value))
|
||||
constexpr bitset_t(raw_type raw_value)
|
||||
: m_value(static_cast<T>(static_cast<under>(raw_value)))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -38,42 +39,42 @@ struct bitset_t
|
|||
|
||||
bitset_t& operator +=(bitset_t rhs)
|
||||
{
|
||||
return *this = { _value() | rhs._value(), std::nothrow };
|
||||
return *this = static_cast<raw_type>(_value() | rhs._value());
|
||||
}
|
||||
|
||||
bitset_t& operator -=(bitset_t rhs)
|
||||
{
|
||||
return *this = { _value() & ~rhs._value(), std::nothrow };
|
||||
return *this = static_cast<raw_type>(_value() & ~rhs._value());
|
||||
}
|
||||
|
||||
bitset_t& operator &=(bitset_t rhs)
|
||||
{
|
||||
return *this = { _value() & rhs._value(), std::nothrow };
|
||||
return *this = static_cast<raw_type>(_value() & rhs._value());
|
||||
}
|
||||
|
||||
bitset_t& operator ^=(bitset_t rhs)
|
||||
{
|
||||
return *this = { _value() ^ rhs._value(), std::nothrow };
|
||||
return *this = static_cast<raw_type>(_value() ^ rhs._value());
|
||||
}
|
||||
|
||||
friend constexpr bitset_t operator +(bitset_t lhs, bitset_t rhs)
|
||||
{
|
||||
return{ lhs._value() | rhs._value(), std::nothrow };
|
||||
return static_cast<raw_type>(lhs._value() | rhs._value());
|
||||
}
|
||||
|
||||
friend constexpr bitset_t operator -(bitset_t lhs, bitset_t rhs)
|
||||
{
|
||||
return{ lhs._value() & ~rhs._value(), std::nothrow };
|
||||
return static_cast<raw_type>(lhs._value() & ~rhs._value());
|
||||
}
|
||||
|
||||
friend constexpr bitset_t operator &(bitset_t lhs, bitset_t rhs)
|
||||
{
|
||||
return{ lhs._value() & rhs._value(), std::nothrow };
|
||||
return static_cast<raw_type>(lhs._value() & rhs._value());
|
||||
}
|
||||
|
||||
friend constexpr bitset_t operator ^(bitset_t lhs, bitset_t rhs)
|
||||
{
|
||||
return{ lhs._value() ^ rhs._value(), std::nothrow };
|
||||
return static_cast<raw_type>(lhs._value() ^ rhs._value());
|
||||
}
|
||||
|
||||
bool test(bitset_t rhs) const
|
||||
|
@ -87,7 +88,7 @@ struct bitset_t
|
|||
{
|
||||
const under v = _value();
|
||||
const under s = rhs._value();
|
||||
*this = { v | s, std::nothrow };
|
||||
*this = static_cast<raw_type>(v | s);
|
||||
return (v & s) != 0;
|
||||
}
|
||||
|
||||
|
@ -95,7 +96,7 @@ struct bitset_t
|
|||
{
|
||||
const under v = _value();
|
||||
const under s = rhs._value();
|
||||
*this = { v & ~s, std::nothrow };
|
||||
*this = static_cast<raw_type>(v & ~s);
|
||||
return (v & s) != 0;
|
||||
}
|
||||
|
||||
|
@ -103,7 +104,7 @@ struct bitset_t
|
|||
{
|
||||
const under v = _value();
|
||||
const under s = rhs._value();
|
||||
*this = { v ^ s, std::nothrow };
|
||||
*this = static_cast<raw_type>(v ^ s);
|
||||
return (v & s) != 0;
|
||||
}
|
||||
|
||||
|
@ -133,17 +134,18 @@ template<typename T, typename CT>
|
|||
struct atomic_add<bitset_t<T>, CT, std::enable_if_t<std::is_enum<T>::value>>
|
||||
{
|
||||
using under = typename bitset_t<T>::under;
|
||||
using raw_type = typename bitset_t<T>::raw_type;
|
||||
|
||||
static inline bitset_t<T> op1(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::fetch_or(reinterpret_cast<under&>(left), right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::fetch_or(reinterpret_cast<under&>(left), right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto fetch_op = &op1;
|
||||
|
||||
static inline bitset_t<T> op2(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::or_fetch(reinterpret_cast<under&>(left), right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::or_fetch(reinterpret_cast<under&>(left), right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto op_fetch = &op2;
|
||||
|
@ -154,17 +156,18 @@ template<typename T, typename CT>
|
|||
struct atomic_sub<bitset_t<T>, CT, std::enable_if_t<std::is_enum<T>::value>>
|
||||
{
|
||||
using under = typename bitset_t<T>::under;
|
||||
using raw_type = typename bitset_t<T>::raw_type;
|
||||
|
||||
static inline bitset_t<T> op1(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::fetch_and(reinterpret_cast<under&>(left), ~right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::fetch_and(reinterpret_cast<under&>(left), ~right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto fetch_op = &op1;
|
||||
|
||||
static inline bitset_t<T> op2(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::and_fetch(reinterpret_cast<under&>(left), ~right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::and_fetch(reinterpret_cast<under&>(left), ~right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto op_fetch = &op2;
|
||||
|
@ -175,17 +178,18 @@ template<typename T, typename CT>
|
|||
struct atomic_and<bitset_t<T>, CT, std::enable_if_t<std::is_enum<T>::value>>
|
||||
{
|
||||
using under = typename bitset_t<T>::under;
|
||||
using raw_type = typename bitset_t<T>::raw_type;
|
||||
|
||||
static inline bitset_t<T> op1(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::fetch_and(reinterpret_cast<under&>(left), right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::fetch_and(reinterpret_cast<under&>(left), right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto fetch_op = &op1;
|
||||
|
||||
static inline bitset_t<T> op2(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::and_fetch(reinterpret_cast<under&>(left), right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::and_fetch(reinterpret_cast<under&>(left), right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto op_fetch = &op2;
|
||||
|
@ -196,17 +200,18 @@ template<typename T, typename CT>
|
|||
struct atomic_xor<bitset_t<T>, CT, std::enable_if_t<std::is_enum<T>::value>>
|
||||
{
|
||||
using under = typename bitset_t<T>::under;
|
||||
using raw_type = typename bitset_t<T>::raw_type;
|
||||
|
||||
static inline bitset_t<T> op1(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::fetch_xor(reinterpret_cast<under&>(left), right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::fetch_xor(reinterpret_cast<under&>(left), right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto fetch_op = &op1;
|
||||
|
||||
static inline bitset_t<T> op2(bitset_t<T>& left, bitset_t<T> right)
|
||||
{
|
||||
return{ atomic_storage<under>::xor_fetch(reinterpret_cast<under&>(left), right._value()), std::nothrow };
|
||||
return static_cast<raw_type>(atomic_storage<under>::xor_fetch(reinterpret_cast<under&>(left), right._value()));
|
||||
}
|
||||
|
||||
static constexpr auto op_fetch = &op2;
|
||||
|
|
|
@ -68,9 +68,8 @@ cpu_thread::~cpu_thread()
|
|||
{
|
||||
}
|
||||
|
||||
cpu_thread::cpu_thread(cpu_type type, const std::string& name)
|
||||
cpu_thread::cpu_thread(cpu_type type)
|
||||
: type(type)
|
||||
, name(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "../Utilities/BitSet.h"
|
||||
|
||||
// CPU Thread Type
|
||||
enum class cpu_type : u32
|
||||
enum class cpu_type : u8
|
||||
{
|
||||
ppu, // PPU Thread
|
||||
spu, // SPU Thread
|
||||
|
@ -12,7 +12,7 @@ enum class cpu_type : u32
|
|||
};
|
||||
|
||||
// CPU Thread State flags
|
||||
enum struct cpu_state : u32
|
||||
enum struct cpu_state : u16
|
||||
{
|
||||
stop, // Thread not running (HLE, initial state)
|
||||
exit, // Irreversible exit
|
||||
|
@ -38,18 +38,17 @@ public:
|
|||
virtual void on_stop() override;
|
||||
virtual ~cpu_thread() override;
|
||||
|
||||
const std::string name;
|
||||
const cpu_type type;
|
||||
const id_value<> id{};
|
||||
const cpu_type type;
|
||||
|
||||
cpu_thread(cpu_type type, const std::string& name);
|
||||
cpu_thread(cpu_type type);
|
||||
|
||||
// Public recursive sleep state counter
|
||||
atomic_t<u8> sleep_counter{};
|
||||
|
||||
// Public thread state
|
||||
atomic_t<bitset_t<cpu_state>> state{ cpu_state::stop };
|
||||
|
||||
// Public recursive sleep state counter
|
||||
atomic_t<u32> sleep_counter{};
|
||||
|
||||
// Object associated with sleep state, possibly synchronization primitive (mutex, semaphore, etc.)
|
||||
atomic_t<void*> owner{};
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ static std::unordered_map<u32, ppu_function_t, ppu_addr_hash> s_ppu_compiled; //
|
|||
|
||||
std::string PPUThread::get_name() const
|
||||
{
|
||||
return fmt::format("PPU[0x%x] Thread (%s)", id, name);
|
||||
return fmt::format("PPU[0x%x] Thread (%s)", id, m_name);
|
||||
}
|
||||
|
||||
std::string PPUThread::dump() const
|
||||
|
@ -298,7 +298,8 @@ PPUThread::~PPUThread()
|
|||
}
|
||||
|
||||
PPUThread::PPUThread(const std::string& name)
|
||||
: cpu_thread(cpu_type::ppu, name)
|
||||
: cpu_thread(cpu_type::ppu)
|
||||
, m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,8 @@ public:
|
|||
bool is_joinable = true;
|
||||
bool is_joining = false;
|
||||
|
||||
const std::string m_name; // Thread name
|
||||
|
||||
std::function<void(PPUThread&)> custom_task;
|
||||
|
||||
// Function name can be stored here. Used to print the last called function.
|
||||
|
|
|
@ -2186,7 +2186,7 @@ void spu_recompiler::BR(spu_opcode_t op)
|
|||
c->mov(*addr, target | 0x2000000);
|
||||
//c->cmp(asmjit::host::dword_ptr(*ls, m_pos), 0x32); // compare instruction opcode with BR-to-self
|
||||
//c->je(labels[target / 4]);
|
||||
c->lock().or_(SPU_OFF_32(state), make_bitset(cpu_state::stop, cpu_state::ret)._value());
|
||||
c->lock().or_(SPU_OFF_16(state), make_bitset(cpu_state::stop, cpu_state::ret)._value());
|
||||
c->jmp(*end);
|
||||
c->unuse(*addr);
|
||||
return;
|
||||
|
|
|
@ -126,7 +126,7 @@ spu_imm_table_t::spu_imm_table_t()
|
|||
|
||||
std::string SPUThread::get_name() const
|
||||
{
|
||||
return fmt::format("%sSPU[0x%x] Thread (%s)", offset > RAW_SPU_BASE_ADDR ? "Raw" : "", id, name);
|
||||
return fmt::format("%sSPU[0x%x] Thread (%s)", offset > RAW_SPU_BASE_ADDR ? "Raw" : "", id, m_name);
|
||||
}
|
||||
|
||||
std::string SPUThread::dump() const
|
||||
|
@ -240,14 +240,16 @@ SPUThread::~SPUThread()
|
|||
}
|
||||
|
||||
SPUThread::SPUThread(const std::string& name)
|
||||
: cpu_thread(cpu_type::spu, name)
|
||||
: cpu_thread(cpu_type::spu)
|
||||
, m_name(name)
|
||||
, index(0)
|
||||
, offset(0)
|
||||
{
|
||||
}
|
||||
|
||||
SPUThread::SPUThread(const std::string& name, u32 index)
|
||||
: cpu_thread(cpu_type::spu, name)
|
||||
: cpu_thread(cpu_type::spu)
|
||||
, m_name(name)
|
||||
, index(index)
|
||||
, offset(vm::alloc(0x40000, vm::main))
|
||||
{
|
||||
|
|
|
@ -553,6 +553,8 @@ public:
|
|||
const u32 index; // SPU index
|
||||
const u32 offset; // SPU LS offset
|
||||
|
||||
const std::string m_name; // Thread name
|
||||
|
||||
std::function<void(SPUThread&)> custom_task;
|
||||
std::exception_ptr pending_exception;
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ void armv7_free_tls(u32 thread)
|
|||
|
||||
std::string ARMv7Thread::get_name() const
|
||||
{
|
||||
return fmt::format("ARMv7[0x%x] Thread (%s)", id, name);
|
||||
return fmt::format("ARMv7[0x%x] Thread (%s)", id, m_name);
|
||||
}
|
||||
|
||||
std::string ARMv7Thread::dump() const
|
||||
|
@ -183,7 +183,8 @@ ARMv7Thread::~ARMv7Thread()
|
|||
}
|
||||
|
||||
ARMv7Thread::ARMv7Thread(const std::string& name)
|
||||
: cpu_thread(cpu_type::arm, name)
|
||||
: cpu_thread(cpu_type::arm)
|
||||
, m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -134,6 +134,8 @@ public:
|
|||
u32 stack_addr = 0;
|
||||
u32 stack_size = 0;
|
||||
|
||||
const std::string m_name;
|
||||
|
||||
std::function<void(ARMv7Thread&)> custom_task;
|
||||
|
||||
const char* last_function = nullptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue