diff --git a/Utilities/BitSet.h b/Utilities/BitSet.h index 77d8f7c4de..40356be5c0 100644 --- a/Utilities/BitSet.h +++ b/Utilities/BitSet.h @@ -10,6 +10,7 @@ struct bitset_t { using type = simple_t; using under = std::underlying_type_t; + 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(raw_value)) + constexpr bitset_t(raw_type raw_value) + : m_value(static_cast(static_cast(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(_value() | rhs._value()); } bitset_t& operator -=(bitset_t rhs) { - return *this = { _value() & ~rhs._value(), std::nothrow }; + return *this = static_cast(_value() & ~rhs._value()); } bitset_t& operator &=(bitset_t rhs) { - return *this = { _value() & rhs._value(), std::nothrow }; + return *this = static_cast(_value() & rhs._value()); } bitset_t& operator ^=(bitset_t rhs) { - return *this = { _value() ^ rhs._value(), std::nothrow }; + return *this = static_cast(_value() ^ rhs._value()); } friend constexpr bitset_t operator +(bitset_t lhs, bitset_t rhs) { - return{ lhs._value() | rhs._value(), std::nothrow }; + return static_cast(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(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(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(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(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(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(v ^ s); return (v & s) != 0; } @@ -133,17 +134,18 @@ template struct atomic_add, CT, std::enable_if_t::value>> { using under = typename bitset_t::under; + using raw_type = typename bitset_t::raw_type; static inline bitset_t op1(bitset_t& left, bitset_t right) { - return{ atomic_storage::fetch_or(reinterpret_cast(left), right._value()), std::nothrow }; + return static_cast(atomic_storage::fetch_or(reinterpret_cast(left), right._value())); } static constexpr auto fetch_op = &op1; static inline bitset_t op2(bitset_t& left, bitset_t right) { - return{ atomic_storage::or_fetch(reinterpret_cast(left), right._value()), std::nothrow }; + return static_cast(atomic_storage::or_fetch(reinterpret_cast(left), right._value())); } static constexpr auto op_fetch = &op2; @@ -154,17 +156,18 @@ template struct atomic_sub, CT, std::enable_if_t::value>> { using under = typename bitset_t::under; + using raw_type = typename bitset_t::raw_type; static inline bitset_t op1(bitset_t& left, bitset_t right) { - return{ atomic_storage::fetch_and(reinterpret_cast(left), ~right._value()), std::nothrow }; + return static_cast(atomic_storage::fetch_and(reinterpret_cast(left), ~right._value())); } static constexpr auto fetch_op = &op1; static inline bitset_t op2(bitset_t& left, bitset_t right) { - return{ atomic_storage::and_fetch(reinterpret_cast(left), ~right._value()), std::nothrow }; + return static_cast(atomic_storage::and_fetch(reinterpret_cast(left), ~right._value())); } static constexpr auto op_fetch = &op2; @@ -175,17 +178,18 @@ template struct atomic_and, CT, std::enable_if_t::value>> { using under = typename bitset_t::under; + using raw_type = typename bitset_t::raw_type; static inline bitset_t op1(bitset_t& left, bitset_t right) { - return{ atomic_storage::fetch_and(reinterpret_cast(left), right._value()), std::nothrow }; + return static_cast(atomic_storage::fetch_and(reinterpret_cast(left), right._value())); } static constexpr auto fetch_op = &op1; static inline bitset_t op2(bitset_t& left, bitset_t right) { - return{ atomic_storage::and_fetch(reinterpret_cast(left), right._value()), std::nothrow }; + return static_cast(atomic_storage::and_fetch(reinterpret_cast(left), right._value())); } static constexpr auto op_fetch = &op2; @@ -196,17 +200,18 @@ template struct atomic_xor, CT, std::enable_if_t::value>> { using under = typename bitset_t::under; + using raw_type = typename bitset_t::raw_type; static inline bitset_t op1(bitset_t& left, bitset_t right) { - return{ atomic_storage::fetch_xor(reinterpret_cast(left), right._value()), std::nothrow }; + return static_cast(atomic_storage::fetch_xor(reinterpret_cast(left), right._value())); } static constexpr auto fetch_op = &op1; static inline bitset_t op2(bitset_t& left, bitset_t right) { - return{ atomic_storage::xor_fetch(reinterpret_cast(left), right._value()), std::nothrow }; + return static_cast(atomic_storage::xor_fetch(reinterpret_cast(left), right._value())); } static constexpr auto op_fetch = &op2; diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 294a1b6e73..7be23e9849 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -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) { } diff --git a/rpcs3/Emu/CPU/CPUThread.h b/rpcs3/Emu/CPU/CPUThread.h index 63f8d50769..3dd21a1aee 100644 --- a/rpcs3/Emu/CPU/CPUThread.h +++ b/rpcs3/Emu/CPU/CPUThread.h @@ -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 sleep_counter{}; // Public thread state atomic_t> state{ cpu_state::stop }; - // Public recursive sleep state counter - atomic_t sleep_counter{}; - // Object associated with sleep state, possibly synchronization primitive (mutex, semaphore, etc.) atomic_t owner{}; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index b46ac6ffb0..e72f2cbce5 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -70,7 +70,7 @@ static std::unordered_map 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) { } diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index 1d95f8dd35..4303090c0e 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -75,6 +75,8 @@ public: bool is_joinable = true; bool is_joining = false; + const std::string m_name; // Thread name + std::function custom_task; // Function name can be stored here. Used to print the last called function. diff --git a/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp b/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp index ecef1e01c6..aae3547b7b 100644 --- a/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp @@ -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; diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index a38fc75b86..1317779ac8 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -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)) { diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index d75dd5e676..9e2354f8fb 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -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 custom_task; std::exception_ptr pending_exception; diff --git a/rpcs3/Emu/PSP2/ARMv7Thread.cpp b/rpcs3/Emu/PSP2/ARMv7Thread.cpp index c0476525e3..5e45fd305c 100644 --- a/rpcs3/Emu/PSP2/ARMv7Thread.cpp +++ b/rpcs3/Emu/PSP2/ARMv7Thread.cpp @@ -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) { } diff --git a/rpcs3/Emu/PSP2/ARMv7Thread.h b/rpcs3/Emu/PSP2/ARMv7Thread.h index 3f0aaa9231..721277ab2e 100644 --- a/rpcs3/Emu/PSP2/ARMv7Thread.h +++ b/rpcs3/Emu/PSP2/ARMv7Thread.h @@ -134,6 +134,8 @@ public: u32 stack_addr = 0; u32 stack_size = 0; + const std::string m_name; + std::function custom_task; const char* last_function = nullptr;