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

[WIP] Reimplement vm::ref to replace vm::ptr #12988

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellL10n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ s32 UTF8toBIG5()

s32 UTF16stoUTF8s(vm::cptr<u16> utf16, vm::ref<s32> utf16_len, vm::ptr<u8> utf8, vm::ref<s32> utf8_len)
{
cellL10n.error("UTF16stoUTF8s(utf16=*0x%x, utf16_len=*0x%x, utf8=*0x%x, utf8_len=*0x%x)", utf16, utf16_len.addr(), utf8, utf8_len.addr());
cellL10n.error("UTF16stoUTF8s(utf16=*0x%x, utf16_len=*0x%x, utf8=*0x%x, utf8_len=*0x%x)", utf16, utf16_len, utf8, utf8_len);

const u32 max_len = utf8_len; utf8_len = 0;

Expand Down
58 changes: 30 additions & 28 deletions rpcs3/Emu/Cell/Modules/cellSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void fmt_class_string<CellSyncError>::format(std::string& out, u64 arg)
});
}

error_code cellSyncMutexInitialize(vm::ptr<CellSyncMutex> mutex)
error_code cellSyncMutexInitialize(vm::ref<CellSyncMutex> mutex)
{
cellSync.trace("cellSyncMutexInitialize(mutex=*0x%x)", mutex);

if (!mutex) [[unlikely]]
if (!mutex.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -52,16 +52,16 @@ error_code cellSyncMutexInitialize(vm::ptr<CellSyncMutex> mutex)
return CELL_SYNC_ERROR_ALIGN;
}

mutex->ctrl.exchange({0, 0});
mutex.ref(&CellSyncMutex::ctrl).exchange({0, 0});

return CELL_OK;
}

error_code cellSyncMutexLock(ppu_thread& ppu, vm::ptr<CellSyncMutex> mutex)
error_code cellSyncMutexLock(ppu_thread& ppu, vm::ref<CellSyncMutex> mutex)
{
cellSync.trace("cellSyncMutexLock(mutex=*0x%x)", mutex);

if (!mutex) [[unlikely]]
if (!mutex.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -71,11 +71,13 @@ error_code cellSyncMutexLock(ppu_thread& ppu, vm::ptr<CellSyncMutex> mutex)
return CELL_SYNC_ERROR_ALIGN;
}

const vm::Ref auto ctrl = mutex.ref(&CellSyncMutex::ctrl);

// Increase acq value and remember its old value
const auto order = mutex->ctrl.atomic_op(&CellSyncMutex::Counter::lock_begin);
const auto order = ctrl.atomic_op(&CellSyncMutex::Counter::lock_begin);

// Wait until rel value is equal to old acq value
while (mutex->ctrl.load().rel != order)
while (ctrl.load().rel != order)
{
if (ppu.test_stopped())
{
Expand All @@ -87,11 +89,11 @@ error_code cellSyncMutexLock(ppu_thread& ppu, vm::ptr<CellSyncMutex> mutex)
return CELL_OK;
}

error_code cellSyncMutexTryLock(vm::ptr<CellSyncMutex> mutex)
error_code cellSyncMutexTryLock(vm::ref<CellSyncMutex> mutex)
{
cellSync.trace("cellSyncMutexTryLock(mutex=*0x%x)", mutex);

if (!mutex) [[unlikely]]
if (!mutex.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -101,19 +103,19 @@ error_code cellSyncMutexTryLock(vm::ptr<CellSyncMutex> mutex)
return CELL_SYNC_ERROR_ALIGN;
}

if (!mutex->ctrl.atomic_op(&CellSyncMutex::Counter::try_lock))
if (!mutex.ref(&CellSyncMutex::ctrl).atomic_op(&CellSyncMutex::Counter::try_lock))
{
return not_an_error(CELL_SYNC_ERROR_BUSY);
}

return CELL_OK;
}

error_code cellSyncMutexUnlock(vm::ptr<CellSyncMutex> mutex)
error_code cellSyncMutexUnlock(vm::ref<CellSyncMutex> mutex)
{
cellSync.trace("cellSyncMutexUnlock(mutex=*0x%x)", mutex);

if (!mutex) [[unlikely]]
if (!mutex.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -123,16 +125,16 @@ error_code cellSyncMutexUnlock(vm::ptr<CellSyncMutex> mutex)
return CELL_SYNC_ERROR_ALIGN;
}

mutex->ctrl.atomic_op(&CellSyncMutex::Counter::unlock);
mutex.ref(&CellSyncMutex::ctrl).atomic_op(&CellSyncMutex::Counter::unlock);

return CELL_OK;
}

error_code cellSyncBarrierInitialize(vm::ptr<CellSyncBarrier> barrier, u16 total_count)
error_code cellSyncBarrierInitialize(vm::ref<CellSyncBarrier> barrier, u16 total_count)
{
cellSync.trace("cellSyncBarrierInitialize(barrier=*0x%x, total_count=%d)", barrier, total_count);

if (!barrier) [[unlikely]]
if (!barrier.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -148,16 +150,16 @@ error_code cellSyncBarrierInitialize(vm::ptr<CellSyncBarrier> barrier, u16 total
}

// clear current value, write total_count and sync
barrier->ctrl.exchange({0, total_count});
barrier.ref(&CellSyncBarrier::ctrl).exchange({0, total_count});

return CELL_OK;
}

error_code cellSyncBarrierNotify(ppu_thread& ppu, vm::ptr<CellSyncBarrier> barrier)
error_code cellSyncBarrierNotify(ppu_thread& ppu, vm::ref<CellSyncBarrier> barrier)
{
cellSync.trace("cellSyncBarrierNotify(barrier=*0x%x)", barrier);

if (!barrier) [[unlikely]]
if (!barrier.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -167,7 +169,7 @@ error_code cellSyncBarrierNotify(ppu_thread& ppu, vm::ptr<CellSyncBarrier> barri
return CELL_SYNC_ERROR_ALIGN;
}

while (!barrier->ctrl.atomic_op(&CellSyncBarrier::try_notify))
while (!barrier.ref(&CellSyncBarrier::ctrl).atomic_op(&CellSyncBarrier::try_notify))
{
if (ppu.test_stopped())
{
Expand All @@ -178,11 +180,11 @@ error_code cellSyncBarrierNotify(ppu_thread& ppu, vm::ptr<CellSyncBarrier> barri
return CELL_OK;
}

error_code cellSyncBarrierTryNotify(vm::ptr<CellSyncBarrier> barrier)
error_code cellSyncBarrierTryNotify(vm::ref<CellSyncBarrier> barrier)
{
cellSync.trace("cellSyncBarrierTryNotify(barrier=*0x%x)", barrier);

if (!barrier) [[unlikely]]
if (!barrier.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -194,19 +196,19 @@ error_code cellSyncBarrierTryNotify(vm::ptr<CellSyncBarrier> barrier)

atomic_fence_acq_rel();

if (!barrier->ctrl.atomic_op(&CellSyncBarrier::try_notify))
if (!barrier.ref(&CellSyncBarrier::ctrl).atomic_op(&CellSyncBarrier::try_notify))
{
return not_an_error(CELL_SYNC_ERROR_BUSY);
}

return CELL_OK;
}

error_code cellSyncBarrierWait(ppu_thread& ppu, vm::ptr<CellSyncBarrier> barrier)
error_code cellSyncBarrierWait(ppu_thread& ppu, vm::ref<CellSyncBarrier> barrier)
{
cellSync.trace("cellSyncBarrierWait(barrier=*0x%x)", barrier);

if (!barrier) [[unlikely]]
if (!barrier.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -218,7 +220,7 @@ error_code cellSyncBarrierWait(ppu_thread& ppu, vm::ptr<CellSyncBarrier> barrier

atomic_fence_acq_rel();

while (!barrier->ctrl.atomic_op(&CellSyncBarrier::try_wait))
while (!barrier.ref(&CellSyncBarrier::ctrl).atomic_op(&CellSyncBarrier::try_wait))
{
if (ppu.test_stopped())
{
Expand All @@ -229,11 +231,11 @@ error_code cellSyncBarrierWait(ppu_thread& ppu, vm::ptr<CellSyncBarrier> barrier
return CELL_OK;
}

error_code cellSyncBarrierTryWait(vm::ptr<CellSyncBarrier> barrier)
error_code cellSyncBarrierTryWait(vm::ref<CellSyncBarrier> barrier)
{
cellSync.trace("cellSyncBarrierTryWait(barrier=*0x%x)", barrier);

if (!barrier) [[unlikely]]
if (!barrier.addr()) [[unlikely]]
{
return CELL_SYNC_ERROR_NULL_POINTER;
}
Expand All @@ -245,7 +247,7 @@ error_code cellSyncBarrierTryWait(vm::ptr<CellSyncBarrier> barrier)

atomic_fence_acq_rel();

if (!barrier->ctrl.atomic_op(&CellSyncBarrier::try_wait))
if (!barrier.ref(&CellSyncBarrier::ctrl).atomic_op(&CellSyncBarrier::try_wait))
{
return not_an_error(CELL_SYNC_ERROR_BUSY);
}
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellSync.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "Emu/Memory/vm_ptr.h"
#include "Emu/Memory/vm_ref.h"

#include "Utilities/BitField.h"

Expand Down
24 changes: 0 additions & 24 deletions rpcs3/Emu/Memory/vm_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ struct ppu_func_opd_t;

namespace vm
{
template <typename T, typename AT>
class _ref_base;

// Enables comparison between comparable types of pointers
template<typename T1, typename T2>
concept PtrComparable = requires (T1* t1, T2* t2) { t1 == t2; };
Expand Down Expand Up @@ -81,27 +78,6 @@ namespace vm
return vm::cast(vm::cast(m_addr) + offset32(mptr) + u32{sizeof(ET)} * index);
}

// Get vm reference to a struct member
template <typename MT, typename T2> requires PtrComparable<T, T2> && (!std::is_void_v<T>)
_ref_base<MT, u32> ref(MT T2::*const mptr) const
{
return vm::cast(vm::cast(m_addr) + offset32(mptr));
}

// Get vm reference to a struct member with array subscription
template <typename MT, typename T2, typename ET = std::remove_extent_t<MT>> requires PtrComparable<T, T2> && (!std::is_void_v<T>)
_ref_base<ET, u32> ref(MT T2::*const mptr, u32 index) const
{
return vm::cast(vm::cast(m_addr) + offset32(mptr) + u32{sizeof(ET)} * index);
}

// Get vm reference
template <bool = false> requires (!std::is_void_v<T>)
_ref_base<T, u32> ref() const
{
return vm::cast(m_addr);
}

T* get_ptr() const
{
return static_cast<T*>(vm::base(vm::cast(m_addr)));
Expand Down
Loading