Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx: Refactor rsx_decode.h and bugfixes #6168

Merged
merged 3 commits into from Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions Utilities/BitField.h
@@ -1,6 +1,7 @@
#pragma once

#include "types.h"
#include <limits>

template<typename T, uint N>
struct bf_base
Expand All @@ -15,11 +16,11 @@ struct bf_base
// Field bitsize
static constexpr uint bitsize = N;

// Value mask
static constexpr utype vmask = static_cast<utype>(~utype{} >> (bitmax - bitsize));

// All ones mask
static constexpr utype mask1 = static_cast<utype>(~utype{});
static constexpr utype mask1 = std::numeric_limits<utype>::max();

// Value mask
static constexpr utype vmask = mask1 >> (bitmax - bitsize);

protected:
type m_data;
Expand Down
2 changes: 1 addition & 1 deletion Utilities/StrFmt.h
Expand Up @@ -62,7 +62,7 @@ struct fmt_unveil<T, std::enable_if_t<std::is_floating_point<T>::value && sizeof
// Convert FP to f64 and reinterpret as u64
static inline u64 get(const f64& arg)
{
return *reinterpret_cast<const u64*>(reinterpret_cast<const u8*>(&arg));
return std::bit_cast<u64>(arg);
}
};

Expand Down
21 changes: 12 additions & 9 deletions Utilities/cfmt.h
Expand Up @@ -412,9 +412,10 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src)
}

const u64 mask =
ctx.type == 1 ? 0xffull :
ctx.type == 2 ? 0xffffull :
ctx.type == 4 ? 0xffffffffull : 0xffffffffffffffffull;
ctx.type == 1 ? u64{std::numeric_limits<get_int_t<1>>::max()} :
ctx.type == 2 ? u64{std::numeric_limits<get_int_t<2>>::max()} :
ctx.type == 4 ? u64{std::numeric_limits<get_int_t<4>>::max()} :
u64{std::numeric_limits<get_int_t<8>>::max()};

// Trunc sign-extended signed types
const u64 val = src.template get<u64>(ctx.args) & mask;
Expand Down Expand Up @@ -468,9 +469,10 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src)
}

const u64 mask =
ctx.type == 1 ? 0xffull :
ctx.type == 2 ? 0xffffull :
ctx.type == 4 ? 0xffffffffull : 0xffffffffffffffffull;
ctx.type == 1 ? u64{std::numeric_limits<get_int_t<1>>::max()} :
ctx.type == 2 ? u64{std::numeric_limits<get_int_t<2>>::max()} :
ctx.type == 4 ? u64{std::numeric_limits<get_int_t<4>>::max()} :
u64{std::numeric_limits<get_int_t<8>>::max()};

// Trunc sign-extended signed types
const u64 val = src.template get<u64>(ctx.args) & mask;
Expand Down Expand Up @@ -531,9 +533,10 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src)
}

const u64 mask =
ctx.type == 1 ? 0xffull :
ctx.type == 2 ? 0xffffull :
ctx.type == 4 ? 0xffffffffull : 0xffffffffffffffffull;
ctx.type == 1 ? u64{std::numeric_limits<get_int_t<1>>::max()} :
ctx.type == 2 ? u64{std::numeric_limits<get_int_t<2>>::max()} :
ctx.type == 4 ? u64{std::numeric_limits<get_int_t<4>>::max()} :
u64{std::numeric_limits<get_int_t<8>>::max()};

// Trunc sign-extended signed types
const u64 val = src.template get<u64>(ctx.args) & mask;
Expand Down
64 changes: 64 additions & 0 deletions Utilities/types.h
Expand Up @@ -131,6 +131,39 @@ using steady_clock = std::conditional<
std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;

// Get unsigned integral type from type size
template<size_t N>
struct get_int_impl
{
};

template<>
struct get_int_impl<sizeof(u8)>
{
using type = u8;
};

template<>
struct get_int_impl<sizeof(u16)>
{
using type = u16;
};

template<>
struct get_int_impl<sizeof(u32)>
{
using type = u32;
};

template<>
struct get_int_impl<sizeof(u64)>
{
using type = u64;
};

template <size_t N>
using get_int_t = typename get_int_impl<N>::type;

namespace gsl
{
using std::byte;
Expand Down Expand Up @@ -855,3 +888,34 @@ inline void busy_wait(std::size_t cycles = 3000)
const u64 s = __rdtsc();
do _mm_pause(); while (__rdtsc() - s < cycles);
}

// TODO: Remove when moving to c++20
template <typename T>
inline constexpr uintmax_t floor2(T value)
{
value >>= 1;

for (uintmax_t i = 0;; i++, value >>= 1)
{
if (value == 0)
{
return i;
}
}
}

template <typename T>
inline constexpr uintmax_t ceil2(T value)
{
const uintmax_t ispow2 = value & (value - 1); // if power of 2 the result is 0

value >>= 1;

for (uintmax_t i = 0;; i++, value >>= 1)
{
if (value == 0)
{
return i + std::min<uintmax_t>(ispow2, 1);
}
}
}
12 changes: 6 additions & 6 deletions rpcs3/Emu/Cell/Modules/cellSpurs.cpp
Expand Up @@ -765,7 +765,7 @@ void _spurs::event_helper_entry(ppu_thread& ppu, vm::ptr<CellSpurs> spurs)

s32 _spurs::create_event_helper(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 ppuPriority)
{
if (s32 rc = _spurs::create_lv2_eq(ppu, spurs, spurs.ptr(&CellSpurs::eventQueue), spurs.ptr(&CellSpurs::spuPort), 0x2A, sys_event_queue_attribute_t{ SYS_SYNC_PRIORITY, SYS_PPU_QUEUE, "_spuPrv" }))
if (s32 rc = _spurs::create_lv2_eq(ppu, spurs, spurs.ptr(&CellSpurs::eventQueue), spurs.ptr(&CellSpurs::spuPort), 0x2A, sys_event_queue_attribute_t{ SYS_SYNC_PRIORITY, SYS_PPU_QUEUE, "_spuPrv\0"_u64 }))
{
return rc;
}
Expand Down Expand Up @@ -1014,7 +1014,7 @@ s32 _spurs::initialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 revision,
semAttr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
semAttr->ipc_key = 0;
semAttr->flags = 0;
std::memcpy(semAttr->name, "_spuWkl", 8);
semAttr->name_u64 = "_spuWkl\0"_u64;

for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
Expand All @@ -1037,7 +1037,7 @@ s32 _spurs::initialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 revision,
}

// Create semaphore
std::memcpy(semAttr->name, "_spuPrv", 8);
semAttr->name_u64 = "_spuPrv\0"_u64;
if (s32 rc = sys_semaphore_create(sem, semAttr, 0, 1))
{
return rollback(), rc;
Expand Down Expand Up @@ -1142,14 +1142,14 @@ s32 _spurs::initialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 revision,
const auto lwCond = spurs.ptr(&CellSpurs::cond);

// Create a mutex to protect access to SPURS handler thread data
if (s32 rc = sys_lwmutex_create(ppu, lwMutex, vm::make_var(sys_lwmutex_attribute_t{ SYS_SYNC_PRIORITY, SYS_SYNC_NOT_RECURSIVE, "_spuPrv" })))
if (s32 rc = sys_lwmutex_create(ppu, lwMutex, vm::make_var(sys_lwmutex_attribute_t{ SYS_SYNC_PRIORITY, SYS_SYNC_NOT_RECURSIVE, "_spuPrv\0"_u64 })))
{
_spurs::finalize_spu(ppu, spurs);
return rollback(), rc;
}

// Create condition variable to signal the SPURS handler thread
if (s32 rc = sys_lwcond_create(ppu, lwCond, lwMutex, vm::make_var(sys_lwcond_attribute_t{ "_spuPrv" })))
if (s32 rc = sys_lwcond_create(ppu, lwCond, lwMutex, vm::make_var(sys_lwcond_attribute_t{ "_spuPrv\0"_u64 })))
{
sys_lwmutex_destroy(ppu, lwMutex);
_spurs::finalize_spu(ppu, spurs);
Expand Down Expand Up @@ -3046,7 +3046,7 @@ s32 cellSpursEventFlagAttachLv2EventQueue(ppu_thread& ppu, vm::ptr<CellSpursEven
return (rc & 0x0FFF0000) == 0x00410000 ? rc : (0x80410900 | (rc & 0xFF));
};

if (s32 rc = _spurs::create_lv2_eq(ppu, spurs, eventQueueId, port, 1, sys_event_queue_attribute_t{ SYS_SYNC_PRIORITY, SYS_PPU_QUEUE, "_spuEvF" }))
if (s32 rc = _spurs::create_lv2_eq(ppu, spurs, eventQueueId, port, 1, sys_event_queue_attribute_t{ SYS_SYNC_PRIORITY, SYS_PPU_QUEUE, "_spuEvF\0"_u64 }))
{
return failure(rc);
}
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_cond.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "sys_sync.h"
#include "sys_mutex.h"
Expand All @@ -13,8 +13,8 @@ struct sys_cond_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_event.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "sys_sync.h"

Expand Down Expand Up @@ -59,8 +59,8 @@ struct sys_event_queue_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_event_flag.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "sys_sync.h"

Expand Down Expand Up @@ -26,8 +26,8 @@ struct sys_event_flag_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_lwcond.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "sys_sync.h"

Expand All @@ -10,8 +10,8 @@ struct sys_lwcond_attribute_t
{
union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_lwmutex.h
Expand Up @@ -11,8 +11,8 @@ struct sys_lwmutex_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_mutex.h
Expand Up @@ -16,8 +16,8 @@ struct sys_mutex_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_rwlock.h
Expand Up @@ -14,8 +14,8 @@ struct sys_rwlock_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_semaphore.h
Expand Up @@ -14,8 +14,8 @@ struct sys_semaphore_attribute_t

union
{
char name[8];
u64 name_u64;
le_t<u64> name_u64;
char name[sizeof(u64)];
};
};

Expand Down