mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-13 02:08:49 +12:00
Remove any_pod<> from types.h
Add simplified any32 to GCM.h Add simplified cmd64 to PPUThread.h
This commit is contained in:
parent
6e05dcadb6
commit
b09b7c1184
4 changed files with 80 additions and 105 deletions
|
@ -884,94 +884,6 @@ struct value_hash
|
|||
}
|
||||
};
|
||||
|
||||
// Contains value of any POD type with fixed size and alignment. TT<> is the type converter applied.
|
||||
// For example, `simple_t` may be used to remove endianness.
|
||||
template <template <typename> class TT, std::size_t S, std::size_t A = S>
|
||||
struct alignas(A) any_pod
|
||||
{
|
||||
alignas(A) std::byte data[S];
|
||||
|
||||
any_pod() = default;
|
||||
|
||||
template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_trivially_copyable_v<T> && sizeof(T2) == S && alignof(T2) <= A>>
|
||||
any_pod(const T& value)
|
||||
{
|
||||
*this = std::bit_cast<any_pod>(value);
|
||||
}
|
||||
|
||||
template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_trivially_copyable_v<T> && sizeof(T2) == S && alignof(T2) <= A>>
|
||||
T2& as()
|
||||
{
|
||||
return reinterpret_cast<T2&>(data);
|
||||
}
|
||||
|
||||
template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_trivially_copyable_v<T> && sizeof(T2) == S && alignof(T2) <= A>>
|
||||
const T2& as() const
|
||||
{
|
||||
return reinterpret_cast<const T2&>(data);
|
||||
}
|
||||
};
|
||||
|
||||
using any16 = any_pod<simple_t, sizeof(u16)>;
|
||||
using any32 = any_pod<simple_t, sizeof(u32)>;
|
||||
using any64 = any_pod<simple_t, sizeof(u64)>;
|
||||
|
||||
struct cmd64 : any64
|
||||
{
|
||||
struct pair_t
|
||||
{
|
||||
any32 arg1;
|
||||
any32 arg2;
|
||||
};
|
||||
|
||||
cmd64() = default;
|
||||
|
||||
template <typename T>
|
||||
cmd64(const T& value)
|
||||
: any64(value)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
cmd64(const T1& arg1, const T2& arg2)
|
||||
: any64(pair_t{arg1, arg2})
|
||||
{
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return as<u64>() != 0;
|
||||
}
|
||||
|
||||
// TODO: compatibility with std::pair/std::tuple?
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) arg1()
|
||||
{
|
||||
return as<pair_t>().arg1.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) arg1() const
|
||||
{
|
||||
return as<const pair_t>().arg1.as<const T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) arg2()
|
||||
{
|
||||
return as<pair_t>().arg2.as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) arg2() const
|
||||
{
|
||||
return as<const pair_t>().arg2.as<const T>();
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(cmd64) == 8 && std::is_trivially_copyable_v<cmd64>, "Incorrect cmd64 type");
|
||||
|
||||
// Error code type (return type), implements error reporting. Could be a template.
|
||||
class error_code
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue