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>
|
2015-07-15 13:58:13 +02:00
|
|
|
#include <list>
|
|
|
|
|
#include <forward_list>
|
2015-08-06 15:05:33 +02:00
|
|
|
#include <typeindex>
|
2015-09-13 00:37:57 +02:00
|
|
|
#include <future>
|
2013-11-19 11:30:58 +01:00
|
|
|
|
2015-08-21 13:07:31 +02:00
|
|
|
using namespace std::string_literals;
|
2015-09-13 00:37:57 +02:00
|
|
|
using namespace std::chrono_literals;
|
2015-08-21 13:07:31 +02:00
|
|
|
|
2014-08-22 23:31:39 +02:00
|
|
|
#include "Utilities/GNU.h"
|
|
|
|
|
|
2015-07-26 02:53:26 +02:00
|
|
|
#define CHECK_SIZE(type, size) static_assert(sizeof(type) == size, "Invalid " #type " type size")
|
2015-09-13 00:37:57 +02:00
|
|
|
#define CHECK_ALIGN(type, align) static_assert(alignof(type) == align, "Invalid " #type " type alignment")
|
2015-07-26 02:53:26 +02:00
|
|
|
#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-08-21 13:07:31 +02:00
|
|
|
#define CHECK_ASCENDING(constexpr_array) static_assert(::is_ascending(constexpr_array), #constexpr_array " is not sorted in ascending order")
|
2015-07-26 02:53:26 +02:00
|
|
|
|
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-06-21 01:04:01 +02:00
|
|
|
using f32 = float;
|
|
|
|
|
using f64 = double;
|
|
|
|
|
|
2015-08-06 22:20:48 +02:00
|
|
|
using u128 = __uint128_t;
|
|
|
|
|
|
|
|
|
|
CHECK_SIZE_ALIGN(u128, 16, 16);
|
|
|
|
|
|
2015-07-26 02:53:26 +02:00
|
|
|
// bool type replacement for PS3/PSV
|
|
|
|
|
class b8
|
|
|
|
|
{
|
|
|
|
|
std::uint8_t m_value;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
b8(const bool value)
|
|
|
|
|
: m_value(value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator bool() const //template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>> operator T() const
|
|
|
|
|
{
|
|
|
|
|
return m_value != 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CHECK_SIZE_ALIGN(b8, 1, 1);
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
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-08-21 13:07:31 +02:00
|
|
|
// returns true if all array elements are unique and sorted in ascending order
|
|
|
|
|
template<typename T, std::size_t N> constexpr bool is_ascending(const T(&array)[N], std::size_t from = 0)
|
|
|
|
|
{
|
|
|
|
|
return from >= N - 1 ? true : array[from] < array[from + 1] ? is_ascending(array, from + 1) : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get (first) array element equal to `value` or nullptr if not found
|
|
|
|
|
template<typename T, std::size_t N, typename T2> constexpr const T* static_search(const T(&array)[N], const T2& value, std::size_t from = 0)
|
|
|
|
|
{
|
|
|
|
|
return from >= N ? nullptr : array[from] == value ? array + from : static_search(array, value, from + 1);
|
|
|
|
|
}
|
|
|
|
|
|
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-08-21 13:07:31 +02:00
|
|
|
template<typename T1, typename T2, typename T3 = const char*> struct triplet_t
|
|
|
|
|
{
|
|
|
|
|
T1 first;
|
|
|
|
|
T2 second;
|
|
|
|
|
T3 third;
|
|
|
|
|
|
|
|
|
|
constexpr bool operator ==(const T1& right) const
|
|
|
|
|
{
|
|
|
|
|
return first == right;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-21 01:04:01 +02:00
|
|
|
// return 32 bit sizeof() to avoid widening/narrowing conversions with size_t
|
2015-07-26 14:10:06 +02:00
|
|
|
#define sizeof32(type) static_cast<u32>(sizeof(type))
|
2015-06-21 01:04:01 +02:00
|
|
|
|
2015-06-21 16:48:21 +02:00
|
|
|
// return 32 bit alignof() to avoid widening/narrowing conversions with size_t
|
2015-09-13 00:37:57 +02:00
|
|
|
#define alignof32(type) static_cast<u32>(alignof(type))
|
2015-03-02 22:09:20 +01:00
|
|
|
|
2015-07-09 21:55:50 +02:00
|
|
|
#define WRAP_EXPR(expr) [&]{ return expr; }
|
|
|
|
|
#define COPY_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-09-18 00:41:14 +02:00
|
|
|
#define IS_INTEGRAL(t) (std::is_integral<t>::value || std::is_same<std::decay_t<t>, u128>::value)
|
|
|
|
|
#define IS_INTEGER(t) (std::is_integral<t>::value || std::is_enum<t>::value || std::is_same<std::decay_t<t>, u128>::value)
|
|
|
|
|
#define IS_BINARY_COMPARABLE(t1, t2) (IS_INTEGER(t1) && IS_INTEGER(t2) && sizeof(t1) == sizeof(t2))
|
2015-06-26 01:26:23 +02:00
|
|
|
|
2015-08-11 18:14:53 +02:00
|
|
|
template<typename T> struct id_traits;
|
|
|
|
|
|
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"
|
2015-09-18 00:41:14 +02:00
|
|
|
#include "Utilities/Atomic.h"
|
2015-06-21 16:48:21 +02:00
|
|
|
#include "Utilities/StrFmt.h"
|