From d7cb5a6e9ea62419543708745b952083acbd9dd3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 15 Jun 2015 14:37:01 +0300 Subject: [PATCH] vm::ref improved (operators) atomic operators fixed, vm::ptr operators improved --- rpcs3/Emu/Memory/atomic.h | 30 ++++--- rpcs3/Emu/Memory/vm_ptr.h | 34 +++++--- rpcs3/Emu/Memory/vm_ref.h | 107 +++++++++++++++++++++--- rpcs3/Emu/SysCalls/Modules/cellL10n.cpp | 12 +-- 4 files changed, 137 insertions(+), 46 deletions(-) diff --git a/rpcs3/Emu/Memory/atomic.h b/rpcs3/Emu/Memory/atomic.h index fc4e430bb6..6eea856d7c 100644 --- a/rpcs3/Emu/Memory/atomic.h +++ b/rpcs3/Emu/Memory/atomic.h @@ -190,42 +190,40 @@ public: } }; -// Helper definitions +template using if_integral_le_t = std::enable_if_t::value && std::is_integral::value, le_t>; +template using if_integral_be_t = std::enable_if_t::value && std::is_integral::value, be_t>; -template using if_arithmetic_le_t = std::enable_if_t::value && std::is_arithmetic::value, le_t>; -template using if_arithmetic_be_t = std::enable_if_t::value && std::is_arithmetic::value, be_t>; - -template inline static if_arithmetic_le_t operator ++(_atomic_base>& left) +template inline if_integral_le_t operator ++(_atomic_base>& left) { return left.from_subtype(sync_fetch_and_add(&left.sub_data, 1) + 1); } -template inline static if_arithmetic_le_t operator --(_atomic_base>& left) +template inline if_integral_le_t operator --(_atomic_base>& left) { return left.from_subtype(sync_fetch_and_sub(&left.sub_data, 1) - 1); } -template inline static if_arithmetic_le_t operator ++(_atomic_base>& left, int) +template inline if_integral_le_t operator ++(_atomic_base>& left, int) { return left.from_subtype(sync_fetch_and_add(&left.sub_data, 1)); } -template inline static if_arithmetic_le_t operator --(_atomic_base>& left, int) +template inline if_integral_le_t operator --(_atomic_base>& left, int) { return left.from_subtype(sync_fetch_and_sub(&left.sub_data, 1)); } -template inline static if_arithmetic_le_t operator +=(_atomic_base>& left, T2 right) +template inline if_integral_le_t operator +=(_atomic_base>& left, T2 right) { return left.from_subtype(sync_fetch_and_add(&left.sub_data, right) + right); } -template inline static if_arithmetic_le_t operator -=(_atomic_base>& left, T2 right) +template inline if_integral_le_t operator -=(_atomic_base>& left, T2 right) { return left.from_subtype(sync_fetch_and_sub(&left.sub_data, right) - right); } -template inline static if_arithmetic_be_t operator ++(_atomic_base>& left) +template inline if_integral_be_t operator ++(_atomic_base>& left) { be_t result; @@ -237,7 +235,7 @@ template inline static if_arithmetic_be_t operator ++(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator --(_atomic_base>& left) +template inline if_integral_be_t operator --(_atomic_base>& left) { be_t result; @@ -249,7 +247,7 @@ template inline static if_arithmetic_be_t operator --(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator ++(_atomic_base>& left, int) +template inline if_integral_be_t operator ++(_atomic_base>& left, int) { be_t result; @@ -261,7 +259,7 @@ template inline static if_arithmetic_be_t operator ++(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator --(_atomic_base>& left, int) +template inline if_integral_be_t operator --(_atomic_base>& left, int) { be_t result; @@ -273,7 +271,7 @@ template inline static if_arithmetic_be_t operator --(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator +=(_atomic_base>& left, T2 right) +template inline if_integral_be_t operator +=(_atomic_base>& left, T2 right) { be_t result; @@ -285,7 +283,7 @@ template inline static if_arithmetic_be_t operat return result; } -template inline static if_arithmetic_be_t operator -=(_atomic_base>& left, T2 right) +template inline if_integral_be_t operator -=(_atomic_base>& left, T2 right) { be_t result; diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 63b7dfd455..61c828f57b 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -58,7 +58,7 @@ namespace vm return{ convert_le_be(vm::cast(m_addr)) }; } - explicit operator T*() const + template::value>> explicit operator T2*() const { return get_ptr(); } @@ -210,14 +210,20 @@ namespace vm RT>; } +// unary plus operator for vm::_ptr_base (always available) +template inline vm::_ptr_base operator +(const vm::_ptr_base& ptr) +{ + return ptr; +} + // indirection operator for vm::_ptr_base -template vm::if_arithmetical_t operator *(const vm::_ptr_base& ptr) +template inline vm::if_arithmetical_t operator *(const vm::_ptr_base& ptr) { return vm::get_ref(vm::cast(ptr.m_addr)); } // postfix increment operator for vm::_ptr_base -template vm::if_arithmetical_t> operator ++(vm::_ptr_base& ptr, int) +template inline vm::if_arithmetical_t> operator ++(vm::_ptr_base& ptr, int) { const AT result = ptr.m_addr; ptr.m_addr += sizeof32(T); @@ -225,14 +231,14 @@ template vm::if_arithmetical_t> } // prefix increment operator for vm::_ptr_base -template vm::if_arithmetical_t&> operator ++(vm::_ptr_base& ptr) +template inline vm::if_arithmetical_t&> operator ++(vm::_ptr_base& ptr) { ptr.m_addr += sizeof32(T); return ptr; } // postfix decrement operator for vm::_ptr_base -template vm::if_arithmetical_t> operator --(vm::_ptr_base& ptr, int) +template inline vm::if_arithmetical_t> operator --(vm::_ptr_base& ptr, int) { const AT result = ptr.m_addr; ptr.m_addr -= sizeof32(T); @@ -240,40 +246,46 @@ template vm::if_arithmetical_t> } // prefix decrement operator for vm::_ptr_base -template vm::if_arithmetical_t&> operator --(vm::_ptr_base& ptr) +template inline vm::if_arithmetical_t&> operator --(vm::_ptr_base& ptr) { ptr.m_addr -= sizeof32(T); return ptr; } // addition assignment operator for vm::_ptr_base (pointer += integer) -template vm::if_arithmetical_t&> operator +=(vm::_ptr_base& ptr, to_ne_t count) +template inline vm::if_arithmetical_t&> operator +=(vm::_ptr_base& ptr, to_ne_t count) { ptr.m_addr += count * sizeof32(T); return ptr; } // subtraction assignment operator for vm::_ptr_base (pointer -= integer) -template vm::if_arithmetical_t&> operator -=(vm::_ptr_base& ptr, to_ne_t count) +template inline vm::if_arithmetical_t&> operator -=(vm::_ptr_base& ptr, to_ne_t count) { ptr.m_addr -= count * sizeof32(T); return ptr; } // addition operator for vm::_ptr_base (pointer + integer) -template vm::if_arithmetical_t> operator +(const vm::_ptr_base& ptr, to_ne_t count) +template inline vm::if_arithmetical_t> operator +(const vm::_ptr_base& ptr, to_ne_t count) +{ + return{ convert_le_be(ptr.m_addr + count * sizeof32(T)) }; +} + +// addition operator for vm::_ptr_base (integer + pointer) +template inline vm::if_arithmetical_t> operator +(to_ne_t count, const vm::_ptr_base& ptr) { return{ convert_le_be(ptr.m_addr + count * sizeof32(T)) }; } // subtraction operator for vm::_ptr_base (pointer - integer) -template vm::if_arithmetical_t> operator -(const vm::_ptr_base& ptr, to_ne_t count) +template inline vm::if_arithmetical_t> operator -(const vm::_ptr_base& ptr, to_ne_t count) { return{ convert_le_be(ptr.m_addr - count * sizeof32(T)) }; } // pointer difference operator for vm::_ptr_base -template std::enable_if_t< +template inline std::enable_if_t< !std::is_void::value && !std::is_void::value && !std::is_function::value && diff --git a/rpcs3/Emu/Memory/vm_ref.h b/rpcs3/Emu/Memory/vm_ref.h index a9ef324903..6a42afa5f7 100644 --- a/rpcs3/Emu/Memory/vm_ref.h +++ b/rpcs3/Emu/Memory/vm_ref.h @@ -43,28 +43,25 @@ namespace vm return get_ref(); } - //operator T() const - //{ - // return get_ref(); - //} + explicit operator T&() const + { + return get_ref(); + } // copy assignment operator - _ref_base& operator =(const _ref_base& right) + auto operator =(const _ref_base& right) -> decltype(std::declval() = std::declval()) { - get_ref() = right.get_ref(); - return *this; + return get_ref() = right.get_ref(); } - template std::enable_if_t::value, const _ref_base&> operator =(const _ref_base& right) const + template auto operator =(const _ref_base& right) -> decltype(std::declval() = std::declval()) const { - get_ref() = right.get_ref(); - return *this; + return get_ref() = right.get_ref(); } - template std::enable_if_t::value, const _ref_base&> operator =(const CT& right) const + template auto operator =(const CT& right) -> decltype(std::declval() = std::declval()) const { - get_ref() = right; - return *this; + return get_ref() = right; } }; @@ -108,6 +105,90 @@ namespace vm using namespace ps3; } +// postfix increment operator for vm::_ref_base +template inline auto operator ++(const vm::_ref_base& ref, int) -> decltype(std::declval()++) +{ + return ref.get_ref()++; +} + +// prefix increment operator for vm::_ref_base +template inline auto operator ++(const vm::_ref_base& ref) -> decltype(++std::declval()) +{ + return ++ref.get_ref(); +} + +// postfix decrement operator for vm::_ref_base +template inline auto operator --(const vm::_ref_base& ref, int) -> decltype(std::declval()--) +{ + return ref.get_ref()--; +} + +// prefix decrement operator for vm::_ref_base +template inline auto operator --(const vm::_ref_base& ref) -> decltype(--std::declval()) +{ + return --ref.get_ref(); +} + +// addition assignment operator for vm::_ref_base +template inline auto operator +=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() += std::declval()) +{ + return ref.get_ref() += right; +} + +// subtraction assignment operator for vm::_ref_base +template inline auto operator -=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() -= std::declval()) +{ + return ref.get_ref() -= right; +} + +// multiplication assignment operator for vm::_ref_base +template inline auto operator *=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() *= std::declval()) +{ + return ref.get_ref() *= right; +} + +// division assignment operator for vm::_ref_base +template inline auto operator /=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() /= std::declval()) +{ + return ref.get_ref() /= right; +} + +// modulo assignment operator for vm::_ref_base +template inline auto operator %=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() %= std::declval()) +{ + return ref.get_ref() %= right; +} + +// bitwise AND assignment operator for vm::_ref_base +template inline auto operator &=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() &= std::declval()) +{ + return ref.get_ref() &= right; +} + +// bitwise OR assignment operator for vm::_ref_base +template inline auto operator |=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() |= std::declval()) +{ + return ref.get_ref() |= right; +} + +// bitwise XOR assignment operator for vm::_ref_base +template inline auto operator ^=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() ^= std::declval()) +{ + return ref.get_ref() ^= right; +} + +// bitwise left shift assignment operator for vm::_ref_base +template inline auto operator <<=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() <<= std::declval()) +{ + return ref.get_ref() <<= right; +} + +// bitwise right shift assignment operator for vm::_ref_base +template inline auto operator >>=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() >>= std::declval()) +{ + return ref.get_ref() >>= right; +} + // external specialization for is_be_t<> (true if AT's endianness is BE) template diff --git a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp index 25abd0e916..3bb1b38525 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp @@ -27,17 +27,17 @@ s32 UTF16stoUTF8s(vm::ptr utf16, vm::ref utf16_len, vm::ptr len = len + 1; // validate character (TODO) - if (false) - { - utf16_len = utf16_len - i; - return SRCIllegal; - } + //if () + //{ + // utf16_len -= i; + // return SRCIllegal; + //} if (utf8) { if (len > max_len) { - utf16_len = utf16_len - i; + utf16_len -= i; return DSTExhausted; }