2012-11-15 00:39:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2014-04-15 16:12:15 +02:00
|
|
|
#ifdef MSVC_CRT_MEMLEAK_DETECTION
|
|
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <crtdbg.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
#define NOMINMAX
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-07-10 22:54:12 +02:00
|
|
|
#if defined(MSVC_CRT_MEMLEAK_DETECTION) && defined(_DEBUG) && !defined(DBG_NEW)
|
|
|
|
|
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
|
2014-09-07 09:49:25 +02:00
|
|
|
#include "define_new_memleakdetect.h"
|
2014-07-10 22:54:12 +02:00
|
|
|
#endif
|
2014-04-15 16:12:15 +02:00
|
|
|
|
2015-07-01 00:25:52 +02:00
|
|
|
#pragma warning( disable : 4351 )
|
2015-01-25 17:23:24 +01:00
|
|
|
|
2014-07-08 18:26:31 +02:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <cassert>
|
2013-11-19 11:30:58 +01:00
|
|
|
#include <cstdint>
|
2015-06-19 18:53:52 +02:00
|
|
|
#include <climits>
|
2014-08-28 18:29:05 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <condition_variable>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
2015-03-04 05:42:04 +01:00
|
|
|
#include <queue>
|
2014-08-28 18:29:05 +02:00
|
|
|
#include <set>
|
2014-09-16 15:56:27 +02:00
|
|
|
#include <array>
|
2014-08-28 18:29:05 +02:00
|
|
|
#include <string>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <algorithm>
|
2014-09-15 16:33:06 +02:00
|
|
|
#include <random>
|
2014-11-04 20:31:20 +01:00
|
|
|
#include <unordered_set>
|
2015-01-29 15:50:34 +01:00
|
|
|
#include <map>
|
|
|
|
|
#include <unordered_map>
|
2013-11-19 11:30:58 +01:00
|
|
|
|
2014-08-22 23:31:39 +02:00
|
|
|
#include "Utilities/GNU.h"
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
using uint = unsigned int;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
using u8 = std::uint8_t;
|
|
|
|
|
using u16 = std::uint16_t;
|
|
|
|
|
using u32 = std::uint32_t;
|
|
|
|
|
using u64 = std::uint64_t;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
using s8 = std::int8_t;
|
|
|
|
|
using s16 = std::int16_t;
|
|
|
|
|
using s32 = std::int32_t;
|
|
|
|
|
using s64 = std::int64_t;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2015-07-01 00:25:52 +02:00
|
|
|
using b8 = std::uint8_t;
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
using f32 = float;
|
|
|
|
|
using f64 = double;
|
|
|
|
|
|
|
|
|
|
template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>> inline T align(const T& value, u64 align)
|
2014-11-19 15:16:30 +01:00
|
|
|
{
|
2015-06-21 01:04:01 +02:00
|
|
|
return static_cast<T>((value + (align - 1)) & ~(align - 1));
|
2014-11-19 15:16:30 +01:00
|
|
|
}
|
2014-08-22 23:15:02 +02:00
|
|
|
|
2015-07-06 01:21:15 +02:00
|
|
|
// copy null-terminated string from std::string to char array with truncation
|
|
|
|
|
template<std::size_t N> inline void strcpy_trunc(char(&dst)[N], const std::string& src)
|
|
|
|
|
{
|
|
|
|
|
const std::size_t count = src.size() >= N ? N - 1 : src.size();
|
|
|
|
|
std::memcpy(dst, src.c_str(), count);
|
|
|
|
|
dst[count] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy null-terminated string from char array to char array with truncation
|
|
|
|
|
template<std::size_t N, std::size_t N2> inline void strcpy_trunc(char(&dst)[N], const char(&src)[N2])
|
|
|
|
|
{
|
|
|
|
|
const std::size_t count = N2 >= N ? N - 1 : N2;
|
|
|
|
|
std::memcpy(dst, src, count);
|
|
|
|
|
dst[count] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 02:03:11 +02:00
|
|
|
// bool wrapper for restricting bool result conversions
|
|
|
|
|
struct explicit_bool_t
|
|
|
|
|
{
|
|
|
|
|
const bool value;
|
|
|
|
|
|
|
|
|
|
explicit_bool_t(bool value)
|
|
|
|
|
: value(value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
explicit operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
// return 32 bit sizeof() to avoid widening/narrowing conversions with size_t
|
|
|
|
|
#define sizeof32(type) sizeof32_t<sizeof(type)>::value
|
|
|
|
|
|
2015-06-21 16:48:21 +02:00
|
|
|
// return 32 bit alignof() to avoid widening/narrowing conversions with size_t
|
|
|
|
|
#define alignof32(type) alignof32_t<__alignof(type)>::value
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
template<std::size_t Size> struct sizeof32_t
|
2015-06-14 23:52:22 +02:00
|
|
|
{
|
2015-06-21 16:48:21 +02:00
|
|
|
static_assert(Size <= UINT32_MAX, "sizeof32() error: size is too big");
|
2015-06-14 23:52:22 +02:00
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
static const u32 value = static_cast<u32>(Size);
|
2015-06-14 23:52:22 +02:00
|
|
|
};
|
|
|
|
|
|
2015-06-21 16:48:21 +02:00
|
|
|
template<std::size_t Align> struct alignof32_t
|
|
|
|
|
{
|
|
|
|
|
static_assert(Align <= UINT32_MAX, "alignof32() error: alignment is too big");
|
2015-06-13 16:48:21 +02:00
|
|
|
|
2015-06-21 16:48:21 +02:00
|
|
|
static const u32 value = static_cast<u32>(Align);
|
|
|
|
|
};
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2015-06-21 16:48:21 +02:00
|
|
|
template<typename T> using func_def = T; // workaround for MSVC bug: `using X = func_def<void()>;` instead of `using X = void();`
|
2015-03-02 22:09:20 +01:00
|
|
|
|
2015-05-27 05:11:59 +02:00
|
|
|
template<typename T> struct ID_type;
|
|
|
|
|
|
|
|
|
|
#define REG_ID_TYPE(t, id) template<> struct ID_type<t> { static const u32 type = id; }
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
#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)
|
|
|
|
|
|
2015-06-26 01:26:23 +02:00
|
|
|
#define WRAP_EXPR(expr) [&]{ return (expr); }
|
2015-07-01 00:25:52 +02:00
|
|
|
#define EXCEPTION(text, ...) fmt::exception(__FILE__, __LINE__, __FUNCTION__, text, ##__VA_ARGS__)
|
2015-07-03 01:11:44 +02:00
|
|
|
#define VM_CAST(value) vm::impl_cast(value, __FILE__, __LINE__, __FUNCTION__)
|
2015-06-26 01:26:23 +02:00
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
#define _PRGNAME_ "RPCS3"
|
2014-07-24 02:54:08 +02:00
|
|
|
#define _PRGVER_ "0.0.0.5"
|
2015-06-21 16:48:21 +02:00
|
|
|
|
|
|
|
|
#include "Utilities/BEType.h"
|
|
|
|
|
#include "Utilities/StrFmt.h"
|
|
|
|
|
#include "Emu/Memory/atomic.h"
|