Misc: Replace likely/unlikely with C++20 equivalents

This commit is contained in:
Stenzek 2023-12-22 19:27:44 +10:00 committed by Connor McLaughlin
parent 76f36b780c
commit c8b051628f
13 changed files with 51 additions and 56 deletions

View File

@ -69,7 +69,7 @@ __noinline static void UpdatePauseTime()
u32 ShortSpin() u32 ShortSpin()
{ {
u32 inc = PAUSE_TIME; u32 inc = PAUSE_TIME;
if (unlikely(inc == 0)) if (inc == 0) [[unlikely]]
{ {
UpdatePauseTime(); UpdatePauseTime();
inc = PAUSE_TIME; inc = PAUSE_TIME;

View File

@ -216,7 +216,7 @@ u64 Threading::GetThreadTicksPerSecond()
// On x86, despite what the MS documentation says, this basically appears to be rdtsc. // On x86, despite what the MS documentation says, this basically appears to be rdtsc.
// So, the frequency is our base clock speed (and stable regardless of power management). // So, the frequency is our base clock speed (and stable regardless of power management).
static u64 frequency = 0; static u64 frequency = 0;
if (unlikely(frequency == 0)) if (frequency == 0) [[unlikely]]
{ {
HKEY key; HKEY key;
LSTATUS res = LSTATUS res =

View File

@ -312,7 +312,7 @@ public:
int endOff = firstRowPgXEnd; int endOff = firstRowPgXEnd;
int yCnt = this->yCnt; int yCnt = this->yCnt;
if (unlikely(slowPath)) if (slowPath) [[unlikely]]
{ {
u32 touched[MAX_PAGES / 32] = {}; u32 touched[MAX_PAGES / 32] = {};
for (int y = 0; y < yCnt; y++) for (int y = 0; y < yCnt; y++)

View File

@ -118,7 +118,7 @@ struct GSRingHeap::Buffer
/// Decrement the main amt_allocated refcount /// Decrement the main amt_allocated refcount
void decref(size_t amt) void decref(size_t amt)
{ {
if (unlikely(m_amt_allocated.fetch_sub(amt, std::memory_order_release) == amt)) if (m_amt_allocated.fetch_sub(amt, std::memory_order_release) == amt) [[unlikely]]
{ {
std::atomic_thread_fence(std::memory_order_acquire); std::atomic_thread_fence(std::memory_order_acquire);
_aligned_free(this); _aligned_free(this);
@ -154,7 +154,7 @@ struct GSRingHeap::Buffer
do do
{ {
usage_mask |= 1ull << (cur_quadrant * 16); usage_mask |= 1ull << (cur_quadrant * 16);
if (unlikely(isStillInUse(cur_quadrant))) if (isStillInUse(cur_quadrant)) [[unlikely]]
return nullptr; return nullptr;
} while (++cur_quadrant <= new_quadrant); } while (++cur_quadrant <= new_quadrant);
} }
@ -202,7 +202,7 @@ void* GSRingHeap::alloc_internal(size_t size, size_t align_mask, size_t prefix_s
prefix_size += sizeof(Buffer*); // Add space for a pointer to the buffer prefix_size += sizeof(Buffer*); // Add space for a pointer to the buffer
size_t total_size = size + prefix_size; size_t total_size = size + prefix_size;
if (likely(total_size <= (m_current_buffer->m_size / 2))) if (total_size <= (m_current_buffer->m_size / 2)) [[likely]]
{ {
if (void* ptr = m_current_buffer->alloc(size, align_mask, prefix_size)) if (void* ptr = m_current_buffer->alloc(size, align_mask, prefix_size))
{ {

View File

@ -2240,7 +2240,7 @@ void GSRendererHW::Draw()
g_texture_cache->LookupSource(TEX0, env.TEXA, MIP_CLAMP, tmm.coverage, (GSConfig.HWMipmap >= HWMipmapLevel::Basic || GSConfig.TriFilter == TriFiltering::Forced) ? &hash_lod_range : nullptr, g_texture_cache->LookupSource(TEX0, env.TEXA, MIP_CLAMP, tmm.coverage, (GSConfig.HWMipmap >= HWMipmapLevel::Basic || GSConfig.TriFilter == TriFiltering::Forced) ? &hash_lod_range : nullptr,
possible_shuffle, m_vt.IsLinear(), m_cached_ctx.FRAME.Block(), req_color, req_alpha); possible_shuffle, m_vt.IsLinear(), m_cached_ctx.FRAME.Block(), req_color, req_alpha);
if (unlikely(!src)) if (!src) [[unlikely]]
{ {
GL_INS("ERROR: Source lookup failed, skipping."); GL_INS("ERROR: Source lookup failed, skipping.");
CleanupDraw(true); CleanupDraw(true);
@ -2352,7 +2352,7 @@ void GSRendererHW::Draw()
rt = g_texture_cache->CreateTarget(FRAME_TEX0, t_size, GetValidSize(src), target_scale, GSTextureCache::RenderTarget, true, rt = g_texture_cache->CreateTarget(FRAME_TEX0, t_size, GetValidSize(src), target_scale, GSTextureCache::RenderTarget, true,
fm, false, force_preload, preserve_rt_color, m_r, src); fm, false, force_preload, preserve_rt_color, m_r, src);
if (unlikely(!rt)) if (!rt) [[unlikely]]
{ {
GL_INS("ERROR: Failed to create FRAME target, skipping."); GL_INS("ERROR: Failed to create FRAME target, skipping.");
CleanupDraw(true); CleanupDraw(true);
@ -2376,7 +2376,7 @@ void GSRendererHW::Draw()
{ {
ds = g_texture_cache->CreateTarget(ZBUF_TEX0, t_size, GetValidSize(src), target_scale, GSTextureCache::DepthStencil, ds = g_texture_cache->CreateTarget(ZBUF_TEX0, t_size, GetValidSize(src), target_scale, GSTextureCache::DepthStencil,
true, 0, false, force_preload, preserve_depth, m_r, src); true, 0, false, force_preload, preserve_depth, m_r, src);
if (unlikely(!ds)) if (!ds) [[unlikely]]
{ {
GL_INS("ERROR: Failed to create ZBUF target, skipping."); GL_INS("ERROR: Failed to create ZBUF target, skipping.");
CleanupDraw(true); CleanupDraw(true);

View File

@ -99,7 +99,7 @@ GSDeviceMTL::Map GSDeviceMTL::Allocate(UploadBuffer& buffer, size_t amt)
amt = (amt + 31) & ~31ull; amt = (amt + 31) & ~31ull;
u64 last_draw = m_last_finished_draw.load(std::memory_order_acquire); u64 last_draw = m_last_finished_draw.load(std::memory_order_acquire);
bool needs_new = buffer.usage.PrepareForAllocation(last_draw, amt); bool needs_new = buffer.usage.PrepareForAllocation(last_draw, amt);
if (unlikely(needs_new)) if (needs_new) [[unlikely]]
{ {
// Orphan buffer // Orphan buffer
size_t newsize = std::max<size_t>(buffer.usage.Size() * 2, 4096); size_t newsize = std::max<size_t>(buffer.usage.Size() * 2, 4096);
@ -140,7 +140,7 @@ GSDeviceMTL::Map GSDeviceMTL::Allocate(BufferPair& buffer, size_t amt)
} }
buffer.last_upload = 0; buffer.last_upload = 0;
} }
if (unlikely(needs_new)) if (needs_new) [[unlikely]]
{ {
// Orphan buffer // Orphan buffer
size_t newsize = std::max<size_t>(buffer.usage.Size() * 2, 4096); size_t newsize = std::max<size_t>(buffer.usage.Size() * 2, 4096);
@ -669,7 +669,7 @@ MRCOwned<id<MTLFunction>> GSDeviceMTL::LoadShader(NSString* name)
{ {
NSError* err = nil; NSError* err = nil;
MRCOwned<id<MTLFunction>> fn = MRCTransfer([m_dev.shaders newFunctionWithName:name constantValues:m_fn_constants error:&err]); MRCOwned<id<MTLFunction>> fn = MRCTransfer([m_dev.shaders newFunctionWithName:name constantValues:m_fn_constants error:&err]);
if (unlikely(err)) if (err) [[unlikely]]
{ {
NSString* msg = [NSString stringWithFormat:@"Failed to load shader %@: %@", name, [err localizedDescription]]; NSString* msg = [NSString stringWithFormat:@"Failed to load shader %@: %@", name, [err localizedDescription]];
Console.Error("%s", [msg UTF8String]); Console.Error("%s", [msg UTF8String]);
@ -685,7 +685,7 @@ MRCOwned<id<MTLRenderPipelineState>> GSDeviceMTL::MakePipeline(MTLRenderPipeline
[desc setFragmentFunction:fragment]; [desc setFragmentFunction:fragment];
NSError* err; NSError* err;
MRCOwned<id<MTLRenderPipelineState>> res = MRCTransfer([m_dev.dev newRenderPipelineStateWithDescriptor:desc error:&err]); MRCOwned<id<MTLRenderPipelineState>> res = MRCTransfer([m_dev.dev newRenderPipelineStateWithDescriptor:desc error:&err]);
if (unlikely(err)) if (err) [[unlikely]]
{ {
NSString* msg = [NSString stringWithFormat:@"Failed to create pipeline %@: %@", name, [err localizedDescription]]; NSString* msg = [NSString stringWithFormat:@"Failed to create pipeline %@: %@", name, [err localizedDescription]];
Console.Error("%s", [msg UTF8String]); Console.Error("%s", [msg UTF8String]);
@ -705,7 +705,7 @@ MRCOwned<id<MTLComputePipelineState>> GSDeviceMTL::MakeComputePipeline(id<MTLFun
options:0 options:0
reflection:nil reflection:nil
error:&err]); error:&err]);
if (unlikely(err)) if (err) [[unlikely]]
{ {
NSString* msg = [NSString stringWithFormat:@"Failed to create pipeline %@: %@", name, [err localizedDescription]]; NSString* msg = [NSString stringWithFormat:@"Failed to create pipeline %@: %@", name, [err localizedDescription]];
Console.Error("%s", [msg UTF8String]); Console.Error("%s", [msg UTF8String]);
@ -1897,7 +1897,7 @@ void GSDeviceMTL::MRESetSampler(SamplerSelector sel)
{ {
if (m_current_render.has.sampler && m_current_render.sampler_sel.key == sel.key) if (m_current_render.has.sampler && m_current_render.sampler_sel.key == sel.key)
return; return;
if (unlikely(!m_sampler_hw[sel.key])) if (!m_sampler_hw[sel.key]) [[unlikely]]
m_sampler_hw[sel.key] = CreateSampler(m_dev.dev, sel); m_sampler_hw[sel.key] = CreateSampler(m_dev.dev, sel);
[m_current_render.encoder setFragmentSamplerState:m_sampler_hw[sel.key] atIndex:0]; [m_current_render.encoder setFragmentSamplerState:m_sampler_hw[sel.key] atIndex:0];
m_current_render.sampler_sel = sel; m_current_render.sampler_sel = sel;

View File

@ -91,7 +91,7 @@ bool GSDrawScanline::SetupDraw(GSRasterizerData& data)
#ifdef ENABLE_JIT_RASTERIZER #ifdef ENABLE_JIT_RASTERIZER
data.draw_scanline = m_ds_map[global.sel]; data.draw_scanline = m_ds_map[global.sel];
if (!unlikely(data.draw_scanline)) if (!data.draw_scanline) [[unlikely]]
return false; return false;
if (global.sel.aa1) if (global.sel.aa1)
@ -103,7 +103,7 @@ bool GSDrawScanline::SetupDraw(GSRasterizerData& data)
sel.edge = 1; sel.edge = 1;
data.draw_edge = m_ds_map[sel]; data.draw_edge = m_ds_map[sel];
if (unlikely(!data.draw_edge)) if (!data.draw_edge) [[unlikely]]
return false; return false;
} }
else else

View File

@ -1168,7 +1168,7 @@ void GSSingleRasterizer::Queue(const GSRingHeap::SharedPtr<GSRasterizerData>& da
void GSSingleRasterizer::Draw(GSRasterizerData& data) void GSSingleRasterizer::Draw(GSRasterizerData& data)
{ {
if (!unlikely(m_ds.SetupDraw(data))) if (!m_ds.SetupDraw(data)) [[unlikely]]
{ {
m_ds.ResetCodeCache(); m_ds.ResetCodeCache();
m_ds.SetupDraw(data); m_ds.SetupDraw(data);
@ -1251,7 +1251,7 @@ void GSRasterizerList::Queue(const GSRingHeap::SharedPtr<GSRasterizerData>& data
{ {
GSVector4i r = data->bbox.rintersect(data->scissor); GSVector4i r = data->bbox.rintersect(data->scissor);
if (unlikely(!m_ds.SetupDraw(*data.get()))) if (!m_ds.SetupDraw(*data.get())) [[unlikely]]
{ {
Sync(); Sync();
m_ds.ResetCodeCache(); m_ds.ResetCodeCache();

View File

@ -62,7 +62,7 @@ std::pair<const char*, u32> Host::LookupTranslationString(const std::string_view
s32 len; s32 len;
// Shouldn't happen, but just in case someone tries to translate an empty string. // Shouldn't happen, but just in case someone tries to translate an empty string.
if (unlikely(msg.empty())) if (msg.empty()) [[unlikely]]
{ {
ret.first = &s_translation_string_cache[0]; ret.first = &s_translation_string_cache[0];
ret.second = 0; ret.second = 0;
@ -72,11 +72,11 @@ std::pair<const char*, u32> Host::LookupTranslationString(const std::string_view
s_translation_string_mutex.lock_shared(); s_translation_string_mutex.lock_shared();
ctx_it = s_translation_string_map.find(context); ctx_it = s_translation_string_map.find(context);
if (unlikely(ctx_it == s_translation_string_map.end())) if (ctx_it == s_translation_string_map.end()) [[unlikely]]
goto add_string; goto add_string;
msg_it = ctx_it->second.find(msg); msg_it = ctx_it->second.find(msg);
if (unlikely(msg_it == ctx_it->second.end())) if (msg_it == ctx_it->second.end()) [[unlikely]]
goto add_string; goto add_string;
ret.first = &s_translation_string_cache[msg_it->second.first]; ret.first = &s_translation_string_cache[msg_it->second.first];
@ -88,7 +88,7 @@ add_string:
s_translation_string_mutex.unlock_shared(); s_translation_string_mutex.unlock_shared();
s_translation_string_mutex.lock(); s_translation_string_mutex.lock();
if (unlikely(s_translation_string_cache.empty())) if (s_translation_string_cache.empty()) [[unlikely]]
{ {
// First element is always an empty string. // First element is always an empty string.
s_translation_string_cache.resize(TRANSLATION_STRING_CACHE_SIZE); s_translation_string_cache.resize(TRANSLATION_STRING_CACHE_SIZE);

View File

@ -278,7 +278,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
while (buf_cnt < buf_size) while (buf_cnt < buf_size)
{ {
if (!SafetyChecks(buf_cnt, 1, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 1, ret_cnt, 0, buf_size)) [[unlikely]]
return IPCBuffer{5, MakeFailIPC(ret_buffer)}; return IPCBuffer{5, MakeFailIPC(ret_buffer)};
buf_cnt++; buf_cnt++;
// example IPC messages: MsgRead/Write // example IPC messages: MsgRead/Write
@ -298,7 +298,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 4, ret_cnt, 1, buf_size)) if (!SafetyChecks(buf_cnt, 4, ret_cnt, 1, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
const u8 res = memRead8(a); const u8 res = memRead8(a);
@ -311,7 +311,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 4, ret_cnt, 2, buf_size)) if (!SafetyChecks(buf_cnt, 4, ret_cnt, 2, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
const u16 res = memRead16(a); const u16 res = memRead16(a);
@ -324,7 +324,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 4, ret_cnt, 4, buf_size)) if (!SafetyChecks(buf_cnt, 4, ret_cnt, 4, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
const u32 res = memRead32(a); const u32 res = memRead32(a);
@ -337,7 +337,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 4, ret_cnt, 8, buf_size)) if (!SafetyChecks(buf_cnt, 4, ret_cnt, 8, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
const u64 res = memRead64(a); const u64 res = memRead64(a);
@ -350,7 +350,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 1 + 4, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 1 + 4, ret_cnt, 0, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
memWrite8(a, FromSpan<u8>(buf, buf_cnt + 4)); memWrite8(a, FromSpan<u8>(buf, buf_cnt + 4));
@ -361,7 +361,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 2 + 4, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 2 + 4, ret_cnt, 0, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
memWrite16(a, FromSpan<u16>(buf, buf_cnt + 4)); memWrite16(a, FromSpan<u16>(buf, buf_cnt + 4));
@ -372,7 +372,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 4 + 4, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 4 + 4, ret_cnt, 0, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
memWrite32(a, FromSpan<u32>(buf, buf_cnt + 4)); memWrite32(a, FromSpan<u32>(buf, buf_cnt + 4));
@ -383,7 +383,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 8 + 4, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 8 + 4, ret_cnt, 0, buf_size)) [[unlikely]]
goto error; goto error;
const u32 a = FromSpan<u32>(buf, buf_cnt); const u32 a = FromSpan<u32>(buf, buf_cnt);
memWrite64(a, FromSpan<u64>(buf, buf_cnt + 4)); memWrite64(a, FromSpan<u64>(buf, buf_cnt + 4));
@ -406,7 +406,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
version = fmt::format("PCSX2 {}.{}.{}-{}", PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo, SVN_REV); version = fmt::format("PCSX2 {}.{}.{}-{}", PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo, SVN_REV);
} }
const u32 size = version.size() + 1; const u32 size = version.size() + 1;
if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) [[unlikely]]
goto error; goto error;
ToResultVector(ret_buffer, size, ret_cnt); ToResultVector(ret_buffer, size, ret_cnt);
ret_cnt += 4; ret_cnt += 4;
@ -418,7 +418,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 1, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 1, ret_cnt, 0, buf_size)) [[unlikely]]
goto error; goto error;
VMManager::SaveStateToSlot(FromSpan<u8>(buf, buf_cnt)); VMManager::SaveStateToSlot(FromSpan<u8>(buf, buf_cnt));
buf_cnt += 1; buf_cnt += 1;
@ -428,7 +428,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
{ {
if (!VMManager::HasValidVM()) if (!VMManager::HasValidVM())
goto error; goto error;
if (!SafetyChecks(buf_cnt, 1, ret_cnt, 0, buf_size)) if (!SafetyChecks(buf_cnt, 1, ret_cnt, 0, buf_size)) [[unlikely]]
goto error; goto error;
VMManager::LoadStateFromSlot(FromSpan<u8>(buf, buf_cnt)); VMManager::LoadStateFromSlot(FromSpan<u8>(buf, buf_cnt));
buf_cnt += 1; buf_cnt += 1;
@ -440,7 +440,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
goto error; goto error;
const std::string gameName = VMManager::GetTitle(false); const std::string gameName = VMManager::GetTitle(false);
const u32 size = gameName.size() + 1; const u32 size = gameName.size() + 1;
if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) [[unlikely]]
goto error; goto error;
ToResultVector(ret_buffer, size, ret_cnt); ToResultVector(ret_buffer, size, ret_cnt);
ret_cnt += 4; ret_cnt += 4;
@ -454,7 +454,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
goto error; goto error;
const std::string gameSerial = VMManager::GetDiscSerial(); const std::string gameSerial = VMManager::GetDiscSerial();
const u32 size = gameSerial.size() + 1; const u32 size = gameSerial.size() + 1;
if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) [[unlikely]]
goto error; goto error;
ToResultVector(ret_buffer, size, ret_cnt); ToResultVector(ret_buffer, size, ret_cnt);
ret_cnt += 4; ret_cnt += 4;
@ -468,7 +468,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
goto error; goto error;
const std::string crc = fmt::format("{:08x}", VMManager::GetDiscCRC()); const std::string crc = fmt::format("{:08x}", VMManager::GetDiscCRC());
const u32 size = crc.size() + 1; const u32 size = crc.size() + 1;
if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) [[unlikely]]
goto error; goto error;
ToResultVector(ret_buffer, size, ret_cnt); ToResultVector(ret_buffer, size, ret_cnt);
ret_cnt += 4; ret_cnt += 4;
@ -483,7 +483,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
const std::string ElfVersion = VMManager::GetDiscVersion(); const std::string ElfVersion = VMManager::GetDiscVersion();
const u32 size = ElfVersion.size() + 1; const u32 size = ElfVersion.size() + 1;
if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) if (!SafetyChecks(buf_cnt, 0, ret_cnt, size + 4, buf_size)) [[unlikely]]
goto error; goto error;
ToResultVector(ret_buffer, size, ret_cnt); ToResultVector(ret_buffer, size, ret_cnt);
ret_cnt += 4; ret_cnt += 4;
@ -493,7 +493,7 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span<u8> buf, std::vector<u8
} }
case MsgStatus: case MsgStatus:
{ {
if (!SafetyChecks(buf_cnt, 0, ret_cnt, 4, buf_size)) if (!SafetyChecks(buf_cnt, 0, ret_cnt, 4, buf_size)) [[unlikely]]
goto error; goto error;
EmuStatus status; EmuStatus status;

View File

@ -201,11 +201,8 @@ protected:
*/ */
static inline bool SafetyChecks(u32 command_len, int command_size, u32 reply_len, int reply_size = 0, u32 buf_size = MAX_IPC_SIZE - 1) static inline bool SafetyChecks(u32 command_len, int command_size, u32 reply_len, int reply_size = 0, u32 buf_size = MAX_IPC_SIZE - 1)
{ {
const bool res = ((command_len + command_size) > buf_size || return ((command_len + command_size) > buf_size ||
(reply_len + reply_size) >= MAX_IPC_RETURN_SIZE); (reply_len + reply_size) >= MAX_IPC_RETURN_SIZE);
if (unlikely(res))
return false;
return true;
} }
public: public:

View File

@ -554,7 +554,7 @@ void LH()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 1)) if (addr & 1) [[unlikely]]
RaiseAddressError(addr, false); RaiseAddressError(addr, false);
s16 temp = memRead16(addr); s16 temp = memRead16(addr);
@ -567,7 +567,7 @@ void LHU()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 1)) if (addr & 1) [[unlikely]]
RaiseAddressError(addr, false); RaiseAddressError(addr, false);
u16 temp = memRead16(addr); u16 temp = memRead16(addr);
@ -580,7 +580,7 @@ void LW()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 3)) if (addr & 3) [[unlikely]]
RaiseAddressError(addr, false); RaiseAddressError(addr, false);
u32 temp = memRead32(addr); u32 temp = memRead32(addr);
@ -593,7 +593,7 @@ void LWU()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 3)) if (addr & 3) [[unlikely]]
RaiseAddressError(addr, false); RaiseAddressError(addr, false);
u32 temp = memRead32(addr); u32 temp = memRead32(addr);
@ -681,7 +681,7 @@ void LD()
{ {
s32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; s32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 7)) if (addr & 7) [[unlikely]]
RaiseAddressError(addr, false); RaiseAddressError(addr, false);
cpuRegs.GPR.r[_Rt_].UD[0] = memRead64(addr); cpuRegs.GPR.r[_Rt_].UD[0] = memRead64(addr);
@ -743,7 +743,7 @@ void SH()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 1)) if (addr & 1) [[unlikely]]
RaiseAddressError(addr, true); RaiseAddressError(addr, true);
memWrite16(addr, cpuRegs.GPR.r[_Rt_].US[0]); memWrite16(addr, cpuRegs.GPR.r[_Rt_].US[0]);
@ -753,7 +753,7 @@ void SW()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 3)) if (addr & 3) [[unlikely]]
RaiseAddressError(addr, true); RaiseAddressError(addr, true);
memWrite32(addr, cpuRegs.GPR.r[_Rt_].UL[0]); memWrite32(addr, cpuRegs.GPR.r[_Rt_].UL[0]);
@ -810,7 +810,7 @@ void SD()
{ {
u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_; u32 addr = cpuRegs.GPR.r[_Rs_].UL[0] + _Imm_;
if (unlikely(addr & 7)) if (addr & 7) [[unlikely]]
RaiseAddressError(addr, true); RaiseAddressError(addr, true);
memWrite64(addr,cpuRegs.GPR.r[_Rt_].UD[0]); memWrite64(addr,cpuRegs.GPR.r[_Rt_].UD[0]);

View File

@ -407,10 +407,8 @@ _vifT __fi void dVifUnpack(const u8* data, bool isFill)
// Seach in cache before trying to compile the block // Seach in cache before trying to compile the block
nVifBlock* b = v.vifBlocks.find(block); nVifBlock* b = v.vifBlocks.find(block);
if (unlikely(b == nullptr)) if (!b) [[unlikely]]
{
b = dVifCompile<idx>(block, isFill); b = dVifCompile<idx>(block, isFill);
}
{ // Execute the block { // Execute the block
const VURegs& VU = vuRegs[idx]; const VURegs& VU = vuRegs[idx];
@ -419,7 +417,7 @@ _vifT __fi void dVifUnpack(const u8* data, bool isFill)
u8* startmem = VU.Mem + (vif.tag.addr & (vuMemLimit - 0x10)); u8* startmem = VU.Mem + (vif.tag.addr & (vuMemLimit - 0x10));
u8* endmem = VU.Mem + vuMemLimit; u8* endmem = VU.Mem + vuMemLimit;
if (likely((startmem + b->length) <= endmem)) if ((startmem + b->length) <= endmem) [[likely]]
{ {
// No wrapping, you can run the fast dynarec // No wrapping, you can run the fast dynarec
((nVifrecCall)b->startPtr)((uptr)startmem, (uptr)data); ((nVifrecCall)b->startPtr)((uptr)startmem, (uptr)data);