From 0f87c4485d7002062fd7f357585f47ecc36881eb Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 14 Aug 2016 03:22:19 +0300 Subject: [PATCH] Silly macro removed-2 --- Utilities/Atomic.h | 1 - Utilities/BEType.h | 6 +- Utilities/BitField.h | 2 +- Utilities/File.cpp | 91 ++++------------ Utilities/File.h | 7 +- Utilities/JIT.cpp | 1 - Utilities/Log.h | 1 - Utilities/Macro.h | 43 -------- Utilities/Platform.cpp | 51 --------- Utilities/Platform.h | 128 ---------------------- Utilities/Semaphore.h | 1 - Utilities/SharedMutex.h | 1 - Utilities/StrFmt.cpp | 27 +++-- Utilities/StrFmt.h | 8 +- Utilities/Thread.h | 6 +- Utilities/bit_set.h | 2 +- Utilities/cfmt.h | 5 +- Utilities/lockless.h | 1 - Utilities/sync.h | 1 - Utilities/types.h | 132 ++++++++++++++++++++++- rpcs3/Emu/Cell/Modules/cellKb.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellMouse.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp | 12 ++- rpcs3/Emu/Cell/Modules/cellPad.cpp | 2 +- rpcs3/Emu/Cell/PPUTranslator.h | 1 - rpcs3/Emu/Cell/SPUInterpreter.cpp | 4 +- rpcs3/Emu/Cell/lv2/sys_time.cpp | 121 ++++++++++++++------- rpcs3/Emu/IdManager.h | 2 - rpcs3/Emu/Memory/vm.cpp | 8 +- rpcs3/Emu/Memory/wait_engine.h | 1 - rpcs3/Emu/RSX/VK/VKHelpers.cpp | 40 ++++--- rpcs3/Emu/RSX/gcm_enums.cpp | 1 - rpcs3/Emu/RSX/rsx_utils.h | 2 +- rpcs3/Emu/System.cpp | 2 +- rpcs3/emucore.vcxproj | 2 - rpcs3/emucore.vcxproj.filters | 6 -- rpcs3/rpcs3.cpp | 38 +++---- rpcs3/stdafx.h | 30 +++--- 38 files changed, 346 insertions(+), 445 deletions(-) delete mode 100644 Utilities/Macro.h delete mode 100644 Utilities/Platform.cpp delete mode 100644 Utilities/Platform.h diff --git a/Utilities/Atomic.h b/Utilities/Atomic.h index 4204267b86..d40e9e6f1c 100644 --- a/Utilities/Atomic.h +++ b/Utilities/Atomic.h @@ -1,7 +1,6 @@ #pragma once #include "types.h" -#include "Platform.h" // Helper class, provides access to compiler-specific atomic intrinsics template diff --git a/Utilities/BEType.h b/Utilities/BEType.h index b55e013c0c..4cba394db8 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -1,7 +1,6 @@ #pragma once #include "types.h" -#include "Platform.h" // 128-bit vector type and also se_storage<> storage type union alignas(16) v128 @@ -353,7 +352,10 @@ struct se_storage static type copy(const type& src) { type result; - std::memcpy(&result, &src, Size); + for (std::size_t i = 0; i < Size; i++) + { + reinterpret_cast(&result)[i] = reinterpret_cast(&src)[i]; + } return result; } }; diff --git a/Utilities/BitField.h b/Utilities/BitField.h index b592e347c0..9da2d14fc0 100644 --- a/Utilities/BitField.h +++ b/Utilities/BitField.h @@ -9,7 +9,7 @@ struct bf_base using vtype = simple_t; // Datatype bitsize - static constexpr uint bitmax = sizeof(T) * CHAR_BIT; static_assert(N - 1 < bitmax, "bf_base<> error: N out of bounds"); + static constexpr uint bitmax = sizeof(T) * 8; static_assert(N - 1 < bitmax, "bf_base<> error: N out of bounds"); // Field bitsize static constexpr uint bitsize = N; diff --git a/Utilities/File.cpp b/Utilities/File.cpp index f451df5ad0..a1af1265e5 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1,6 +1,5 @@ #include "File.h" #include "StrFmt.h" -#include "Macro.h" #include "SharedMutex.h" #include "BEType.h" #include "Crypto/sha1.h" @@ -22,10 +21,7 @@ static std::unique_ptr to_wchar(const std::string& source) std::unique_ptr buffer(new wchar_t[buf_size]); // allocate buffer assuming that length is the max possible size - if (!MultiByteToWideChar(CP_UTF8, 0, source.c_str(), size, buffer.get(), size)) - { - fmt::throw_exception("to_wchar(): MultiByteToWideChar() failed: error %u.", GetLastError()); - } + verify("to_wchar" HERE), MultiByteToWideChar(CP_UTF8, 0, source.c_str(), size, buffer.get(), size); return buffer; } @@ -38,14 +34,10 @@ static void to_utf8(std::string& result, const wchar_t* source) result.resize(buf_size); // set max possible length for utf-8 + null terminator - if (const int nwritten = WideCharToMultiByte(CP_UTF8, 0, source, static_cast(length) + 1, &result.front(), buf_size, NULL, NULL)) - { - result.resize(nwritten - 1); // fix the size, remove null terminator - } - else - { - fmt::throw_exception("to_utf8(): WideCharToMultiByte() failed: error %u.", GetLastError()); - } + const int nwritten = verify(WideCharToMultiByte(CP_UTF8, 0, source, static_cast(length) + 1, &result.front(), buf_size, NULL, NULL), "to_utf8" HERE); + + // fix the size, remove null terminator + result.resize(nwritten - 1); } static time_t to_time(const ULARGE_INTEGER& ft) @@ -692,10 +684,7 @@ bool fs::file::open(const std::string& path, bs_t mode) stat_t stat() override { FILE_BASIC_INFO basic_info; - if (!GetFileInformationByHandleEx(m_handle, FileBasicInfo, &basic_info, sizeof(FILE_BASIC_INFO))) - { - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); - } + verify("file::stat" HERE), GetFileInformationByHandleEx(m_handle, FileBasicInfo, &basic_info, sizeof(FILE_BASIC_INFO)); stat_t info; info.is_directory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; @@ -726,14 +715,8 @@ bool fs::file::open(const std::string& path, bs_t mode) return false; } - const BOOL result = SetEndOfFile(m_handle); // change file size - - if (!result || !SetFilePointerEx(m_handle, old, NULL, FILE_BEGIN)) // restore position - { - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); - } - - return result != FALSE; + verify("file::trunc" HERE), SetEndOfFile(m_handle), SetFilePointerEx(m_handle, old, NULL, FILE_BEGIN); + return true; } u64 read(void* buffer, u64 count) override @@ -743,10 +726,7 @@ bool fs::file::open(const std::string& path, bs_t mode) EXPECTS(size >= 0); DWORD nread; - if (!ReadFile(m_handle, buffer, size, &nread, NULL)) - { - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); - } + verify("file::read" HERE), ReadFile(m_handle, buffer, size, &nread, NULL); return nread; } @@ -758,10 +738,7 @@ bool fs::file::open(const std::string& path, bs_t mode) EXPECTS(size >= 0); DWORD nwritten; - if (!WriteFile(m_handle, buffer, size, &nwritten, NULL)) - { - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); - } + verify("file::write" HERE), WriteFile(m_handle, buffer, size, &nwritten, NULL); return nwritten; } @@ -777,10 +754,7 @@ bool fs::file::open(const std::string& path, bs_t mode) whence == seek_end ? FILE_END : (fmt::throw_exception("Invalid whence (0x%x)" HERE, whence), 0); - if (!SetFilePointerEx(m_handle, pos, &pos, mode)) - { - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); - } + verify("file::seek" HERE), SetFilePointerEx(m_handle, pos, &pos, mode); return pos.QuadPart; } @@ -788,10 +762,7 @@ bool fs::file::open(const std::string& path, bs_t mode) u64 size() override { LARGE_INTEGER size; - if (!GetFileSizeEx(m_handle, &size)) - { - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); - } + verify("file::size" HERE), GetFileSizeEx(m_handle, &size); return size.QuadPart; } @@ -836,10 +807,7 @@ bool fs::file::open(const std::string& path, bs_t mode) stat_t stat() override { struct ::stat file_info; - if (::fstat(m_fd, &file_info) != 0) - { - fmt::throw_exception("System error: %d." HERE, errno); - } + verify("file::stat" HERE), ::fstat(m_fd, &file_info) == 0; stat_t info; info.is_directory = S_ISDIR(file_info.st_mode); @@ -866,10 +834,7 @@ bool fs::file::open(const std::string& path, bs_t mode) u64 read(void* buffer, u64 count) override { const auto result = ::read(m_fd, buffer, count); - if (result == -1) - { - fmt::throw_exception("System error: %d." HERE, errno); - } + verify("file::read" HERE), result != -1; return result; } @@ -877,10 +842,7 @@ bool fs::file::open(const std::string& path, bs_t mode) u64 write(const void* buffer, u64 count) override { const auto result = ::write(m_fd, buffer, count); - if (result == -1) - { - fmt::throw_exception("System error: %d." HERE, errno); - } + verify("file::write" HERE), result != -1; return result; } @@ -894,10 +856,7 @@ bool fs::file::open(const std::string& path, bs_t mode) (fmt::throw_exception("Invalid whence (0x%x)" HERE, whence), 0); const auto result = ::lseek(m_fd, offset, mode); - if (result == -1) - { - fmt::throw_exception("System error: %d." HERE, errno); - } + verify("file::seek" HERE), result != -1; return result; } @@ -905,10 +864,7 @@ bool fs::file::open(const std::string& path, bs_t mode) u64 size() override { struct ::stat file_info; - if (::fstat(m_fd, &file_info) != 0) - { - fmt::throw_exception("System error: %d." HERE, errno); - } + verify("file::size" HERE), ::fstat(m_fd, &file_info) == 0; return file_info.st_size; } @@ -1048,12 +1004,8 @@ bool fs::dir::open(const std::string& path) WIN32_FIND_DATAW found; if (!FindNextFileW(m_handle, &found)) { - if (ERROR_NO_MORE_FILES == GetLastError()) - { - return false; - } - - fmt::throw_exception("Win32 error: %u." HERE, GetLastError()); + verify("dir::read" HERE), ERROR_NO_MORE_FILES == GetLastError(); + return false; } add_entry(found); @@ -1103,10 +1055,7 @@ bool fs::dir::open(const std::string& path) } struct ::stat file_info; - if (::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) != 0) - { - fmt::throw_exception("System error: %d." HERE, errno); - } + verify("dir::read" HERE), ::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) == 0; info.name = found->d_name; info.is_directory = S_ISDIR(file_info.st_mode); diff --git a/Utilities/File.h b/Utilities/File.h index ddffd4667a..0146e8f422 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -1,12 +1,11 @@ #pragma once +#include "types.h" +#include "bit_set.h" + #include #include #include -#include - -#include "types.h" -#include "bit_set.h" namespace fs { diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index 9d7fec31bb..733a4c5002 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -7,7 +7,6 @@ #include #include "types.h" -#include "Macro.h" #include "StrFmt.h" #include "File.h" #include "Log.h" diff --git a/Utilities/Log.h b/Utilities/Log.h index e48b7d656a..6829fc0c9a 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -1,7 +1,6 @@ #pragma once #include "types.h" -#include "Platform.h" #include "Atomic.h" #include "StrFmt.h" diff --git a/Utilities/Macro.h b/Utilities/Macro.h deleted file mode 100644 index 6bbcc985e6..0000000000 --- a/Utilities/Macro.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "types.h" - -#define CHECK_SIZE(type, size) static_assert(sizeof(type) == size, "Invalid " #type " type size") -#define CHECK_ALIGN(type, align) static_assert(alignof(type) == align, "Invalid " #type " type alignment") -#define CHECK_MAX_SIZE(type, size) static_assert(sizeof(type) <= size, #type " type size is too big") -#define CHECK_SIZE_ALIGN(type, size, align) CHECK_SIZE(type, size); CHECK_ALIGN(type, align) -#define CHECK_STORAGE(type, storage) static_assert(sizeof(type) <= sizeof(storage) && alignof(type) <= alignof(decltype(storage)), #type " is too small") - -// Return 32 bit sizeof() to avoid widening/narrowing conversions with size_t -#define SIZE_32(type) static_cast(sizeof(type)) - -// Return 32 bit alignof() to avoid widening/narrowing conversions with size_t -#define ALIGN_32(type) static_cast(alignof(type)) - -// Return 32 bit custom offsetof() -#define OFFSET_32(type, x) static_cast(reinterpret_cast(&reinterpret_cast(reinterpret_cast(0ull)->x))) - -#define CONCATENATE_DETAIL(x, y) x ## y -#define CONCATENATE(x, y) CONCATENATE_DETAIL(x, y) - -#define STRINGIZE_DETAIL(x) #x -#define STRINGIZE(x) STRINGIZE_DETAIL(x) - -// Macro set, wraps an expression into lambda -#define WRAP_EXPR(expr, ...) [&](__VA_ARGS__) { return expr; } -#define COPY_EXPR(expr, ...) [=](__VA_ARGS__) { return expr; } -#define PURE_EXPR(expr, ...) [] (__VA_ARGS__) { return expr; } - -#define HERE "\n(in file " __FILE__ ":" STRINGIZE(__LINE__) ")" - -// Ensure that the expression is evaluated to true. Always evaluated and allowed to have side effects (unlike assert() macro). -#define VERIFY(expr) do { if (!(expr)) fmt::raw_error("Verification failed: " #expr HERE); } while (0) - -// EXPECTS() and ENSURES() are intended to check function arguments and results. -// Expressions are not guaranteed to evaluate. -#define EXPECTS(expr) do { if (!(expr)) fmt::raw_error("Precondition failed: " #expr HERE); } while (0) -#define ENSURES(expr) do { if (!(expr)) fmt::raw_error("Postcondition failed: " #expr HERE); } while (0) - -#define DECLARE(...) decltype(__VA_ARGS__) __VA_ARGS__ - -#define STR_CASE(value) case value: return #value diff --git a/Utilities/Platform.cpp b/Utilities/Platform.cpp deleted file mode 100644 index 9f2672997e..0000000000 --- a/Utilities/Platform.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "Platform.h" - -#ifdef __APPLE__ -#include -#include -#include -#include -#include -#undef CPU_STATE_MAX - -#define MT_NANO (+1.0E-9) -#define MT_GIGA UINT64_C(1000000000) - -// TODO create a list of timers, -static double mt_timebase = 0.0; -static uint64_t mt_timestart = 0; - -// TODO be more careful in a multithreaded environement -int clock_gettime(clockid_t clk_id, struct timespec *tp) -{ - kern_return_t retval = KERN_SUCCESS; - if( clk_id == TIMER_ABSTIME) - { - if (!mt_timestart) { // only one timer, initilized on the first call to the TIMER - mach_timebase_info_data_t tb = { 0 }; - mach_timebase_info(&tb); - mt_timebase = tb.numer; - mt_timebase /= tb.denom; - mt_timestart = mach_absolute_time(); - } - - double diff = (mach_absolute_time() - mt_timestart) * mt_timebase; - tp->tv_sec = diff * MT_NANO; - tp->tv_nsec = diff - (tp->tv_sec * MT_GIGA); - } - else // other clk_ids are mapped to the coresponding mach clock_service - { - clock_serv_t cclock; - mach_timespec_t mts; - - host_get_clock_service(mach_host_self(), clk_id, &cclock); - retval = clock_get_time(cclock, &mts); - mach_port_deallocate(mach_task_self(), cclock); - - tp->tv_sec = mts.tv_sec; - tp->tv_nsec = mts.tv_nsec; - } - - return retval; -} -#endif /* __APPLE__ */ diff --git a/Utilities/Platform.h b/Utilities/Platform.h deleted file mode 100644 index a1cfa7a544..0000000000 --- a/Utilities/Platform.h +++ /dev/null @@ -1,128 +0,0 @@ -#pragma once - -#include -#include -#include - -#define IS_LE_MACHINE 1 -#define IS_BE_MACHINE 0 - -#ifdef _MSC_VER -#include -#else -#include -#endif - -#ifdef _MSC_VER -#define ASSUME(cond) __assume(cond) -#define LIKELY(cond) (cond) -#define UNLIKELY(cond) (cond) -#else -#define ASSUME(cond) do { if (!(cond)) __builtin_unreachable(); } while (0) -#define LIKELY(cond) __builtin_expect(!!(cond), 1) -#define UNLIKELY(cond) __builtin_expect(!!(cond), 0) -#endif - -// Some platforms don't support thread_local well yet. -#ifndef _MSC_VER -#define thread_local __thread -#endif - -#ifdef _MSC_VER -#define SAFE_BUFFERS __declspec(safebuffers) -#else -#define SAFE_BUFFERS -#endif - -#ifdef _MSC_VER -#define NEVER_INLINE __declspec(noinline) -#else -#define NEVER_INLINE __attribute__((noinline)) -#endif - -#ifdef _MSC_VER -#define FORCE_INLINE __forceinline -#else -#define FORCE_INLINE __attribute__((always_inline)) inline -#endif - -#if defined(__GNUG__) - -#include - -#define _fpclass(x) std::fpclassify(x) -#define INFINITE 0xFFFFFFFF - -#ifdef __APPLE__ - -// XXX only supports a single timer -#define TIMER_ABSTIME -1 -/* The opengroup spec isn't clear on the mapping from REALTIME to CALENDAR - being appropriate or not. - http://pubs.opengroup.org/onlinepubs/009695299/basedefs/time.h.html */ -#define CLOCK_REALTIME 1 // #define CALENDAR_CLOCK 1 from mach/clock_types.h -#define CLOCK_MONOTONIC 0 // #define SYSTEM_CLOCK 0 - -typedef int clockid_t; - -/* the mach kernel uses struct mach_timespec, so struct timespec - is loaded from for compatability */ -// struct timespec { time_t tv_sec; long tv_nsec; }; - -int clock_gettime(clockid_t clk_id, struct timespec *tp); - -#endif /* __APPLE__ */ -#endif /* __GNUG__ */ - -inline std::uint32_t cntlz32(std::uint32_t arg) -{ -#if defined(_MSC_VER) - unsigned long res; - return _BitScanReverse(&res, arg) ? res ^ 31 : 32; -#else - return arg ? __builtin_clzll(arg) - 32 : 32; -#endif -} - -inline std::uint64_t cntlz64(std::uint64_t arg) -{ -#if defined(_MSC_VER) - unsigned long res; - return _BitScanReverse64(&res, arg) ? res ^ 63 : 64; -#else - return arg ? __builtin_clzll(arg) : 64; -#endif -} - -// Helper function, used by ""_u16, ""_u32, ""_u64 -constexpr std::uint8_t to_u8(char c) -{ - return static_cast(c); -} - -// Convert 2-byte string to u16 value like reinterpret_cast does -constexpr std::uint16_t operator""_u16(const char* s, std::size_t length) -{ - return length != 2 ? throw s : -#if IS_LE_MACHINE == 1 - to_u8(s[1]) << 8 | to_u8(s[0]); -#endif -} - -// Convert 4-byte string to u32 value like reinterpret_cast does -constexpr std::uint32_t operator""_u32(const char* s, std::size_t length) -{ - return length != 4 ? throw s : -#if IS_LE_MACHINE == 1 - to_u8(s[3]) << 24 | to_u8(s[2]) << 16 | to_u8(s[1]) << 8 | to_u8(s[0]); -#endif -} - -// Convert 8-byte string to u64 value like reinterpret_cast does -constexpr std::uint64_t operator""_u64(const char* s, std::size_t length) -{ - return length != 8 ? throw s : -#if IS_LE_MACHINE == 1 - static_cast(to_u8(s[7]) << 24 | to_u8(s[6]) << 16 | to_u8(s[5]) << 8 | to_u8(s[4])) << 32 | to_u8(s[3]) << 24 | to_u8(s[2]) << 16 | to_u8(s[1]) << 8 | to_u8(s[0]); -#endif -} diff --git a/Utilities/Semaphore.h b/Utilities/Semaphore.h index 5ecde9a44c..cd8bdfcd41 100644 --- a/Utilities/Semaphore.h +++ b/Utilities/Semaphore.h @@ -2,7 +2,6 @@ #include "types.h" #include "Atomic.h" -#include "Platform.h" // Binary semaphore class benaphore diff --git a/Utilities/SharedMutex.h b/Utilities/SharedMutex.h index 0d69d36e07..fe01558bdf 100644 --- a/Utilities/SharedMutex.h +++ b/Utilities/SharedMutex.h @@ -2,7 +2,6 @@ #include "types.h" #include "Atomic.h" -#include "Platform.h" //! An attempt to create effective implementation of "shared mutex", lock-free in optimistic case. //! All locking and unlocking may be done by a single LOCK XADD or LOCK CMPXCHG instruction. diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 36f05551b9..93fd9693d0 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -1,11 +1,16 @@ #include "StrFmt.h" #include "BEType.h" #include "StrUtil.h" -#include "Macro.h" #include "cfmt.h" #include +#ifdef _WIN32 +#include +#else +#include +#endif + void fmt_class_string::format(std::string& out, u64 arg) { fmt::append(out, "%p", reinterpret_cast(static_cast(arg))); @@ -124,18 +129,26 @@ namespace fmt { void raw_error(const char* msg) { - std::string out{"Error"}; - - out += ": "; - out += msg; - - throw std::runtime_error{out}; + throw std::runtime_error{msg}; } void raw_verify_error(const char* msg, uint position) { std::string out{"Verification failed"}; + // Print error code (may be irrelevant) +#ifdef _WIN32 + if (DWORD error = GetLastError()) + { + fmt::append(out, " (e%#x)", error); + } +#else + if (int error = errno) + { + fmt::append(out, " (e%d)", error); + } +#endif + if (position) { out += " (+"; diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 3b283fcf7b..9c080d7e94 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -1,11 +1,11 @@ #pragma once -#include -#include - -#include "Platform.h" #include "types.h" +#include +#include +#include + namespace fmt { template diff --git a/Utilities/Thread.h b/Utilities/Thread.h index ffa3ef63bb..8c61cbf974 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -1,12 +1,12 @@ #pragma once +#include "types.h" +#include "Atomic.h" + #include #include #include -#include "Platform.h" -#include "Atomic.h" - // Will report exception and call std::abort() if put in catch(...) [[noreturn]] void catch_all_exceptions(); diff --git a/Utilities/bit_set.h b/Utilities/bit_set.h index fda36f5ec8..cc6b30f74a 100644 --- a/Utilities/bit_set.h +++ b/Utilities/bit_set.h @@ -59,7 +59,7 @@ struct bs_base __bitset_set_type = 0 // SFINAE marker }; - static constexpr std::size_t bitmax = sizeof(T) * CHAR_BIT; + static constexpr std::size_t bitmax = sizeof(T) * 8; static constexpr std::size_t bitsize = static_cast(T::__bitset_enum_max); static_assert(std::is_enum::value, "bs_t<> error: invalid type (must be enum)"); diff --git a/Utilities/cfmt.h b/Utilities/cfmt.h index 6573b8faa8..05bd5c13bf 100644 --- a/Utilities/cfmt.h +++ b/Utilities/cfmt.h @@ -1,6 +1,7 @@ #pragma once #include "types.h" +#include #include #include #include @@ -55,7 +56,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) const auto write_octal = [&](u64 value, u64 min_num) { - out.resize(out.size() + std::max(min_num, 66 / 3 - (cntlz64(value | 1) + 2) / 3), '0'); + out.resize(out.size() + std::max(min_num, 66 / 3 - (cntlz64(value | 1, true) + 2) / 3), '0'); // Write in reversed order for (auto i = out.rbegin(); value; i++, value /= 8) @@ -66,7 +67,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) const auto write_hex = [&](u64 value, bool upper, u64 min_num) { - out.resize(out.size() + std::max(min_num, 64 / 4 - cntlz64(value | 1) / 4), '0'); + out.resize(out.size() + std::max(min_num, 64 / 4 - cntlz64(value | 1, true) / 4), '0'); // Write in reversed order for (auto i = out.rbegin(); value; i++, value /= 16) diff --git a/Utilities/lockless.h b/Utilities/lockless.h index c6890722b2..f7b98cd65c 100644 --- a/Utilities/lockless.h +++ b/Utilities/lockless.h @@ -2,7 +2,6 @@ #include "types.h" #include "Atomic.h" -#include "Platform.h" //! Simple sizeless array base for concurrent access. Cannot shrink, only growths automatically. //! There is no way to know the current size. The smaller index is, the faster it's accessed. diff --git a/Utilities/sync.h b/Utilities/sync.h index 01c5d2e7d6..98fa4d8377 100644 --- a/Utilities/sync.h +++ b/Utilities/sync.h @@ -3,7 +3,6 @@ /* For internal use. Don't include. */ #include "types.h" -#include "Macro.h" #include "Atomic.h" #ifdef _WIN32 diff --git a/Utilities/types.h b/Utilities/types.h index 3fe743f57f..0b5c2b1b45 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -1,8 +1,77 @@ #pragma once +#ifdef _MSC_VER +#include +#else +#include +#endif +#include +#include + #include -#include #include +#include + +// Assume little-endian +#define IS_LE_MACHINE 1 +#define IS_BE_MACHINE 0 + +#ifdef _MSC_VER +#define ASSUME(cond) __assume(cond) +#define LIKELY(cond) (cond) +#define UNLIKELY(cond) (cond) +#define SAFE_BUFFERS __declspec(safebuffers) +#define NEVER_INLINE __declspec(noinline) +#define FORCE_INLINE __forceinline +#else +#define ASSUME(cond) do { if (!(cond)) __builtin_unreachable(); } while (0) +#define LIKELY(cond) __builtin_expect(!!(cond), 1) +#define UNLIKELY(cond) __builtin_expect(!!(cond), 0) +#define SAFE_BUFFERS +#define NEVER_INLINE __attribute__((noinline)) +#define FORCE_INLINE __attribute__((always_inline)) inline + +// Some platforms don't support thread_local well yet. +#define thread_local __thread +#endif + +#define CHECK_SIZE(type, size) static_assert(sizeof(type) == size, "Invalid " #type " type size") +#define CHECK_ALIGN(type, align) static_assert(alignof(type) == align, "Invalid " #type " type alignment") +#define CHECK_MAX_SIZE(type, size) static_assert(sizeof(type) <= size, #type " type size is too big") +#define CHECK_SIZE_ALIGN(type, size, align) CHECK_SIZE(type, size); CHECK_ALIGN(type, align) +#define CHECK_STORAGE(type, storage) static_assert(sizeof(type) <= sizeof(storage) && alignof(type) <= alignof(decltype(storage)), #type " is too small") + +// Return 32 bit sizeof() to avoid widening/narrowing conversions with size_t +#define SIZE_32(...) static_cast(sizeof(__VA_ARGS__)) + +// Return 32 bit alignof() to avoid widening/narrowing conversions with size_t +#define ALIGN_32(...) static_cast(alignof(__VA_ARGS__)) + +// Return 32 bit offsetof() +#define OFFSET_32(type, x) static_cast(reinterpret_cast(&reinterpret_cast(reinterpret_cast(0ull)->x))) + +#define CONCATENATE_DETAIL(x, y) x ## y +#define CONCATENATE(x, y) CONCATENATE_DETAIL(x, y) + +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) + +#define HERE "\n(in file " __FILE__ ":" STRINGIZE(__LINE__) ")" + +// Wrap an expression into lambda +#define WRAP_EXPR(...) [&] { return __VA_ARGS__; } + +// Ensure that the expression is evaluated to true. Always evaluated and allowed to have side effects (unlike assert() macro). +#define VERIFY(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Verification failed: " #__VA_ARGS__ HERE); } while (0) + +// EXPECTS() and ENSURES() are intended to check function arguments and results. +// Expressions are not guaranteed to evaluate. +#define EXPECTS(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Precondition failed: " #__VA_ARGS__ HERE); } while (0) +#define ENSURES(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Postcondition failed: " #__VA_ARGS__ HERE); } while (0) + +#define DECLARE(...) decltype(__VA_ARGS__) __VA_ARGS__ + +#define STR_CASE(...) case __VA_ARGS__: return #__VA_ARGS__ using schar = signed char; using uchar = unsigned char; @@ -159,8 +228,6 @@ using u128 = __uint128_t; using s128 = __int128_t; #else -#include "intrin.h" - // Unsigned 128-bit integer implementation (TODO) struct alignas(16) u128 { @@ -342,8 +409,8 @@ struct alignas(16) s128 }; #endif -static_assert(alignof(u128) == 16 && sizeof(u128) == 16, "Wrong u128 implementation"); -static_assert(alignof(s128) == 16 && sizeof(s128) == 16, "Wrong s128 implementation"); +CHECK_SIZE_ALIGN(u128, 16, 16); +CHECK_SIZE_ALIGN(s128, 16, 16); union alignas(2) f16 { @@ -366,6 +433,8 @@ union alignas(2) f16 } }; +CHECK_SIZE_ALIGN(f16, 2, 2); + using f32 = float; using f64 = double; @@ -383,6 +452,59 @@ constexpr T align(const T& value, std::uint64_t align) return static_cast((value + (align - 1)) & ~(align - 1)); } +inline std::uint32_t cntlz32(std::uint32_t arg, bool nonzero = false) +{ +#if defined(_MSC_VER) + unsigned long res; + return _BitScanReverse(&res, arg) || nonzero ? res ^ 31 : 32; +#else + return arg || nonzero ? __builtin_clzll(arg) - 32 : 32; +#endif +} + +inline std::uint64_t cntlz64(std::uint64_t arg, bool nonzero = false) +{ +#if defined(_MSC_VER) + unsigned long res; + return _BitScanReverse64(&res, arg) || nonzero ? res ^ 63 : 64; +#else + return arg || nonzero ? __builtin_clzll(arg) : 64; +#endif +} + +// Helper function, used by ""_u16, ""_u32, ""_u64 +constexpr std::uint8_t to_u8(char c) +{ + return static_cast(c); +} + +// Convert 2-byte string to u16 value like reinterpret_cast does +constexpr std::uint16_t operator""_u16(const char* s, std::size_t length) +{ + return length != 2 ? throw s : +#if IS_LE_MACHINE == 1 + to_u8(s[1]) << 8 | to_u8(s[0]); +#endif +} + +// Convert 4-byte string to u32 value like reinterpret_cast does +constexpr std::uint32_t operator""_u32(const char* s, std::size_t length) +{ + return length != 4 ? throw s : +#if IS_LE_MACHINE == 1 + to_u8(s[3]) << 24 | to_u8(s[2]) << 16 | to_u8(s[1]) << 8 | to_u8(s[0]); +#endif +} + +// Convert 8-byte string to u64 value like reinterpret_cast does +constexpr std::uint64_t operator""_u64(const char* s, std::size_t length) +{ + return length != 8 ? throw s : +#if IS_LE_MACHINE == 1 + static_cast(to_u8(s[7]) << 24 | to_u8(s[6]) << 16 | to_u8(s[5]) << 8 | to_u8(s[4])) << 32 | to_u8(s[3]) << 24 | to_u8(s[2]) << 16 | to_u8(s[1]) << 8 | to_u8(s[0]); +#endif +} + namespace fmt { [[noreturn]] void raw_error(const char* msg); diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index 08d69ae94d..ecaa46f89e 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -15,7 +15,7 @@ s32 cellKbInit(u32 max_connect) if (max_connect > 7) return CELL_KB_ERROR_INVALID_PARAMETER; - const auto handler = fxm::import(PURE_EXPR(Emu.GetCallbacks().get_kb_handler())); + const auto handler = fxm::import(Emu.GetCallbacks().get_kb_handler); if (!handler) return CELL_KB_ERROR_ALREADY_INITIALIZED; diff --git a/rpcs3/Emu/Cell/Modules/cellMouse.cpp b/rpcs3/Emu/Cell/Modules/cellMouse.cpp index fd91435ed9..2b97b40be8 100644 --- a/rpcs3/Emu/Cell/Modules/cellMouse.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMouse.cpp @@ -17,7 +17,7 @@ s32 cellMouseInit(u32 max_connect) return CELL_MOUSE_ERROR_INVALID_PARAMETER; } - const auto handler = fxm::import(PURE_EXPR(Emu.GetCallbacks().get_mouse_handler())); + const auto handler = fxm::import(Emu.GetCallbacks().get_mouse_handler); if (!handler) { diff --git a/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp b/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp index 59f5f6cafe..622d9a936e 100644 --- a/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp @@ -61,7 +61,7 @@ s32 cellMsgDialogOpen2(u32 type, vm::cptr msgString, vm::ptr(PURE_EXPR(Emu.GetCallbacks().get_msg_dialog())); + const auto dlg = fxm::import(Emu.GetCallbacks().get_msg_dialog); if (!dlg) { @@ -294,7 +294,10 @@ s32 cellMsgDialogProgressBarReset(u32 progressBarIndex) return CELL_MSGDIALOG_ERROR_PARAM; } - Emu.CallAfter(COPY_EXPR(dlg->ProgressBarReset(progressBarIndex))); + Emu.CallAfter([=] + { + dlg->ProgressBarReset(progressBarIndex); + }); return CELL_OK; } @@ -315,7 +318,10 @@ s32 cellMsgDialogProgressBarInc(u32 progressBarIndex, u32 delta) return CELL_MSGDIALOG_ERROR_PARAM; } - Emu.CallAfter(COPY_EXPR(dlg->ProgressBarInc(progressBarIndex, delta))); + Emu.CallAfter([=] + { + dlg->ProgressBarInc(progressBarIndex, delta); + }); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellPad.cpp b/rpcs3/Emu/Cell/Modules/cellPad.cpp index 0dc2b5db1f..8d230990a2 100644 --- a/rpcs3/Emu/Cell/Modules/cellPad.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPad.cpp @@ -15,7 +15,7 @@ s32 cellPadInit(u32 max_connect) if (max_connect > CELL_PAD_MAX_PORT_NUM) return CELL_PAD_ERROR_INVALID_PARAMETER; - const auto handler = fxm::import(PURE_EXPR(Emu.GetCallbacks().get_pad_handler())); + const auto handler = fxm::import(Emu.GetCallbacks().get_pad_handler); if (!handler) return CELL_PAD_ERROR_ALREADY_INITIALIZED; diff --git a/rpcs3/Emu/Cell/PPUTranslator.h b/rpcs3/Emu/Cell/PPUTranslator.h index d57925af09..5c36ee029b 100644 --- a/rpcs3/Emu/Cell/PPUTranslator.h +++ b/rpcs3/Emu/Cell/PPUTranslator.h @@ -23,7 +23,6 @@ #include "../Utilities/types.h" #include "../Utilities/StrFmt.h" -#include "../Utilities/Macro.h" #include "../Utilities/BEType.h" template diff --git a/rpcs3/Emu/Cell/SPUInterpreter.cpp b/rpcs3/Emu/Cell/SPUInterpreter.cpp index 5a7e2cd223..a8aca695db 100644 --- a/rpcs3/Emu/Cell/SPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/SPUInterpreter.cpp @@ -1359,7 +1359,7 @@ inline float ldexpf_extended(float x, int exp) // ldexpf() for extended values, inline bool isdenormal(float x) { - const int fpc = _fpclass(x); + const int fpc = std::fpclassify(x); #ifdef __GNUG__ return fpc == FP_SUBNORMAL; #else @@ -1369,7 +1369,7 @@ inline bool isdenormal(float x) inline bool isdenormal(double x) { - const int fpc = _fpclass(x); + const int fpc = std::fpclassify(x); #ifdef __GNUG__ return fpc == FP_SUBNORMAL; #else diff --git a/rpcs3/Emu/Cell/lv2/sys_time.cpp b/rpcs3/Emu/Cell/lv2/sys_time.cpp index d07b6fa73a..10c87b74a8 100644 --- a/rpcs3/Emu/Cell/lv2/sys_time.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_time.cpp @@ -14,14 +14,16 @@ struct time_aux_info_t u64 perf_freq; u64 start_time; u64 start_ftime; // time in 100ns units since Epoch -} -const g_time_aux_info = []() -> time_aux_info_t // initialize time-related values (Windows-only) +}; + +// Initialize time-related values +const auto s_time_aux_info = []() -> time_aux_info_t { LARGE_INTEGER freq; if (!QueryPerformanceFrequency(&freq)) { MessageBox(0, L"Your hardware doesn't support a high-resolution performance counter", L"Error", MB_OK | MB_ICONERROR); - return{}; + return {}; } LARGE_INTEGER start; @@ -31,16 +33,75 @@ const g_time_aux_info = []() -> time_aux_info_t // initialize time-related value GetSystemTimeAsFileTime(&ftime); // get time in 100ns units since January 1, 1601 (UTC) time_aux_info_t result; - result.perf_freq = freq.QuadPart; - result.start_time = start.QuadPart; + result.perf_freq = freq.QuadPart; + result.start_time = start.QuadPart; result.start_ftime = (ftime.dwLowDateTime | (u64)ftime.dwHighDateTime << 32) - 116444736000000000; return result; }(); -#else +#elif __APPLE__ -#include "errno.h" +// XXX only supports a single timer +#define TIMER_ABSTIME -1 +// The opengroup spec isn't clear on the mapping from REALTIME to CALENDAR being appropriate or not. +// http://pubs.opengroup.org/onlinepubs/009695299/basedefs/time.h.html +#define CLOCK_REALTIME 1 // #define CALENDAR_CLOCK 1 from mach/clock_types.h +#define CLOCK_MONOTONIC 0 // #define SYSTEM_CLOCK 0 + +typedef int clockid_t; + +// the mach kernel uses struct mach_timespec, so struct timespec is loaded from for compatability +// struct timespec { time_t tv_sec; long tv_nsec; }; + +#include +#include +#include +#include +#include +#undef CPU_STATE_MAX + +#define MT_NANO (+1.0E-9) +#define MT_GIGA UINT64_C(1000000000) + +// TODO create a list of timers, +static double mt_timebase = 0.0; +static uint64_t mt_timestart = 0; + +static int clock_gettime(clockid_t clk_id, struct timespec* tp) +{ + kern_return_t retval = KERN_SUCCESS; + if (clk_id == TIMER_ABSTIME) + { + if (!mt_timestart) + { + // only one timer, initilized on the first call to the TIMER + mach_timebase_info_data_t tb = {0}; + mach_timebase_info(&tb); + mt_timebase = tb.numer; + mt_timebase /= tb.denom; + mt_timestart = mach_absolute_time(); + } + + double diff = (mach_absolute_time() - mt_timestart) * mt_timebase; + tp->tv_sec = diff * MT_NANO; + tp->tv_nsec = diff - (tp->tv_sec * MT_GIGA); + } + else // other clk_ids are mapped to the coresponding mach clock_service + { + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), clk_id, &cclock); + retval = clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + + tp->tv_sec = mts.tv_sec; + tp->tv_nsec = mts.tv_nsec; + } + + return retval; +} #endif @@ -53,22 +114,16 @@ u64 get_timebased_time() { #ifdef _WIN32 LARGE_INTEGER count; - if (!QueryPerformanceCounter(&count)) - { - fmt::throw_exception("Unexpected" HERE); - } + verify(HERE), QueryPerformanceCounter(&count); const u64 time = count.QuadPart; - const u64 freq = g_time_aux_info.perf_freq; + const u64 freq = s_time_aux_info.perf_freq; return time / freq * g_timebase_freq + time % freq * g_timebase_freq / freq; #else struct timespec ts; - if (::clock_gettime(CLOCK_MONOTONIC, &ts)) - { - fmt::throw_exception("System error %d" HERE, errno); - } - + verify(HERE), ::clock_gettime(CLOCK_MONOTONIC, &ts) == 0; + return static_cast(ts.tv_sec) * g_timebase_freq + static_cast(ts.tv_nsec) * g_timebase_freq / 1000000000u; #endif } @@ -80,21 +135,15 @@ u64 get_system_time() { #ifdef _WIN32 LARGE_INTEGER count; - if (!QueryPerformanceCounter(&count)) - { - fmt::throw_exception("Unexpected" HERE); - } + verify(HERE), QueryPerformanceCounter(&count); const u64 time = count.QuadPart; - const u64 freq = g_time_aux_info.perf_freq; + const u64 freq = s_time_aux_info.perf_freq; const u64 result = time / freq * 1000000u + (time % freq) * 1000000u / freq; #else struct timespec ts; - if (::clock_gettime(CLOCK_MONOTONIC, &ts)) - { - fmt::throw_exception("System error %d" HERE, errno); - } + verify(HERE), ::clock_gettime(CLOCK_MONOTONIC, &ts) == 0; const u64 result = static_cast(ts.tv_sec) * 1000000u + static_cast(ts.tv_nsec) / 1000u; #endif @@ -108,7 +157,7 @@ s32 sys_time_get_timezone(vm::ptr timezone, vm::ptr summertime) { sys_time.warning("sys_time_get_timezone(timezone=*0x%x, summertime=*0x%x)", timezone, summertime); - *timezone = 180; + *timezone = 180; *summertime = 0; return CELL_OK; @@ -120,27 +169,21 @@ s32 sys_time_get_current_time(vm::ptr sec, vm::ptr nsec) #ifdef _WIN32 LARGE_INTEGER count; - if (!QueryPerformanceCounter(&count)) - { - fmt::throw_exception("Unexpected" HERE); - } + verify(HERE), QueryPerformanceCounter(&count); // get time difference in nanoseconds - const u64 diff = (count.QuadPart - g_time_aux_info.start_time) * 1000000000u / g_time_aux_info.perf_freq; + const u64 diff = (count.QuadPart - s_time_aux_info.start_time) * 1000000000u / s_time_aux_info.perf_freq; // get time since Epoch in nanoseconds - const u64 time = g_time_aux_info.start_ftime * 100u + diff; + const u64 time = s_time_aux_info.start_ftime * 100u + diff; - *sec = time / 1000000000u; + *sec = time / 1000000000u; *nsec = time % 1000000000u; #else struct timespec ts; - if (::clock_gettime(CLOCK_REALTIME, &ts)) - { - fmt::throw_exception("System error %d" HERE, errno); - } + verify(HERE), ::clock_gettime(CLOCK_REALTIME, &ts) == 0; - *sec = ts.tv_sec; + *sec = ts.tv_sec; *nsec = ts.tv_nsec; #endif diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index 4b897377fe..05dc2ea77b 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -1,8 +1,6 @@ #pragma once #include "Utilities/types.h" -#include "Utilities/Macro.h" -#include "Utilities/Platform.h" #include "Utilities/SharedMutex.h" #include diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 49eda32873..cfbf2f8539 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -162,7 +162,7 @@ namespace vm { std::lock_guard lock(g_reservation_mutex); - const u64 align = 0x80000000ull >> cntlz32(size); + const u64 align = 0x80000000ull >> cntlz32(size, true); if (!size || !addr || size > 4096 || size != align || addr & (align - 1)) { @@ -198,7 +198,7 @@ namespace vm { std::unique_lock lock(g_reservation_mutex); - const u64 align = 0x80000000ull >> cntlz32(size); + const u64 align = 0x80000000ull >> cntlz32(size, true); if (!size || !addr || size > 4096 || size != align || addr & (align - 1)) { @@ -285,7 +285,7 @@ namespace vm { std::unique_lock lock(g_reservation_mutex); - const u64 align = 0x80000000ull >> cntlz32(size); + const u64 align = 0x80000000ull >> cntlz32(size, true); if (!size || !addr || size > 4096 || size != align || addr & (align - 1)) { @@ -582,7 +582,7 @@ namespace vm size = ::align(size, 4096); // Check alignment (it's page allocation, so passing small values there is just silly) - if (align < 4096 || align != (0x80000000u >> cntlz32(align))) + if (align < 4096 || align != (0x80000000u >> cntlz32(align, true))) { fmt::throw_exception("Invalid alignment (size=0x%x, align=0x%x)" HERE, size, align); } diff --git a/rpcs3/Emu/Memory/wait_engine.h b/rpcs3/Emu/Memory/wait_engine.h index a777c90af4..99b2ed7833 100644 --- a/rpcs3/Emu/Memory/wait_engine.h +++ b/rpcs3/Emu/Memory/wait_engine.h @@ -1,7 +1,6 @@ #pragma once #include "Utilities/types.h" -#include "Utilities/Macro.h" class thread_ctrl; diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.cpp b/rpcs3/Emu/RSX/VK/VKHelpers.cpp index 68f1cca34f..2f9bfe4040 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.cpp +++ b/rpcs3/Emu/RSX/VK/VKHelpers.cpp @@ -3,34 +3,44 @@ namespace vk { - context *g_current_vulkan_ctx = nullptr; + context* g_current_vulkan_ctx = nullptr; render_device g_current_renderer; texture g_null_texture; - VkSampler g_null_sampler = nullptr; + VkSampler g_null_sampler = nullptr; VkImageView g_null_image_view = nullptr; - VKAPI_ATTR void *VKAPI_CALL mem_realloc(void *pUserData, void *pOriginal, size_t size, size_t alignment, VkSystemAllocationScope allocationScope) + VKAPI_ATTR void* VKAPI_CALL mem_realloc(void* pUserData, void* pOriginal, size_t size, size_t alignment, VkSystemAllocationScope allocationScope) { - return realloc(pOriginal, size); - } - - VKAPI_ATTR void *VKAPI_CALL mem_alloc(void *pUserData, size_t size, size_t alignment, VkSystemAllocationScope allocationScope) - { -#ifdef _WIN32 - return _aligned_malloc(size, alignment); +#ifdef _MSC_VER + return _aligned_realloc(pOriginal, size, alignment); +#elif _WIN32 + return __mingw_aligned_realloc(pOriginal, size, alignment); #else - return malloc(size); + std::abort(); #endif } - VKAPI_ATTR void VKAPI_CALL mem_free(void *pUserData, void *pMemory) + VKAPI_ATTR void* VKAPI_CALL mem_alloc(void* pUserData, size_t size, size_t alignment, VkSystemAllocationScope allocationScope) { -#ifdef _WIN32 - _aligned_free(pMemory); +#ifdef _MSC_VER + return _aligned_malloc(size, alignment); +#elif _WIN32 + return __mingw_aligned_malloc(size, alignment); #else - free(pMemory); + std::abort(); +#endif + } + + VKAPI_ATTR void VKAPI_CALL mem_free(void* pUserData, void* pMemory) + { +#ifdef _MSC_VER + _aligned_free(pMemory); +#elif _WIN32 + __mingw_aligned_free(pMemory); +#else + std::abort(); #endif } diff --git a/rpcs3/Emu/RSX/gcm_enums.cpp b/rpcs3/Emu/RSX/gcm_enums.cpp index 20814538d5..8cd1aa8f5b 100644 --- a/rpcs3/Emu/RSX/gcm_enums.cpp +++ b/rpcs3/Emu/RSX/gcm_enums.cpp @@ -1,6 +1,5 @@ #include "gcm_enums.h" #include "Utilities/StrFmt.h" -#include "Utilities/Macro.h" rsx::vertex_base_type rsx::to_vertex_base_type(u8 in) { diff --git a/rpcs3/Emu/RSX/rsx_utils.h b/rpcs3/Emu/RSX/rsx_utils.h index 587efc24f4..b6a5be8332 100644 --- a/rpcs3/Emu/RSX/rsx_utils.h +++ b/rpcs3/Emu/RSX/rsx_utils.h @@ -27,7 +27,7 @@ namespace rsx // static inline u32 ceil_log2(u32 value) { - return value <= 1 ? 0 : ::cntlz32((value - 1) << 1) ^ 31; + return value <= 1 ? 0 : ::cntlz32((value - 1) << 1, true) ^ 31; } /* Note: What the ps3 calls swizzling in this case is actually z-ordering / morton ordering of pixels diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index ed3028ba61..7945cf87b0 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -274,7 +274,7 @@ void Emulator::Load() ppu_load_exec(ppu_exec); - fxm::import(PURE_EXPR(Emu.GetCallbacks().get_gs_render())); // TODO: must be created in appropriate sys_rsx syscall + fxm::import(Emu.GetCallbacks().get_gs_render); // TODO: must be created in appropriate sys_rsx syscall } else if (ppu_prx.open(elf_file) == elf_error::ok) { diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index e41b4a23f3..778de05c0d 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -396,10 +396,8 @@ - - diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index d8c20193c0..cebc04f463 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1141,12 +1141,6 @@ Emu\GPU\RSX\Common - - Utilities - - - Utilities - Loader diff --git a/rpcs3/rpcs3.cpp b/rpcs3/rpcs3.cpp index 65505521f0..594f465a71 100644 --- a/rpcs3/rpcs3.cpp +++ b/rpcs3/rpcs3.cpp @@ -71,44 +71,44 @@ Rpcs3App* TheApp; cfg::map_entry()>> g_cfg_kb_handler(cfg::root.io, "Keyboard", { - { "Null", PURE_EXPR(std::make_shared()) }, - { "Basic", PURE_EXPR(std::make_shared()) }, + { "Null", &std::make_shared }, + { "Basic", &std::make_shared }, }); cfg::map_entry()>> g_cfg_mouse_handler(cfg::root.io, "Mouse", { - { "Null", PURE_EXPR(std::make_shared()) }, - { "Basic", PURE_EXPR(std::make_shared()) }, + { "Null", &std::make_shared }, + { "Basic", &std::make_shared }, }); cfg::map_entry()>> g_cfg_pad_handler(cfg::root.io, "Pad", "Keyboard", { - { "Null", PURE_EXPR(std::make_shared()) }, - { "Keyboard", PURE_EXPR(std::make_shared()) }, + { "Null", &std::make_shared }, + { "Keyboard", &std::make_shared }, #ifdef _MSC_VER - { "XInput", PURE_EXPR(std::make_shared()) }, + { "XInput", &std::make_shared }, #endif }); cfg::map_entry()>> g_cfg_gs_render(cfg::root.video, "Renderer", "OpenGL", { - { "Null", PURE_EXPR(std::make_shared()) }, - { "OpenGL", PURE_EXPR(std::make_shared()) }, + { "Null", &std::make_shared }, + { "OpenGL", &std::make_shared }, #ifdef _MSC_VER - { "D3D12", PURE_EXPR(std::make_shared()) }, + { "D3D12", &std::make_shared }, #endif #ifdef _WIN32 - { "Vulkan", PURE_EXPR(std::make_shared()) }, + { "Vulkan", &std::make_shared }, #endif }); cfg::map_entry()>> g_cfg_audio_render(cfg::root.audio, "Renderer", 1, { - { "Null", PURE_EXPR(std::make_shared()) }, + { "Null", &std::make_shared }, #ifdef _WIN32 - { "XAudio2", PURE_EXPR(std::make_shared()) }, + { "XAudio2", &std::make_shared }, #endif - { "OpenAL", PURE_EXPR(std::make_shared()) }, + { "OpenAL", &std::make_shared }, }); extern cfg::bool_entry g_cfg_autostart; @@ -159,11 +159,11 @@ bool Rpcs3App::OnInit() wxGetApp().SendDbgCommand(id, t); }; - callbacks.get_kb_handler = PURE_EXPR(g_cfg_kb_handler.get()()); + callbacks.get_kb_handler = []{ return g_cfg_kb_handler.get()(); }; - callbacks.get_mouse_handler = PURE_EXPR(g_cfg_mouse_handler.get()()); + callbacks.get_mouse_handler = []{ return g_cfg_mouse_handler.get()(); }; - callbacks.get_pad_handler = PURE_EXPR(g_cfg_pad_handler.get()()); + callbacks.get_pad_handler = []{ return g_cfg_pad_handler.get()(); }; callbacks.get_gs_frame = [](frame_type type, int w, int h) -> std::unique_ptr { @@ -178,9 +178,9 @@ bool Rpcs3App::OnInit() fmt::throw_exception("Invalid frame type (0x%x)" HERE, (int)type); }; - callbacks.get_gs_render = PURE_EXPR(g_cfg_gs_render.get()()); + callbacks.get_gs_render = []{ return g_cfg_gs_render.get()(); }; - callbacks.get_audio = PURE_EXPR(g_cfg_audio_render.get()()); + callbacks.get_audio = []{ return g_cfg_audio_render.get()(); }; callbacks.get_msg_dialog = []() -> std::shared_ptr { diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index ae1b7277f5..764bd4d7b8 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -19,11 +19,23 @@ #pragma warning( disable : 4351 ) +// MSVC bug workaround +#ifdef _MSC_VER +namespace std { inline namespace literals { inline namespace chrono_literals {}}} +#endif + +#include "Utilities/types.h" +#include "Utilities/BEType.h" +#include "Utilities/Atomic.h" +#include "Utilities/StrFmt.h" +#include "Utilities/File.h" +#include "Utilities/Log.h" + #include -#include -#include #include +#include #include +#include #include #include #include @@ -31,18 +43,4 @@ #include #include -// MSVC bug workaround -#ifdef _MSC_VER -namespace std { inline namespace literals { inline namespace chrono_literals {}}} -#endif - using namespace std::literals; - -#include "Utilities/types.h" -#include "Utilities/Macro.h" -#include "Utilities/Platform.h" -#include "Utilities/BEType.h" -#include "Utilities/Atomic.h" -#include "Utilities/StrFmt.h" -#include "Utilities/File.h" -#include "Utilities/Log.h"