1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

Remove any_pod<> from types.h

Add simplified any32 to GCM.h
Add simplified cmd64 to PPUThread.h
This commit is contained in:
Nekotekina 2020-12-12 13:12:39 +03:00
parent 6e05dcadb6
commit b09b7c1184
4 changed files with 80 additions and 105 deletions

View File

@ -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. // Error code type (return type), implements error reporting. Could be a template.
class error_code class error_code
{ {

View File

@ -33,6 +33,28 @@ void fmt_class_string<CellGcmError>::format(std::string& out, u64 arg)
}); });
} }
namespace rsx
{
u32 make_command(vm::bptr<u32>& dst, u32 start_register, std::initializer_list<any32> values)
{
*dst++ = start_register << 2 | static_cast<u32>(values.size()) << 18;
for (const any32& cmd : values)
{
*dst++ = cmd.as<u32>();
}
return u32{sizeof(u32)} * (static_cast<u32>(values.size()) + 1);
}
u32 make_jump(vm::bptr<u32>& dst, u32 offset)
{
*dst++ = RSX_METHOD_OLD_JUMP_CMD | offset;
return sizeof(u32);
}
}
extern s32 cellGcmCallback(ppu_thread& ppu, vm::ptr<CellGcmContextData> context, u32 count); extern s32 cellGcmCallback(ppu_thread& ppu, vm::ptr<CellGcmContextData> context, u32 count);
const u32 tiled_pitches[] = { const u32 tiled_pitches[] = {

View File

@ -59,6 +59,54 @@ struct ppu_thread_params
u64 arg1; u64 arg1;
}; };
struct cmd64
{
u64 m_data = 0;
constexpr cmd64() noexcept = default;
struct pair_t
{
u32 arg1;
u32 arg2;
};
template <typename T, typename T2 = simple_t<T>>
cmd64(const T& value)
: m_data(std::bit_cast<u64, T2>(value))
{
}
template <typename T1, typename T2>
cmd64(const T1& arg1, const T2& arg2)
: cmd64(pair_t{std::bit_cast<u32>(arg1), std::bit_cast<u32>(arg2)})
{
}
explicit operator bool() const
{
return m_data != 0;
}
template <typename T>
T as() const
{
return std::bit_cast<T>(m_data);
}
template <typename T>
T arg1() const
{
return std::bit_cast<T>(std::bit_cast<pair_t>(m_data).arg1);
}
template <typename T>
T arg2() const
{
return std::bit_cast<T>(std::bit_cast<pair_t>(m_data).arg2);
}
};
class ppu_thread : public cpu_thread class ppu_thread : public cpu_thread
{ {
public: public:

View File

@ -151,26 +151,19 @@ struct GcmTileInfo
} }
}; };
namespace rsx struct any32
{ {
template<typename AT> u32 m_data;
static inline u32 make_command(vm::_ptr_base<be_t<u32>, AT>& dst, u32 start_register, std::initializer_list<any32> values)
{
*dst++ = start_register << 2 | static_cast<u32>(values.size()) << 18;
for (const any32& cmd : values) template <typename T, typename T2 = simple_t<T>>
any32(const T& value)
: m_data(std::bit_cast<u32, T2>(value))
{ {
*dst++ = cmd.as<u32>();
} }
return u32{sizeof(u32)} * (static_cast<u32>(values.size()) + 1); template <typename T>
} T as() const
template<typename AT>
static inline u32 make_jump(vm::_ptr_base<be_t<u32>, AT>& dst, u32 offset)
{ {
*dst++ = RSX_METHOD_OLD_JUMP_CMD | offset; return std::bit_cast<T>(m_data);
return sizeof(u32);
} }
} };