1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +01:00

Silly macro removed-2

This commit is contained in:
Nekotekina 2016-08-14 03:22:19 +03:00
parent 5e0489dcc0
commit 0f87c4485d
38 changed files with 346 additions and 445 deletions

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "types.h" #include "types.h"
#include "Platform.h"
// Helper class, provides access to compiler-specific atomic intrinsics // Helper class, provides access to compiler-specific atomic intrinsics
template<typename T, std::size_t Size> template<typename T, std::size_t Size>

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "types.h" #include "types.h"
#include "Platform.h"
// 128-bit vector type and also se_storage<> storage type // 128-bit vector type and also se_storage<> storage type
union alignas(16) v128 union alignas(16) v128
@ -353,7 +352,10 @@ struct se_storage
static type copy(const type& src) static type copy(const type& src)
{ {
type result; type result;
std::memcpy(&result, &src, Size); for (std::size_t i = 0; i < Size; i++)
{
reinterpret_cast<u8*>(&result)[i] = reinterpret_cast<const u8*>(&src)[i];
}
return result; return result;
} }
}; };

View File

@ -9,7 +9,7 @@ struct bf_base
using vtype = simple_t<type>; using vtype = simple_t<type>;
// Datatype bitsize // 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 // Field bitsize
static constexpr uint bitsize = N; static constexpr uint bitsize = N;

View File

@ -1,6 +1,5 @@
#include "File.h" #include "File.h"
#include "StrFmt.h" #include "StrFmt.h"
#include "Macro.h"
#include "SharedMutex.h" #include "SharedMutex.h"
#include "BEType.h" #include "BEType.h"
#include "Crypto/sha1.h" #include "Crypto/sha1.h"
@ -22,10 +21,7 @@ static std::unique_ptr<wchar_t[]> to_wchar(const std::string& source)
std::unique_ptr<wchar_t[]> buffer(new wchar_t[buf_size]); // allocate buffer assuming that length is the max possible size std::unique_ptr<wchar_t[]> 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)) verify("to_wchar" HERE), MultiByteToWideChar(CP_UTF8, 0, source.c_str(), size, buffer.get(), size);
{
fmt::throw_exception("to_wchar(): MultiByteToWideChar() failed: error %u.", GetLastError());
}
return buffer; 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 result.resize(buf_size); // set max possible length for utf-8 + null terminator
if (const int nwritten = WideCharToMultiByte(CP_UTF8, 0, source, static_cast<int>(length) + 1, &result.front(), buf_size, NULL, NULL)) const int nwritten = verify(WideCharToMultiByte(CP_UTF8, 0, source, static_cast<int>(length) + 1, &result.front(), buf_size, NULL, NULL), "to_utf8" HERE);
{
result.resize(nwritten - 1); // fix the size, remove null terminator // fix the size, remove null terminator
} result.resize(nwritten - 1);
else
{
fmt::throw_exception("to_utf8(): WideCharToMultiByte() failed: error %u.", GetLastError());
}
} }
static time_t to_time(const ULARGE_INTEGER& ft) static time_t to_time(const ULARGE_INTEGER& ft)
@ -692,10 +684,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
stat_t stat() override stat_t stat() override
{ {
FILE_BASIC_INFO basic_info; FILE_BASIC_INFO basic_info;
if (!GetFileInformationByHandleEx(m_handle, FileBasicInfo, &basic_info, sizeof(FILE_BASIC_INFO))) verify("file::stat" HERE), GetFileInformationByHandleEx(m_handle, FileBasicInfo, &basic_info, sizeof(FILE_BASIC_INFO));
{
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
}
stat_t info; stat_t info;
info.is_directory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; info.is_directory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
@ -726,14 +715,8 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
return false; return false;
} }
const BOOL result = SetEndOfFile(m_handle); // change file size verify("file::trunc" HERE), SetEndOfFile(m_handle), SetFilePointerEx(m_handle, old, NULL, FILE_BEGIN);
return true;
if (!result || !SetFilePointerEx(m_handle, old, NULL, FILE_BEGIN)) // restore position
{
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
}
return result != FALSE;
} }
u64 read(void* buffer, u64 count) override u64 read(void* buffer, u64 count) override
@ -743,10 +726,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
EXPECTS(size >= 0); EXPECTS(size >= 0);
DWORD nread; DWORD nread;
if (!ReadFile(m_handle, buffer, size, &nread, NULL)) verify("file::read" HERE), ReadFile(m_handle, buffer, size, &nread, NULL);
{
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
}
return nread; return nread;
} }
@ -758,10 +738,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
EXPECTS(size >= 0); EXPECTS(size >= 0);
DWORD nwritten; DWORD nwritten;
if (!WriteFile(m_handle, buffer, size, &nwritten, NULL)) verify("file::write" HERE), WriteFile(m_handle, buffer, size, &nwritten, NULL);
{
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
}
return nwritten; return nwritten;
} }
@ -777,10 +754,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
whence == seek_end ? FILE_END : whence == seek_end ? FILE_END :
(fmt::throw_exception("Invalid whence (0x%x)" HERE, whence), 0); (fmt::throw_exception("Invalid whence (0x%x)" HERE, whence), 0);
if (!SetFilePointerEx(m_handle, pos, &pos, mode)) verify("file::seek" HERE), SetFilePointerEx(m_handle, pos, &pos, mode);
{
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
}
return pos.QuadPart; return pos.QuadPart;
} }
@ -788,10 +762,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
u64 size() override u64 size() override
{ {
LARGE_INTEGER size; LARGE_INTEGER size;
if (!GetFileSizeEx(m_handle, &size)) verify("file::size" HERE), GetFileSizeEx(m_handle, &size);
{
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
}
return size.QuadPart; return size.QuadPart;
} }
@ -836,10 +807,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
stat_t stat() override stat_t stat() override
{ {
struct ::stat file_info; struct ::stat file_info;
if (::fstat(m_fd, &file_info) != 0) verify("file::stat" HERE), ::fstat(m_fd, &file_info) == 0;
{
fmt::throw_exception("System error: %d." HERE, errno);
}
stat_t info; stat_t info;
info.is_directory = S_ISDIR(file_info.st_mode); info.is_directory = S_ISDIR(file_info.st_mode);
@ -866,10 +834,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
u64 read(void* buffer, u64 count) override u64 read(void* buffer, u64 count) override
{ {
const auto result = ::read(m_fd, buffer, count); const auto result = ::read(m_fd, buffer, count);
if (result == -1) verify("file::read" HERE), result != -1;
{
fmt::throw_exception("System error: %d." HERE, errno);
}
return result; return result;
} }
@ -877,10 +842,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
u64 write(const void* buffer, u64 count) override u64 write(const void* buffer, u64 count) override
{ {
const auto result = ::write(m_fd, buffer, count); const auto result = ::write(m_fd, buffer, count);
if (result == -1) verify("file::write" HERE), result != -1;
{
fmt::throw_exception("System error: %d." HERE, errno);
}
return result; return result;
} }
@ -894,10 +856,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
(fmt::throw_exception("Invalid whence (0x%x)" HERE, whence), 0); (fmt::throw_exception("Invalid whence (0x%x)" HERE, whence), 0);
const auto result = ::lseek(m_fd, offset, mode); const auto result = ::lseek(m_fd, offset, mode);
if (result == -1) verify("file::seek" HERE), result != -1;
{
fmt::throw_exception("System error: %d." HERE, errno);
}
return result; return result;
} }
@ -905,10 +864,7 @@ bool fs::file::open(const std::string& path, bs_t<open_mode> mode)
u64 size() override u64 size() override
{ {
struct ::stat file_info; struct ::stat file_info;
if (::fstat(m_fd, &file_info) != 0) verify("file::size" HERE), ::fstat(m_fd, &file_info) == 0;
{
fmt::throw_exception("System error: %d." HERE, errno);
}
return file_info.st_size; return file_info.st_size;
} }
@ -1048,12 +1004,8 @@ bool fs::dir::open(const std::string& path)
WIN32_FIND_DATAW found; WIN32_FIND_DATAW found;
if (!FindNextFileW(m_handle, &found)) if (!FindNextFileW(m_handle, &found))
{ {
if (ERROR_NO_MORE_FILES == GetLastError()) verify("dir::read" HERE), ERROR_NO_MORE_FILES == GetLastError();
{ return false;
return false;
}
fmt::throw_exception("Win32 error: %u." HERE, GetLastError());
} }
add_entry(found); add_entry(found);
@ -1103,10 +1055,7 @@ bool fs::dir::open(const std::string& path)
} }
struct ::stat file_info; struct ::stat file_info;
if (::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) != 0) verify("dir::read" HERE), ::fstatat(::dirfd(m_dd), found->d_name, &file_info, 0) == 0;
{
fmt::throw_exception("System error: %d." HERE, errno);
}
info.name = found->d_name; info.name = found->d_name;
info.is_directory = S_ISDIR(file_info.st_mode); info.is_directory = S_ISDIR(file_info.st_mode);

View File

@ -1,12 +1,11 @@
#pragma once #pragma once
#include "types.h"
#include "bit_set.h"
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <type_traits>
#include "types.h"
#include "bit_set.h"
namespace fs namespace fs
{ {

View File

@ -7,7 +7,6 @@
#include <array> #include <array>
#include "types.h" #include "types.h"
#include "Macro.h"
#include "StrFmt.h" #include "StrFmt.h"
#include "File.h" #include "File.h"
#include "Log.h" #include "Log.h"

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "types.h" #include "types.h"
#include "Platform.h"
#include "Atomic.h" #include "Atomic.h"
#include "StrFmt.h" #include "StrFmt.h"

View File

@ -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<std::uint32_t>(sizeof(type))
// Return 32 bit alignof() to avoid widening/narrowing conversions with size_t
#define ALIGN_32(type) static_cast<std::uint32_t>(alignof(type))
// Return 32 bit custom offsetof()
#define OFFSET_32(type, x) static_cast<std::uint32_t>(reinterpret_cast<std::uintptr_t>(&reinterpret_cast<const volatile char&>(reinterpret_cast<type*>(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

View File

@ -1,51 +0,0 @@
#include "Platform.h"
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/_types/_timespec.h>
#include <mach/mach.h>
#include <mach/clock.h>
#include <mach/mach_time.h>
#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__ */

View File

@ -1,128 +0,0 @@
#pragma once
#include <cstdint>
#include <immintrin.h>
#include <emmintrin.h>
#define IS_LE_MACHINE 1
#define IS_BE_MACHINE 0
#ifdef _MSC_VER
#include <intrin.h>
#else
#include <x86intrin.h>
#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 <stdlib.h>
#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 <sys/_types/_timespec.h> 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<std::uint8_t>(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<std::uint64_t>(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
}

View File

@ -2,7 +2,6 @@
#include "types.h" #include "types.h"
#include "Atomic.h" #include "Atomic.h"
#include "Platform.h"
// Binary semaphore // Binary semaphore
class benaphore class benaphore

View File

@ -2,7 +2,6 @@
#include "types.h" #include "types.h"
#include "Atomic.h" #include "Atomic.h"
#include "Platform.h"
//! An attempt to create effective implementation of "shared mutex", lock-free in optimistic case. //! 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. //! All locking and unlocking may be done by a single LOCK XADD or LOCK CMPXCHG instruction.

View File

@ -1,11 +1,16 @@
#include "StrFmt.h" #include "StrFmt.h"
#include "BEType.h" #include "BEType.h"
#include "StrUtil.h" #include "StrUtil.h"
#include "Macro.h"
#include "cfmt.h" #include "cfmt.h"
#include <algorithm> #include <algorithm>
#ifdef _WIN32
#include <Windows.h>
#else
#include <errno.h>
#endif
void fmt_class_string<const void*>::format(std::string& out, u64 arg) void fmt_class_string<const void*>::format(std::string& out, u64 arg)
{ {
fmt::append(out, "%p", reinterpret_cast<const void*>(static_cast<std::uintptr_t>(arg))); fmt::append(out, "%p", reinterpret_cast<const void*>(static_cast<std::uintptr_t>(arg)));
@ -124,18 +129,26 @@ namespace fmt
{ {
void raw_error(const char* msg) void raw_error(const char* msg)
{ {
std::string out{"Error"}; throw std::runtime_error{msg};
out += ": ";
out += msg;
throw std::runtime_error{out};
} }
void raw_verify_error(const char* msg, uint position) void raw_verify_error(const char* msg, uint position)
{ {
std::string out{"Verification failed"}; 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) if (position)
{ {
out += " (+"; out += " (+";

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include <exception>
#include <string>
#include "Platform.h"
#include "types.h" #include "types.h"
#include <exception>
#include <stdexcept>
#include <string>
namespace fmt namespace fmt
{ {
template <typename... Args> template <typename... Args>

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include "types.h"
#include "Atomic.h"
#include <exception> #include <exception>
#include <string> #include <string>
#include <memory> #include <memory>
#include "Platform.h"
#include "Atomic.h"
// Will report exception and call std::abort() if put in catch(...) // Will report exception and call std::abort() if put in catch(...)
[[noreturn]] void catch_all_exceptions(); [[noreturn]] void catch_all_exceptions();

View File

@ -59,7 +59,7 @@ struct bs_base
__bitset_set_type = 0 // SFINAE marker __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<under>(T::__bitset_enum_max); static constexpr std::size_t bitsize = static_cast<under>(T::__bitset_enum_max);
static_assert(std::is_enum<T>::value, "bs_t<> error: invalid type (must be enum)"); static_assert(std::is_enum<T>::value, "bs_t<> error: invalid type (must be enum)");

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "types.h" #include "types.h"
#include <climits>
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@ -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) const auto write_octal = [&](u64 value, u64 min_num)
{ {
out.resize(out.size() + std::max<u64>(min_num, 66 / 3 - (cntlz64(value | 1) + 2) / 3), '0'); out.resize(out.size() + std::max<u64>(min_num, 66 / 3 - (cntlz64(value | 1, true) + 2) / 3), '0');
// Write in reversed order // Write in reversed order
for (auto i = out.rbegin(); value; i++, value /= 8) 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) const auto write_hex = [&](u64 value, bool upper, u64 min_num)
{ {
out.resize(out.size() + std::max<u64>(min_num, 64 / 4 - cntlz64(value | 1) / 4), '0'); out.resize(out.size() + std::max<u64>(min_num, 64 / 4 - cntlz64(value | 1, true) / 4), '0');
// Write in reversed order // Write in reversed order
for (auto i = out.rbegin(); value; i++, value /= 16) for (auto i = out.rbegin(); value; i++, value /= 16)

View File

@ -2,7 +2,6 @@
#include "types.h" #include "types.h"
#include "Atomic.h" #include "Atomic.h"
#include "Platform.h"
//! Simple sizeless array base for concurrent access. Cannot shrink, only growths automatically. //! 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. //! There is no way to know the current size. The smaller index is, the faster it's accessed.

View File

@ -3,7 +3,6 @@
/* For internal use. Don't include. */ /* For internal use. Don't include. */
#include "types.h" #include "types.h"
#include "Macro.h"
#include "Atomic.h" #include "Atomic.h"
#ifdef _WIN32 #ifdef _WIN32

View File

@ -1,8 +1,77 @@
#pragma once #pragma once
#ifdef _MSC_VER
#include <intrin.h>
#else
#include <x86intrin.h>
#endif
#include <immintrin.h>
#include <emmintrin.h>
#include <cstdint> #include <cstdint>
#include <climits>
#include <type_traits> #include <type_traits>
#include <utility>
// 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<u32>(sizeof(__VA_ARGS__))
// Return 32 bit alignof() to avoid widening/narrowing conversions with size_t
#define ALIGN_32(...) static_cast<u32>(alignof(__VA_ARGS__))
// Return 32 bit offsetof()
#define OFFSET_32(type, x) static_cast<u32>(reinterpret_cast<std::uintptr_t>(&reinterpret_cast<const volatile char&>(reinterpret_cast<type*>(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 schar = signed char;
using uchar = unsigned char; using uchar = unsigned char;
@ -159,8 +228,6 @@ using u128 = __uint128_t;
using s128 = __int128_t; using s128 = __int128_t;
#else #else
#include "intrin.h"
// Unsigned 128-bit integer implementation (TODO) // Unsigned 128-bit integer implementation (TODO)
struct alignas(16) u128 struct alignas(16) u128
{ {
@ -342,8 +409,8 @@ struct alignas(16) s128
}; };
#endif #endif
static_assert(alignof(u128) == 16 && sizeof(u128) == 16, "Wrong u128 implementation"); CHECK_SIZE_ALIGN(u128, 16, 16);
static_assert(alignof(s128) == 16 && sizeof(s128) == 16, "Wrong s128 implementation"); CHECK_SIZE_ALIGN(s128, 16, 16);
union alignas(2) f16 union alignas(2) f16
{ {
@ -366,6 +433,8 @@ union alignas(2) f16
} }
}; };
CHECK_SIZE_ALIGN(f16, 2, 2);
using f32 = float; using f32 = float;
using f64 = double; using f64 = double;
@ -383,6 +452,59 @@ constexpr T align(const T& value, std::uint64_t align)
return static_cast<T>((value + (align - 1)) & ~(align - 1)); return static_cast<T>((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<std::uint8_t>(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<std::uint64_t>(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 namespace fmt
{ {
[[noreturn]] void raw_error(const char* msg); [[noreturn]] void raw_error(const char* msg);

View File

@ -15,7 +15,7 @@ s32 cellKbInit(u32 max_connect)
if (max_connect > 7) if (max_connect > 7)
return CELL_KB_ERROR_INVALID_PARAMETER; return CELL_KB_ERROR_INVALID_PARAMETER;
const auto handler = fxm::import<KeyboardHandlerBase>(PURE_EXPR(Emu.GetCallbacks().get_kb_handler())); const auto handler = fxm::import<KeyboardHandlerBase>(Emu.GetCallbacks().get_kb_handler);
if (!handler) if (!handler)
return CELL_KB_ERROR_ALREADY_INITIALIZED; return CELL_KB_ERROR_ALREADY_INITIALIZED;

View File

@ -17,7 +17,7 @@ s32 cellMouseInit(u32 max_connect)
return CELL_MOUSE_ERROR_INVALID_PARAMETER; return CELL_MOUSE_ERROR_INVALID_PARAMETER;
} }
const auto handler = fxm::import<MouseHandlerBase>(PURE_EXPR(Emu.GetCallbacks().get_mouse_handler())); const auto handler = fxm::import<MouseHandlerBase>(Emu.GetCallbacks().get_mouse_handler);
if (!handler) if (!handler)
{ {

View File

@ -61,7 +61,7 @@ s32 cellMsgDialogOpen2(u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialog
default: return CELL_MSGDIALOG_ERROR_PARAM; default: return CELL_MSGDIALOG_ERROR_PARAM;
} }
const auto dlg = fxm::import<MsgDialogBase>(PURE_EXPR(Emu.GetCallbacks().get_msg_dialog())); const auto dlg = fxm::import<MsgDialogBase>(Emu.GetCallbacks().get_msg_dialog);
if (!dlg) if (!dlg)
{ {
@ -294,7 +294,10 @@ s32 cellMsgDialogProgressBarReset(u32 progressBarIndex)
return CELL_MSGDIALOG_ERROR_PARAM; return CELL_MSGDIALOG_ERROR_PARAM;
} }
Emu.CallAfter(COPY_EXPR(dlg->ProgressBarReset(progressBarIndex))); Emu.CallAfter([=]
{
dlg->ProgressBarReset(progressBarIndex);
});
return CELL_OK; return CELL_OK;
} }
@ -315,7 +318,10 @@ s32 cellMsgDialogProgressBarInc(u32 progressBarIndex, u32 delta)
return CELL_MSGDIALOG_ERROR_PARAM; return CELL_MSGDIALOG_ERROR_PARAM;
} }
Emu.CallAfter(COPY_EXPR(dlg->ProgressBarInc(progressBarIndex, delta))); Emu.CallAfter([=]
{
dlg->ProgressBarInc(progressBarIndex, delta);
});
return CELL_OK; return CELL_OK;
} }

View File

@ -15,7 +15,7 @@ s32 cellPadInit(u32 max_connect)
if (max_connect > CELL_PAD_MAX_PORT_NUM) if (max_connect > CELL_PAD_MAX_PORT_NUM)
return CELL_PAD_ERROR_INVALID_PARAMETER; return CELL_PAD_ERROR_INVALID_PARAMETER;
const auto handler = fxm::import<PadHandlerBase>(PURE_EXPR(Emu.GetCallbacks().get_pad_handler())); const auto handler = fxm::import<PadHandlerBase>(Emu.GetCallbacks().get_pad_handler);
if (!handler) if (!handler)
return CELL_PAD_ERROR_ALREADY_INITIALIZED; return CELL_PAD_ERROR_ALREADY_INITIALIZED;

View File

@ -23,7 +23,6 @@
#include "../Utilities/types.h" #include "../Utilities/types.h"
#include "../Utilities/StrFmt.h" #include "../Utilities/StrFmt.h"
#include "../Utilities/Macro.h"
#include "../Utilities/BEType.h" #include "../Utilities/BEType.h"
template<typename T, typename = void> template<typename T, typename = void>

View File

@ -1359,7 +1359,7 @@ inline float ldexpf_extended(float x, int exp) // ldexpf() for extended values,
inline bool isdenormal(float x) inline bool isdenormal(float x)
{ {
const int fpc = _fpclass(x); const int fpc = std::fpclassify(x);
#ifdef __GNUG__ #ifdef __GNUG__
return fpc == FP_SUBNORMAL; return fpc == FP_SUBNORMAL;
#else #else
@ -1369,7 +1369,7 @@ inline bool isdenormal(float x)
inline bool isdenormal(double x) inline bool isdenormal(double x)
{ {
const int fpc = _fpclass(x); const int fpc = std::fpclassify(x);
#ifdef __GNUG__ #ifdef __GNUG__
return fpc == FP_SUBNORMAL; return fpc == FP_SUBNORMAL;
#else #else

View File

@ -14,14 +14,16 @@ struct time_aux_info_t
u64 perf_freq; u64 perf_freq;
u64 start_time; u64 start_time;
u64 start_ftime; // time in 100ns units since Epoch 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; LARGE_INTEGER freq;
if (!QueryPerformanceFrequency(&freq)) if (!QueryPerformanceFrequency(&freq))
{ {
MessageBox(0, L"Your hardware doesn't support a high-resolution performance counter", L"Error", MB_OK | MB_ICONERROR); MessageBox(0, L"Your hardware doesn't support a high-resolution performance counter", L"Error", MB_OK | MB_ICONERROR);
return{}; return {};
} }
LARGE_INTEGER start; 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) GetSystemTimeAsFileTime(&ftime); // get time in 100ns units since January 1, 1601 (UTC)
time_aux_info_t result; time_aux_info_t result;
result.perf_freq = freq.QuadPart; result.perf_freq = freq.QuadPart;
result.start_time = start.QuadPart; result.start_time = start.QuadPart;
result.start_ftime = (ftime.dwLowDateTime | (u64)ftime.dwHighDateTime << 32) - 116444736000000000; result.start_ftime = (ftime.dwLowDateTime | (u64)ftime.dwHighDateTime << 32) - 116444736000000000;
return result; 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 <sys/_types/_timespec.h> for compatability
// struct timespec { time_t tv_sec; long tv_nsec; };
#include <sys/types.h>
#include <sys/_types/_timespec.h>
#include <mach/mach.h>
#include <mach/clock.h>
#include <mach/mach_time.h>
#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 #endif
@ -53,22 +114,16 @@ u64 get_timebased_time()
{ {
#ifdef _WIN32 #ifdef _WIN32
LARGE_INTEGER count; LARGE_INTEGER count;
if (!QueryPerformanceCounter(&count)) verify(HERE), QueryPerformanceCounter(&count);
{
fmt::throw_exception("Unexpected" HERE);
}
const u64 time = count.QuadPart; 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; return time / freq * g_timebase_freq + time % freq * g_timebase_freq / freq;
#else #else
struct timespec ts; struct timespec ts;
if (::clock_gettime(CLOCK_MONOTONIC, &ts)) verify(HERE), ::clock_gettime(CLOCK_MONOTONIC, &ts) == 0;
{
fmt::throw_exception("System error %d" HERE, errno);
}
return static_cast<u64>(ts.tv_sec) * g_timebase_freq + static_cast<u64>(ts.tv_nsec) * g_timebase_freq / 1000000000u; return static_cast<u64>(ts.tv_sec) * g_timebase_freq + static_cast<u64>(ts.tv_nsec) * g_timebase_freq / 1000000000u;
#endif #endif
} }
@ -80,21 +135,15 @@ u64 get_system_time()
{ {
#ifdef _WIN32 #ifdef _WIN32
LARGE_INTEGER count; LARGE_INTEGER count;
if (!QueryPerformanceCounter(&count)) verify(HERE), QueryPerformanceCounter(&count);
{
fmt::throw_exception("Unexpected" HERE);
}
const u64 time = count.QuadPart; 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; const u64 result = time / freq * 1000000u + (time % freq) * 1000000u / freq;
#else #else
struct timespec ts; struct timespec ts;
if (::clock_gettime(CLOCK_MONOTONIC, &ts)) verify(HERE), ::clock_gettime(CLOCK_MONOTONIC, &ts) == 0;
{
fmt::throw_exception("System error %d" HERE, errno);
}
const u64 result = static_cast<u64>(ts.tv_sec) * 1000000u + static_cast<u64>(ts.tv_nsec) / 1000u; const u64 result = static_cast<u64>(ts.tv_sec) * 1000000u + static_cast<u64>(ts.tv_nsec) / 1000u;
#endif #endif
@ -108,7 +157,7 @@ s32 sys_time_get_timezone(vm::ptr<s32> timezone, vm::ptr<s32> summertime)
{ {
sys_time.warning("sys_time_get_timezone(timezone=*0x%x, summertime=*0x%x)", timezone, summertime); sys_time.warning("sys_time_get_timezone(timezone=*0x%x, summertime=*0x%x)", timezone, summertime);
*timezone = 180; *timezone = 180;
*summertime = 0; *summertime = 0;
return CELL_OK; return CELL_OK;
@ -120,27 +169,21 @@ s32 sys_time_get_current_time(vm::ptr<s64> sec, vm::ptr<s64> nsec)
#ifdef _WIN32 #ifdef _WIN32
LARGE_INTEGER count; LARGE_INTEGER count;
if (!QueryPerformanceCounter(&count)) verify(HERE), QueryPerformanceCounter(&count);
{
fmt::throw_exception("Unexpected" HERE);
}
// get time difference in nanoseconds // 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 // 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; *nsec = time % 1000000000u;
#else #else
struct timespec ts; struct timespec ts;
if (::clock_gettime(CLOCK_REALTIME, &ts)) verify(HERE), ::clock_gettime(CLOCK_REALTIME, &ts) == 0;
{
fmt::throw_exception("System error %d" HERE, errno);
}
*sec = ts.tv_sec; *sec = ts.tv_sec;
*nsec = ts.tv_nsec; *nsec = ts.tv_nsec;
#endif #endif

View File

@ -1,8 +1,6 @@
#pragma once #pragma once
#include "Utilities/types.h" #include "Utilities/types.h"
#include "Utilities/Macro.h"
#include "Utilities/Platform.h"
#include "Utilities/SharedMutex.h" #include "Utilities/SharedMutex.h"
#include <memory> #include <memory>

View File

@ -162,7 +162,7 @@ namespace vm
{ {
std::lock_guard<reservation_mutex_t> lock(g_reservation_mutex); std::lock_guard<reservation_mutex_t> 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)) if (!size || !addr || size > 4096 || size != align || addr & (align - 1))
{ {
@ -198,7 +198,7 @@ namespace vm
{ {
std::unique_lock<reservation_mutex_t> lock(g_reservation_mutex); std::unique_lock<reservation_mutex_t> 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)) if (!size || !addr || size > 4096 || size != align || addr & (align - 1))
{ {
@ -285,7 +285,7 @@ namespace vm
{ {
std::unique_lock<reservation_mutex_t> lock(g_reservation_mutex); std::unique_lock<reservation_mutex_t> 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)) if (!size || !addr || size > 4096 || size != align || addr & (align - 1))
{ {
@ -582,7 +582,7 @@ namespace vm
size = ::align(size, 4096); size = ::align(size, 4096);
// Check alignment (it's page allocation, so passing small values there is just silly) // 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); fmt::throw_exception("Invalid alignment (size=0x%x, align=0x%x)" HERE, size, align);
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "Utilities/types.h" #include "Utilities/types.h"
#include "Utilities/Macro.h"
class thread_ctrl; class thread_ctrl;

View File

@ -3,34 +3,44 @@
namespace vk namespace vk
{ {
context *g_current_vulkan_ctx = nullptr; context* g_current_vulkan_ctx = nullptr;
render_device g_current_renderer; render_device g_current_renderer;
texture g_null_texture; texture g_null_texture;
VkSampler g_null_sampler = nullptr; VkSampler g_null_sampler = nullptr;
VkImageView g_null_image_view = 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); #ifdef _MSC_VER
} return _aligned_realloc(pOriginal, size, alignment);
#elif _WIN32
VKAPI_ATTR void *VKAPI_CALL mem_alloc(void *pUserData, size_t size, size_t alignment, VkSystemAllocationScope allocationScope) return __mingw_aligned_realloc(pOriginal, size, alignment);
{
#ifdef _WIN32
return _aligned_malloc(size, alignment);
#else #else
return malloc(size); std::abort();
#endif #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 #ifdef _MSC_VER
_aligned_free(pMemory); return _aligned_malloc(size, alignment);
#elif _WIN32
return __mingw_aligned_malloc(size, alignment);
#else #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 #endif
} }

View File

@ -1,6 +1,5 @@
#include "gcm_enums.h" #include "gcm_enums.h"
#include "Utilities/StrFmt.h" #include "Utilities/StrFmt.h"
#include "Utilities/Macro.h"
rsx::vertex_base_type rsx::to_vertex_base_type(u8 in) rsx::vertex_base_type rsx::to_vertex_base_type(u8 in)
{ {

View File

@ -27,7 +27,7 @@ namespace rsx
// //
static inline u32 ceil_log2(u32 value) 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 /* Note: What the ps3 calls swizzling in this case is actually z-ordering / morton ordering of pixels

View File

@ -274,7 +274,7 @@ void Emulator::Load()
ppu_load_exec(ppu_exec); ppu_load_exec(ppu_exec);
fxm::import<GSRender>(PURE_EXPR(Emu.GetCallbacks().get_gs_render())); // TODO: must be created in appropriate sys_rsx syscall fxm::import<GSRender>(Emu.GetCallbacks().get_gs_render); // TODO: must be created in appropriate sys_rsx syscall
} }
else if (ppu_prx.open(elf_file) == elf_error::ok) else if (ppu_prx.open(elf_file) == elf_error::ok)
{ {

View File

@ -396,10 +396,8 @@
<ClInclude Include="..\Utilities\lockless.h" /> <ClInclude Include="..\Utilities\lockless.h" />
<ClInclude Include="..\Utilities\SleepQueue.h" /> <ClInclude Include="..\Utilities\SleepQueue.h" />
<ClInclude Include="..\Utilities\sync.h" /> <ClInclude Include="..\Utilities\sync.h" />
<ClInclude Include="..\Utilities\Platform.h" />
<ClInclude Include="..\Utilities\Log.h" /> <ClInclude Include="..\Utilities\Log.h" />
<ClInclude Include="..\Utilities\File.h" /> <ClInclude Include="..\Utilities\File.h" />
<ClInclude Include="..\Utilities\Macro.h" />
<ClInclude Include="..\Utilities\Config.h" /> <ClInclude Include="..\Utilities\Config.h" />
<ClInclude Include="..\Utilities\rXml.h" /> <ClInclude Include="..\Utilities\rXml.h" />
<ClInclude Include="..\Utilities\Semaphore.h" /> <ClInclude Include="..\Utilities\Semaphore.h" />

View File

@ -1141,12 +1141,6 @@
<ClInclude Include="Emu\RSX\Common\ring_buffer_helper.h"> <ClInclude Include="Emu\RSX\Common\ring_buffer_helper.h">
<Filter>Emu\GPU\RSX\Common</Filter> <Filter>Emu\GPU\RSX\Common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Utilities\Macro.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\Platform.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="Loader\ELF.h"> <ClInclude Include="Loader\ELF.h">
<Filter>Loader</Filter> <Filter>Loader</Filter>
</ClInclude> </ClInclude>

View File

@ -71,44 +71,44 @@ Rpcs3App* TheApp;
cfg::map_entry<std::function<std::shared_ptr<KeyboardHandlerBase>()>> g_cfg_kb_handler(cfg::root.io, "Keyboard", cfg::map_entry<std::function<std::shared_ptr<KeyboardHandlerBase>()>> g_cfg_kb_handler(cfg::root.io, "Keyboard",
{ {
{ "Null", PURE_EXPR(std::make_shared<NullKeyboardHandler>()) }, { "Null", &std::make_shared<NullKeyboardHandler> },
{ "Basic", PURE_EXPR(std::make_shared<BasicKeyboardHandler>()) }, { "Basic", &std::make_shared<BasicKeyboardHandler> },
}); });
cfg::map_entry<std::function<std::shared_ptr<MouseHandlerBase>()>> g_cfg_mouse_handler(cfg::root.io, "Mouse", cfg::map_entry<std::function<std::shared_ptr<MouseHandlerBase>()>> g_cfg_mouse_handler(cfg::root.io, "Mouse",
{ {
{ "Null", PURE_EXPR(std::make_shared<NullMouseHandler>()) }, { "Null", &std::make_shared<NullMouseHandler> },
{ "Basic", PURE_EXPR(std::make_shared<BasicMouseHandler>()) }, { "Basic", &std::make_shared<BasicMouseHandler> },
}); });
cfg::map_entry<std::function<std::shared_ptr<PadHandlerBase>()>> g_cfg_pad_handler(cfg::root.io, "Pad", "Keyboard", cfg::map_entry<std::function<std::shared_ptr<PadHandlerBase>()>> g_cfg_pad_handler(cfg::root.io, "Pad", "Keyboard",
{ {
{ "Null", PURE_EXPR(std::make_shared<NullPadHandler>()) }, { "Null", &std::make_shared<NullPadHandler> },
{ "Keyboard", PURE_EXPR(std::make_shared<KeyboardPadHandler>()) }, { "Keyboard", &std::make_shared<KeyboardPadHandler> },
#ifdef _MSC_VER #ifdef _MSC_VER
{ "XInput", PURE_EXPR(std::make_shared<XInputPadHandler>()) }, { "XInput", &std::make_shared<XInputPadHandler> },
#endif #endif
}); });
cfg::map_entry<std::function<std::shared_ptr<GSRender>()>> g_cfg_gs_render(cfg::root.video, "Renderer", "OpenGL", cfg::map_entry<std::function<std::shared_ptr<GSRender>()>> g_cfg_gs_render(cfg::root.video, "Renderer", "OpenGL",
{ {
{ "Null", PURE_EXPR(std::make_shared<NullGSRender>()) }, { "Null", &std::make_shared<NullGSRender> },
{ "OpenGL", PURE_EXPR(std::make_shared<GLGSRender>()) }, { "OpenGL", &std::make_shared<GLGSRender> },
#ifdef _MSC_VER #ifdef _MSC_VER
{ "D3D12", PURE_EXPR(std::make_shared<D3D12GSRender>()) }, { "D3D12", &std::make_shared<D3D12GSRender> },
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
{ "Vulkan", PURE_EXPR(std::make_shared<VKGSRender>()) }, { "Vulkan", &std::make_shared<VKGSRender> },
#endif #endif
}); });
cfg::map_entry<std::function<std::shared_ptr<AudioThread>()>> g_cfg_audio_render(cfg::root.audio, "Renderer", 1, cfg::map_entry<std::function<std::shared_ptr<AudioThread>()>> g_cfg_audio_render(cfg::root.audio, "Renderer", 1,
{ {
{ "Null", PURE_EXPR(std::make_shared<NullAudioThread>()) }, { "Null", &std::make_shared<NullAudioThread> },
#ifdef _WIN32 #ifdef _WIN32
{ "XAudio2", PURE_EXPR(std::make_shared<XAudio2Thread>()) }, { "XAudio2", &std::make_shared<XAudio2Thread> },
#endif #endif
{ "OpenAL", PURE_EXPR(std::make_shared<OpenALThread>()) }, { "OpenAL", &std::make_shared<OpenALThread> },
}); });
extern cfg::bool_entry g_cfg_autostart; extern cfg::bool_entry g_cfg_autostart;
@ -159,11 +159,11 @@ bool Rpcs3App::OnInit()
wxGetApp().SendDbgCommand(id, t); 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<GSFrameBase> callbacks.get_gs_frame = [](frame_type type, int w, int h) -> std::unique_ptr<GSFrameBase>
{ {
@ -178,9 +178,9 @@ bool Rpcs3App::OnInit()
fmt::throw_exception("Invalid frame type (0x%x)" HERE, (int)type); 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<MsgDialogBase> callbacks.get_msg_dialog = []() -> std::shared_ptr<MsgDialogBase>
{ {

View File

@ -19,11 +19,23 @@
#pragma warning( disable : 4351 ) #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 <cstdlib> #include <cstdlib>
#include <cstdint>
#include <climits>
#include <cstring> #include <cstring>
#include <climits>
#include <exception> #include <exception>
#include <stdexcept>
#include <string> #include <string>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -31,18 +43,4 @@
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
// MSVC bug workaround
#ifdef _MSC_VER
namespace std { inline namespace literals { inline namespace chrono_literals {}}}
#endif
using namespace std::literals; 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"