From 2491aad6f2caa5cd1138e244021d28564c3b11f9 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 22 May 2021 21:46:10 +0300 Subject: [PATCH] types.hpp: implement min_v<>, max_v<>, SignedInt, UnsignedInt, FPInt concepts Restrict smax to only work with signed values for consistency. Cleanup includes. Cleanup includes. --- rpcs3/Emu/CPU/CPUDisAsm.h | 3 +- rpcs3/Emu/CPU/CPUThread.cpp | 4 +- rpcs3/Emu/CPU/CPUTranslator.h | 2 +- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 6 +- rpcs3/Emu/Cell/Modules/cellGcmSys.cpp | 5 +- rpcs3/Emu/Cell/Modules/cellSpurs.cpp | 3 +- rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp | 8 +- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 4 +- rpcs3/Emu/Memory/vm.cpp | 10 +- rpcs3/Emu/Memory/vm.h | 2 +- rpcs3/Emu/RSX/Common/ring_buffer_helper.h | 2 +- rpcs3/Emu/RSX/Common/texture_cache.h | 8 +- rpcs3/Emu/RSX/Common/texture_cache_checker.h | 4 +- .../Emu/RSX/Common/texture_cache_predictor.h | 8 +- rpcs3/Emu/RSX/Common/texture_cache_utils.h | 8 +- rpcs3/Emu/RSX/GL/GLOverlays.cpp | 2 +- rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp | 2 +- rpcs3/Emu/RSX/Overlays/overlay_controls.h | 5 +- rpcs3/Emu/RSX/Overlays/overlay_edit_text.cpp | 2 +- rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp | 2 +- rpcs3/Emu/RSX/Overlays/overlay_fonts.h | 4 +- rpcs3/Emu/RSX/Overlays/overlay_osk.h | 2 +- .../Emu/RSX/Overlays/overlay_perf_metrics.cpp | 2 +- rpcs3/Emu/RSX/Overlays/overlays.h | 4 +- .../RSX/Program/FragmentProgramDecompiler.h | 4 +- rpcs3/Emu/RSX/Program/ProgramStateCache.cpp | 4 +- .../RSX/Program/VertexProgramDecompiler.cpp | 8 +- rpcs3/Emu/RSX/RSXFIFO.cpp | 2 +- rpcs3/Emu/RSX/RSXThread.cpp | 8 +- rpcs3/Emu/RSX/RSXThread.h | 2 +- rpcs3/Emu/RSX/VK/VKDraw.cpp | 4 +- rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp | 2 +- rpcs3/Emu/RSX/VK/VKGSRender.h | 2 +- rpcs3/Emu/RSX/VK/VKOverlays.cpp | 4 +- rpcs3/Emu/RSX/VK/VKPresent.cpp | 10 +- rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp | 16 +- rpcs3/Emu/RSX/VK/vkutils/device.cpp | 2 +- rpcs3/Emu/RSX/VK/vkutils/instance.hpp | 16 +- rpcs3/Emu/RSX/VK/vkutils/swapchain.hpp | 2 +- rpcs3/Emu/RSX/rsx_cache.h | 4 +- rpcs3/main.cpp | 1 - rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp | 2 +- rpcs3/rpcs3qt/debugger_frame.cpp | 6 +- rpcs3/rpcs3qt/instruction_editor_dialog.cpp | 2 +- rpcs3/rpcs3qt/kernel_explorer.cpp | 6 +- rpcs3/rpcs3qt/log_frame.cpp | 2 +- rpcs3/rpcs3qt/memory_string_searcher.cpp | 4 +- rpcs3/util/types.hpp | 143 +++++++++++------- 48 files changed, 190 insertions(+), 168 deletions(-) diff --git a/rpcs3/Emu/CPU/CPUDisAsm.h b/rpcs3/Emu/CPU/CPUDisAsm.h index 259a71416b..c7f8a5b7e9 100644 --- a/rpcs3/Emu/CPU/CPUDisAsm.h +++ b/rpcs3/Emu/CPU/CPUDisAsm.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include "Utilities/StrFmt.h" enum class cpu_disasm_mode @@ -93,7 +92,7 @@ protected: { const auto v = static_cast>(value); - if (v == std::numeric_limits>::min()) + if (v == smin) { // for INTx_MIN return fmt::format("-0x%x", v); diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 2bdba5c929..9a13484f6c 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -902,12 +902,12 @@ u32 cpu_thread::get_pc() const case 0x55: { const auto ctrl = static_cast(this)->ctrl; - return ctrl ? ctrl->get : UINT32_MAX; + return ctrl ? ctrl->get.load() : umax; } default: break; } - return pc ? atomic_storage::load(*pc) : UINT32_MAX; + return pc ? atomic_storage::load(*pc) : u32{umax}; } u32* cpu_thread::get_pc2() diff --git a/rpcs3/Emu/CPU/CPUTranslator.h b/rpcs3/Emu/CPU/CPUTranslator.h index c8db00a4db..be5d0349e8 100644 --- a/rpcs3/Emu/CPU/CPUTranslator.h +++ b/rpcs3/Emu/CPU/CPUTranslator.h @@ -1375,7 +1375,7 @@ inline llvm_xor::type>> operator ^( template inline llvm_xor::type, true>> operator ~(T1&& a1) { - return {a1, {UINT64_MAX}}; + return {a1, {u64{umax}}}; } template > diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index ec76cc296e..a596e6db4f 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -361,7 +361,7 @@ void audio_port::tag(s32 offset) last_tag_value[tag_nr] = -0.0f; } - prev_touched_tag_nr = UINT32_MAX; + prev_touched_tag_nr = -1; } std::tuple cell_audio_thread::count_port_buffer_tags() @@ -395,13 +395,13 @@ std::tuple cell_audio_thread::count_port_buffer_tags() { last_val = val; - retouched |= (tag_nr <= port.prev_touched_tag_nr) && port.prev_touched_tag_nr != UINT32_MAX; + retouched |= (tag_nr <= port.prev_touched_tag_nr) && port.prev_touched_tag_nr != umax; last_touched_tag_nr = tag_nr; } } // Decide whether the buffer is untouched, in progress, incomplete, or complete - if (last_touched_tag_nr == UINT32_MAX) + if (last_touched_tag_nr == umax) { // no tag has been touched yet untouched++; diff --git a/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp b/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp index c230e866f8..f51a1325fb 100644 --- a/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp @@ -775,10 +775,7 @@ error_code cellGcmGetCurrentDisplayBufferId(vm::ptr id) { cellGcmSys.warning("cellGcmGetCurrentDisplayBufferId(id=*0x%x)", id); - if ((*id = rsx::get_current_renderer()->current_display_buffer) > UINT8_MAX) - { - fmt::throw_exception("Unexpected"); - } + *id = ::narrow(rsx::get_current_renderer()->current_display_buffer); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp index 92d19d6200..14d2ea2f91 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp @@ -4608,8 +4608,7 @@ s32 cellSpursCreateJobChain(ppu_thread& ppu, vm::ptr spurs, vm::ptr(*priorities); - if (auto err = _spurs::check_job_chain_attribute(UINT32_MAX, jobChainEntry, sizeJobDescriptor, maxGrabbedJob, prio, maxContention - , autoReadyCount, tag1, tag2, 0, 0, 0)) + if (auto err = _spurs::check_job_chain_attribute(-1, jobChainEntry, sizeJobDescriptor, maxGrabbedJob, prio, maxContention, autoReadyCount, tag1, tag2, 0, 0, 0)) { return err; } diff --git a/rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp b/rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp index 2fe71cb5da..3b30724651 100644 --- a/rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp @@ -58,7 +58,7 @@ error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr lwcond) if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY) { - return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, UINT32_MAX, 2); + return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, u32{umax}, 2); } if (lwmutex->vars.owner.load() == ppu.id) @@ -67,7 +67,7 @@ error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr lwcond) lwmutex->all_info++; // call the syscall - if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, UINT32_MAX, 1)) + if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, u32{umax}, 1)) { if (ppu.test_stopped()) { @@ -95,7 +95,7 @@ error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr lwcond) } // call the syscall - return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, UINT32_MAX, 2); + return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, u32{umax}, 2); } // if locking succeeded @@ -106,7 +106,7 @@ error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr lwcond) }); // call the syscall - if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, UINT32_MAX, 3)) + if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, u32{umax}, 3)) { if (ppu.test_stopped()) { diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index ab1a2c0096..416f836978 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -43,7 +43,7 @@ void lv2_timer_context::operator()() { // Set next expiration time and check again const u64 _next = next + period; - expire.release(_next > next ? _next : UINT64_MAX); + expire.release(_next > next ? _next : umax); continue; } @@ -164,7 +164,7 @@ error_code _sys_timer_start(ppu_thread& ppu, u32 timer_id, u64 base_time, u64 pe // sys_timer_start_periodic() will use current time (TODO: is it correct?) const u64 expire = base_time ? base_time : start_time + period; - timer.expire = expire > start_time ? expire : UINT64_MAX; + timer.expire = expire > start_time ? expire : umax; timer.period = period; timer.state = SYS_TIMER_STATE_RUN; diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 98f96db9a7..76827ba85b 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -94,7 +94,7 @@ namespace vm void reservation_update(u32 addr) { - u64 old = UINT64_MAX; + u64 old = -1; const auto cpu = get_current_cpu_thread(); while (true) @@ -705,7 +705,7 @@ namespace vm } // Unsharing only happens on deallocation currently, so make sure all further refs are shared - shm->info = UINT32_MAX; + shm->info = 0xffff'ffff; } // Obtain existing pointer @@ -1643,11 +1643,11 @@ namespace vm "vm::g_hook_addr = %p - %p\n" "vm::g_stat_addr = %p - %p\n" "vm::g_reservations = %p - %p\n", - g_base_addr, g_base_addr + UINT32_MAX, - g_sudo_addr, g_sudo_addr + UINT32_MAX, + g_base_addr, g_base_addr + 0xffff'ffff, + g_sudo_addr, g_sudo_addr + 0xffff'ffff, g_exec_addr, g_exec_addr + 0x200000000 - 1, g_hook_addr, g_hook_addr + 0x800000000 - 1, - g_stat_addr, g_stat_addr + UINT32_MAX, + g_stat_addr, g_stat_addr + 0xffff'ffff, g_reservations, g_reservations + sizeof(g_reservations) - 1); std::memset(&g_pages, 0, sizeof(g_pages)); diff --git a/rpcs3/Emu/Memory/vm.h b/rpcs3/Emu/Memory/vm.h index af1a4ebb6a..e6623187c0 100644 --- a/rpcs3/Emu/Memory/vm.h +++ b/rpcs3/Emu/Memory/vm.h @@ -171,7 +171,7 @@ namespace vm { const std::make_unsigned_t diff = static_cast(real_ptr) - g_base_addr; - if (diff <= u64{UINT32_MAX} * 2 + 1) + if (diff <= u64{u32{umax}} * 2 + 1) { return {vm::addr_t{static_cast(diff)}, true}; } diff --git a/rpcs3/Emu/RSX/Common/ring_buffer_helper.h b/rpcs3/Emu/RSX/Common/ring_buffer_helper.h index a2ccbb0008..7f434ef1b0 100644 --- a/rpcs3/Emu/RSX/Common/ring_buffer_helper.h +++ b/rpcs3/Emu/RSX/Common/ring_buffer_helper.h @@ -133,7 +133,7 @@ public: // Updates the current_allocated_size metrics void notify() { - if (m_get_pos == UINT64_MAX) + if (m_get_pos == umax) m_current_allocated_size = 0; else if (m_get_pos < m_put_pos) m_current_allocated_size = (m_put_pos - m_get_pos - 1); diff --git a/rpcs3/Emu/RSX/Common/texture_cache.h b/rpcs3/Emu/RSX/Common/texture_cache.h index 49182f1eda..59706f4cb0 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache.h +++ b/rpcs3/Emu/RSX/Common/texture_cache.h @@ -670,7 +670,7 @@ namespace rsx invalidate_range = fault_range; // Sections fully inside this range will be invalidated, others will be deemed false positives // Loop through cache and find pages that overlap the invalidate_range - u32 last_dirty_block = UINT32_MAX; + u32 last_dirty_block = -1; bool repeat_loop = false; auto It = m_storage.range_begin(invalidate_range, locked_range, true); // will iterate through locked sections only @@ -685,7 +685,7 @@ namespace rsx auto &tex = *It; AUDIT(tex.is_locked()); // we should be iterating locked sections only, but just to make sure... - AUDIT(tex.cache_tag != cache_tag || last_dirty_block != UINT32_MAX); // cache tag should not match during the first loop + AUDIT(tex.cache_tag != cache_tag || last_dirty_block != umax); // cache tag should not match during the first loop if (tex.cache_tag != cache_tag) //flushable sections can be 'clean' but unlocked. TODO: Handle this better { @@ -997,7 +997,7 @@ namespace rsx if (!tex.is_dirty() && (context_mask & static_cast(tex.get_context()))) { - if (required_pitch && !rsx::pitch_compatible(&tex, required_pitch, UINT16_MAX)) + if (required_pitch && !rsx::pitch_compatible(&tex, required_pitch, -1)) { continue; } @@ -1784,7 +1784,7 @@ namespace rsx if (result_is_valid) { // Check for possible duplicates - usz max_safe_sections = UINT32_MAX; + usz max_safe_sections = u32{umax}; switch (result.external_subresource_desc.op) { case deferred_request_command::atlas_gather: diff --git a/rpcs3/Emu/RSX/Common/texture_cache_checker.h b/rpcs3/Emu/RSX/Common/texture_cache_checker.h index 3235a4c90c..0325dda596 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_checker.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_checker.h @@ -48,8 +48,8 @@ namespace rsx { { switch (prot) { - case utils::protection::no: if (no++ == UINT8_MAX) fmt::throw_exception("add(protection::no) overflow with NO==%d", UINT8_MAX); return; - case utils::protection::ro: if (ro++ == UINT8_MAX) fmt::throw_exception("add(protection::ro) overflow with RO==%d", UINT8_MAX); return; + case utils::protection::no: if (no++ == umax) fmt::throw_exception("add(protection::no) overflow"); return; + case utils::protection::ro: if (ro++ == umax) fmt::throw_exception("add(protection::ro) overflow"); return; default: fmt::throw_exception("Unreachable"); } } diff --git a/rpcs3/Emu/RSX/Common/texture_cache_predictor.h b/rpcs3/Emu/RSX/Common/texture_cache_predictor.h index 73a87d324b..287a2debca 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_predictor.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_predictor.h @@ -196,7 +196,7 @@ namespace rsx if (history_size == 0) { // We need some history to be able to take a guess - return UINT32_MAX; + return -1; } else if (history_size == 1) { @@ -209,7 +209,7 @@ namespace rsx const u32 stop_when_found_matches = 4; u32 matches_found = 0; - u32 guess = UINT32_MAX; + u32 guess = -1; for (u32 i = 0; i < history_size; i++) { @@ -249,7 +249,7 @@ namespace rsx void calculate_next_guess(bool reset) { - if (reset || m_guessed_writes == UINT32_MAX || m_writes_since_last_flush > m_guessed_writes) + if (reset || m_guessed_writes == umax || m_writes_since_last_flush > m_guessed_writes) { m_guessed_writes = guess_number_of_writes(); } @@ -260,7 +260,7 @@ namespace rsx { confidence = starting_confidence; m_writes_since_last_flush = 0; - m_guessed_writes = UINT32_MAX; + m_guessed_writes = -1; write_history.clear(); } diff --git a/rpcs3/Emu/RSX/Common/texture_cache_utils.h b/rpcs3/Emu/RSX/Common/texture_cache_utils.h index 01f2c32b1b..4365bbb823 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_utils.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_utils.h @@ -73,14 +73,14 @@ namespace rsx idx(0) { if (_block->empty()) - idx = UINT32_MAX; + idx = u32{umax}; } private: // Members block_list *block; list_iterator list_it = {}; - size_type idx = UINT32_MAX; + size_type idx = u32{umax}; size_type array_idx = 0; inline void next() @@ -88,7 +88,7 @@ namespace rsx ++idx; if (idx >= block->size()) { - idx = UINT32_MAX; + idx = u32{umax}; return; } @@ -134,7 +134,7 @@ namespace rsx // Constructor, Destructor ranged_storage_block_list() : m_data_it(m_data.end()), - m_array_idx(UINT32_MAX), + m_array_idx(-1), m_capacity(0) {} diff --git a/rpcs3/Emu/RSX/GL/GLOverlays.cpp b/rpcs3/Emu/RSX/GL/GLOverlays.cpp index 9822cdb62d..3d28e263cb 100644 --- a/rpcs3/Emu/RSX/GL/GLOverlays.cpp +++ b/rpcs3/Emu/RSX/GL/GLOverlays.cpp @@ -375,7 +375,7 @@ namespace gl for (const auto &res : configuration.texture_raw_data) { - load_simple_image(res.get(), false, UINT32_MAX); + load_simple_image(res.get(), false, -1); } configuration.free_resources(); diff --git a/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp b/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp index 77ce02bb19..72a1984c9f 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp @@ -187,7 +187,7 @@ gl::vertex_upload_info GLGSRender::set_vertex_buffer() //TODO: make vertex cache keep local data beyond frame boundaries and hook notify command bool in_cache = false; bool to_store = false; - u32 storage_address = UINT32_MAX; + u32 storage_address = -1; if (m_vertex_layout.interleaved_blocks.size() == 1 && rsx::method_registers.current_draw_clause.command != rsx::draw_command::inlined_array) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.h b/rpcs3/Emu/RSX/Overlays/overlay_controls.h index 647343f23b..45bb6be7b3 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.h @@ -20,7 +20,6 @@ #include #include #include -#include #endif #ifdef __APPLE__ @@ -508,7 +507,7 @@ namespace rsx auto renderer = get_font(); f32 text_extents_w = 0.f; - u16 clip_width = clip_text ? w : UINT16_MAX; + u16 clip_width = clip_text ? w : umax; std::vector result = renderer->render_text(string, clip_width, wrap_text); if (!result.empty()) @@ -1005,7 +1004,7 @@ namespace rsx set_text(text); } - bool auto_resize(bool grow_only = false, u16 limit_w = UINT16_MAX, u16 limit_h = UINT16_MAX) + bool auto_resize(bool grow_only = false, u16 limit_w = -1, u16 limit_h = -1) { u16 new_width, new_height; u16 old_width = w, old_height = h; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_edit_text.cpp b/rpcs3/Emu/RSX/Overlays/overlay_edit_text.cpp index efcce9743e..aab3626efa 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_edit_text.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_edit_text.cpp @@ -181,7 +181,7 @@ namespace rsx overlay_element caret; auto renderer = get_font(); - const auto caret_loc = renderer->get_char_offset(text.c_str(), caret_position, clip_text ? w : UINT16_MAX, wrap_text); + const auto caret_loc = renderer->get_char_offset(text.c_str(), caret_position, clip_text ? w : -1, wrap_text); caret.set_pos(static_cast(caret_loc.first) + padding_left + x, static_cast(caret_loc.second) + padding_top + y); caret.set_size(1, static_cast(renderer->get_size_px() + 2)); diff --git a/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp b/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp index e1c1a19bf3..c34411b179 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp @@ -414,7 +414,7 @@ namespace rsx std::vector result; f32 unused_x, unused_y; - render_text_ex(result, unused_x, unused_y, text, UINT32_MAX, max_width, wrap); + render_text_ex(result, unused_x, unused_y, text, -1, max_width, wrap); return result; } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_fonts.h b/rpcs3/Emu/RSX/Overlays/overlay_fonts.h index 0f1fd243f5..246562dc3b 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_fonts.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_fonts.h @@ -74,9 +74,9 @@ namespace rsx void render_text_ex(std::vector& result, f32& x_advance, f32& y_advance, const char32_t* text, u32 char_limit, u16 max_width, bool wrap); - std::vector render_text(const char32_t* text, u16 max_width = UINT16_MAX, bool wrap = false); + std::vector render_text(const char32_t* text, u16 max_width = -1, bool wrap = false); - std::pair get_char_offset(const char32_t* text, u16 max_length, u16 max_width = UINT16_MAX, bool wrap = false); + std::pair get_char_offset(const char32_t* text, u16 max_length, u16 max_width = -1, bool wrap = false); bool matches(const char* name, int size) const { return font_name == name && static_cast(size_pt) == size; } std::string_view get_name() const { return font_name; } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_osk.h b/rpcs3/Emu/RSX/Overlays/overlay_osk.h index a90488d549..0778d3e44d 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_osk.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_osk.h @@ -73,7 +73,7 @@ namespace rsx compiled_resource m_cached_resource; u32 flags = 0; - u32 char_limit = UINT32_MAX; + u32 char_limit = umax; std::vector m_panels; usz m_panel_index = 0; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp index 4359a04540..9719c5428f 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp @@ -700,7 +700,7 @@ namespace rsx m_datapoints.push_back(datapoint); // Calculate new min/max - m_min = std::numeric_limits::max(); + m_min = max_v; m_max = 0.0f; // Make sure min/max reflects the data being displayed, not the entire datapoints vector diff --git a/rpcs3/Emu/RSX/Overlays/overlays.h b/rpcs3/Emu/RSX/Overlays/overlays.h index b54ff2dc13..fca363a365 100644 --- a/rpcs3/Emu/RSX/Overlays/overlays.h +++ b/rpcs3/Emu/RSX/Overlays/overlays.h @@ -19,8 +19,8 @@ namespace rsx // Non-interactable UI element struct overlay { - u32 uid = UINT32_MAX; - u32 type_index = UINT32_MAX; + u32 uid = umax; + u32 type_index = umax; u16 virtual_width = 1280; u16 virtual_height = 720; diff --git a/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.h b/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.h index d489f50c76..b16b8f5e45 100644 --- a/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.h +++ b/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.h @@ -11,7 +11,7 @@ struct temp_register bool aliased_h1 = false; bool last_write_half[4] = { false, false, false, false }; - u32 real_index = UINT32_MAX; + u32 real_index = -1; u32 h0_writes = 0u; // Number of writes to the first 64-bits of the register u32 h1_writes = 0u; // Number of writes to the last 64-bits of the register @@ -54,7 +54,7 @@ struct temp_register h1_writes++; } - if (real_index == UINT32_MAX) + if (real_index == umax) { if (half_register) real_index = index >> 1; diff --git a/rpcs3/Emu/RSX/Program/ProgramStateCache.cpp b/rpcs3/Emu/RSX/Program/ProgramStateCache.cpp index c5b15a9f17..24378816d6 100644 --- a/rpcs3/Emu/RSX/Program/ProgramStateCache.cpp +++ b/rpcs3/Emu/RSX/Program/ProgramStateCache.cpp @@ -37,7 +37,7 @@ vertex_program_utils::vertex_program_metadata vertex_program_utils::analyse_vert //u32 first_instruction_address = entry; std::stack call_stack; - std::pair instruction_range = { UINT32_MAX, 0 }; + std::pair instruction_range{umax, 0}; std::bitset<512> instructions_to_patch; bool has_branch_instruction = false; @@ -330,7 +330,7 @@ usz fragment_program_utils::get_fragment_program_ucode_size(const void* ptr) fragment_program_utils::fragment_program_metadata fragment_program_utils::analyse_fragment_program(const void* ptr) { fragment_program_utils::fragment_program_metadata result{}; - result.program_start_offset = UINT32_MAX; + result.program_start_offset = -1; const auto instBuffer = ptr; s32 index = 0; diff --git a/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp b/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp index 66670cf9c4..79af20991c 100644 --- a/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp @@ -439,7 +439,7 @@ std::string VertexProgramDecompiler::Decompile() last_label_addr = *m_prog.jump_table.rbegin(); } - auto find_jump_lvl = [this](u32 address) + auto find_jump_lvl = [this](u32 address) -> u32 { u32 jump = 1; @@ -451,7 +451,7 @@ std::string VertexProgramDecompiler::Decompile() ++jump; } - return UINT32_MAX; + return -1; }; auto do_function_call = [this, &i](const std::string& condition) @@ -509,7 +509,7 @@ std::string VertexProgramDecompiler::Decompile() if (m_prog.entry != m_prog.base_address) { jump_position = find_jump_lvl(m_prog.entry - m_prog.base_address); - ensure(jump_position != UINT32_MAX); + ensure(jump_position != umax); } AddCode(fmt::format("int jump_position = %u;", jump_position)); @@ -547,7 +547,7 @@ std::string VertexProgramDecompiler::Decompile() { //TODO: Subroutines can also have arbitrary jumps! u32 jump_position = find_jump_lvl(i); - if (is_has_BRA || jump_position != UINT32_MAX) + if (is_has_BRA || jump_position != umax) { m_cur_instr->close_scopes++; AddCode("}"); diff --git a/rpcs3/Emu/RSX/RSXFIFO.cpp b/rpcs3/Emu/RSX/RSXFIFO.cpp index 3bae392e03..9829847b73 100644 --- a/rpcs3/Emu/RSX/RSXFIFO.cpp +++ b/rpcs3/Emu/RSX/RSXFIFO.cpp @@ -558,7 +558,7 @@ namespace rsx if (reg >= range.first && reg < range.first + range.second) { const u32 remaining = std::min(fifo_ctrl->get_remaining_args_count() + 1, - (fifo_ctrl->last_cmd() & RSX_METHOD_NON_INCREMENT_CMD_MASK) ? UINT32_MAX : (range.first + range.second) - reg); + (fifo_ctrl->last_cmd() & RSX_METHOD_NON_INCREMENT_CMD_MASK) ? -1 : (range.first + range.second) - reg); commands.back().rsx_command.first = (fifo_ctrl->last_cmd() & RSX_METHOD_NON_INCREMENT_CMD_MASK) | (reg << 2) | (remaining << 18); diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 9e3a56fd6a..9058acfcc5 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -2129,7 +2129,7 @@ namespace rsx const s32 default_frequency_mask = (1 << 8); const s32 swap_storage_mask = (1 << 29); const s32 volatile_storage_mask = (1 << 30); - const s32 modulo_op_frequency_mask = (INT32_MIN); + const s32 modulo_op_frequency_mask = smin; const u32 modulo_mask = rsx::method_registers.frequency_divider_operation_mask(); const auto max_index = (first_vertex + vertex_count) - 1; @@ -3321,17 +3321,17 @@ namespace rsx switch (type) { case CELL_GCM_ZPASS_PIXEL_CNT: - value = value ? UINT16_MAX : 0; + value = value ? u16{umax} : 0; break; case CELL_GCM_ZCULL_STATS3: - value = value ? 0 : UINT16_MAX; + value = value ? 0 : u16{umax}; break; case CELL_GCM_ZCULL_STATS2: case CELL_GCM_ZCULL_STATS1: case CELL_GCM_ZCULL_STATS: default: //Not implemented - value = UINT32_MAX; + value = -1; break; } diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index b1d2f60d92..4002252958 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -486,7 +486,7 @@ namespace rsx virtual void begin_occlusion_query(occlusion_query_info* /*query*/) {} virtual void end_occlusion_query(occlusion_query_info* /*query*/) {} virtual bool check_occlusion_query_status(occlusion_query_info* /*query*/) { return true; } - virtual void get_occlusion_query_result(occlusion_query_info* query) { query->result = UINT32_MAX; } + virtual void get_occlusion_query_result(occlusion_query_info* query) { query->result = -1; } virtual void discard_occlusion_query(occlusion_query_info* /*query*/) {} }; diff --git a/rpcs3/Emu/RSX/VK/VKDraw.cpp b/rpcs3/Emu/RSX/VK/VKDraw.cpp index a1527708b3..404ffa8990 100644 --- a/rpcs3/Emu/RSX/VK/VKDraw.cpp +++ b/rpcs3/Emu/RSX/VK/VKDraw.cpp @@ -983,14 +983,14 @@ void VKGSRender::end() if (m_current_command_buffer->flags & vk::command_buffer::cb_load_occluson_task) { u32 occlusion_id = m_occlusion_query_manager->allocate_query(*m_current_command_buffer); - if (occlusion_id == UINT32_MAX) + if (occlusion_id == umax) { // Force flush rsx_log.error("[Performance Warning] Out of free occlusion slots. Forcing hard sync."); ZCULL_control::sync(this); occlusion_id = m_occlusion_query_manager->allocate_query(*m_current_command_buffer); - if (occlusion_id == UINT32_MAX) + if (occlusion_id == umax) { //rsx_log.error("Occlusion pool overflow"); if (m_current_task) m_current_task->result = 1; diff --git a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp index fb868cd695..c8fe176951 100644 --- a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp @@ -109,7 +109,7 @@ void VKFragmentDecompilerThread::insertOutputs(std::stringstream & OS) if (m_parr.HasParam(PF_PARAM_NONE, reg_type, table[i].second)) { OS << "layout(location=" << std::to_string(output_index++) << ") " << "out vec4 " << table[i].first << ";\n"; - vk_prog->output_color_masks[i] = UINT32_MAX; + vk_prog->output_color_masks[i] = -1; } } } diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.h b/rpcs3/Emu/RSX/VK/VKGSRender.h index 5aafe7b7d0..558043d898 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.h +++ b/rpcs3/Emu/RSX/VK/VKGSRender.h @@ -203,7 +203,7 @@ namespace vk std::vector> buffer_views_to_clean; - u32 present_image = UINT32_MAX; + u32 present_image = -1; command_buffer_chunk* swap_command_buffer = nullptr; //Heap pointers diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.cpp b/rpcs3/Emu/RSX/VK/VKOverlays.cpp index 2d419db032..701cb9ba2c 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.cpp +++ b/rpcs3/Emu/RSX/VK/VKOverlays.cpp @@ -551,7 +551,7 @@ namespace vk for (const auto &res : configuration.texture_raw_data) { - upload_simple_texture(dev, cmd, upload_heap, storage_key++, res->w, res->h, 1, false, false, res->data, UINT32_MAX); + upload_simple_texture(dev, cmd, upload_heap, storage_key++, res->w, res->h, 1, false, false, res->data, -1); } configuration.free_resources(); @@ -615,7 +615,7 @@ namespace vk font->get_glyph_data(bytes); return upload_simple_texture(cmd.get_command_pool().get_owner(), cmd, upload_heap, key, image_size.width, image_size.height, image_size.depth, - true, false, bytes.data(), UINT32_MAX); + true, false, bytes.data(), -1); } vk::image_view* ui_overlay_renderer::find_temp_image(rsx::overlays::image_info* desc, vk::command_buffer& cmd, vk::data_heap& upload_heap, u32 owner_uid) diff --git a/rpcs3/Emu/RSX/VK/VKPresent.cpp b/rpcs3/Emu/RSX/VK/VKPresent.cpp index 4635afb1a6..4439b1438d 100644 --- a/rpcs3/Emu/RSX/VK/VKPresent.cpp +++ b/rpcs3/Emu/RSX/VK/VKPresent.cpp @@ -27,7 +27,7 @@ void VKGSRender::reinitialize_swapchain() for (auto &ctx : frame_context_storage) { - if (ctx.present_image == UINT32_MAX) + if (ctx.present_image == umax) continue; // Release present image by presenting it @@ -77,7 +77,7 @@ void VKGSRender::reinitialize_swapchain() void VKGSRender::present(vk::frame_context_t *ctx) { - ensure(ctx->present_image != UINT32_MAX); + ensure(ctx->present_image != umax); // Partial CS flush ctx->swap_command_buffer->flush(); @@ -100,7 +100,7 @@ void VKGSRender::present(vk::frame_context_t *ctx) } // Presentation image released; reset value - ctx->present_image = UINT32_MAX; + ctx->present_image = -1; } void VKGSRender::advance_queued_frames() @@ -498,7 +498,7 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info) } // Prepare surface for new frame. Set no timeout here so that we wait for the next image if need be - ensure(m_current_frame->present_image == UINT32_MAX); + ensure(m_current_frame->present_image == umax); ensure(m_current_frame->swap_command_buffer == nullptr); u64 timeout = m_swapchain->get_swap_image_count() <= VK_MAX_ASYNC_FRAMES? 0ull: 100000000ull; @@ -541,7 +541,7 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info) } // Confirm that the driver did not silently fail - ensure(m_current_frame->present_image != UINT32_MAX); + ensure(m_current_frame->present_image != umax); // Calculate output dimensions. Done after swapchain acquisition in case it was recreated. coordi aspect_ratio; diff --git a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp index 3b2fe975f8..4a48c45de4 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp @@ -178,11 +178,11 @@ namespace { if (index_type == rsx::index_array_type::u16) { - index_count = rsx::remove_restart_index(static_cast(buf), reinterpret_cast(tmp.data()), index_count, u16{UINT16_MAX}); + index_count = rsx::remove_restart_index(static_cast(buf), reinterpret_cast(tmp.data()), index_count, u16{umax}); } else { - index_count = rsx::remove_restart_index(static_cast(buf), reinterpret_cast(tmp.data()), index_count, u32{UINT32_MAX}); + index_count = rsx::remove_restart_index(static_cast(buf), reinterpret_cast(tmp.data()), index_count, u32{umax}); } } @@ -238,8 +238,8 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() //Do actual vertex upload auto required = calculate_memory_requirements(m_vertex_layout, vertex_base, vertex_count); - u32 persistent_range_base = UINT32_MAX, volatile_range_base = UINT32_MAX; - usz persistent_offset = UINT64_MAX, volatile_offset = UINT64_MAX; + u32 persistent_range_base = -1, volatile_range_base = -1; + usz persistent_offset = -1, volatile_offset = -1; if (required.first > 0) { @@ -248,7 +248,7 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() //TODO: make vertex cache keep local data beyond frame boundaries and hook notify command bool in_cache = false; bool to_store = false; - u32 storage_address = UINT32_MAX; + u32 storage_address = -1; if (m_vertex_layout.interleaved_blocks.size() == 1 && rsx::method_registers.current_draw_clause.command != rsx::draw_command::inlined_array) @@ -302,7 +302,7 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() } else { - if (required.first > 0 && persistent_offset != UINT64_MAX) + if (required.first > 0 && persistent_offset != umax) { void *persistent_mapping = m_attrib_ring_info.map(persistent_offset, required.first); write_vertex_data_to_memory(m_vertex_layout, vertex_base, vertex_count, persistent_mapping, nullptr); @@ -335,7 +335,7 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() vk::clear_status_interrupt(vk::heap_changed); } - if (persistent_range_base != UINT32_MAX) + if (persistent_range_base != umax) { if (!m_persistent_attribute_storage || !m_persistent_attribute_storage->in_range(persistent_range_base, required.first, persistent_range_base)) { @@ -351,7 +351,7 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() } } - if (volatile_range_base != UINT32_MAX) + if (volatile_range_base != umax) { if (!m_volatile_attribute_storage || !m_volatile_attribute_storage->in_range(volatile_range_base, required.second, volatile_range_base)) { diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.cpp b/rpcs3/Emu/RSX/VK/vkutils/device.cpp index fdb28b0322..086d8e0a0f 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/device.cpp @@ -426,7 +426,7 @@ namespace vk vkGetDeviceQueue(dev, graphics_queue_idx, 0, &m_graphics_queue); vkGetDeviceQueue(dev, transfer_queue_idx, transfer_queue_sub_index, &m_transfer_queue); - if (present_queue_idx != UINT32_MAX) + if (present_queue_idx != umax) { vkGetDeviceQueue(dev, present_queue_idx, 0, &m_present_queue); } diff --git a/rpcs3/Emu/RSX/VK/vkutils/instance.hpp b/rpcs3/Emu/RSX/VK/vkutils/instance.hpp index ab944c6376..4bf3ecdcef 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/instance.hpp +++ b/rpcs3/Emu/RSX/VK/vkutils/instance.hpp @@ -321,9 +321,9 @@ namespace vk vkGetPhysicalDeviceSurfaceSupportKHR(dev, index, m_surface, &supports_present[index]); } - u32 graphics_queue_idx = UINT32_MAX; - u32 present_queue_idx = UINT32_MAX; - u32 transfer_queue_idx = UINT32_MAX; + u32 graphics_queue_idx = -1; + u32 present_queue_idx = -1; + u32 transfer_queue_idx = -1; auto test_queue_family = [&](u32 index, u32 desired_flags) { @@ -339,7 +339,7 @@ namespace vk for (u32 i = 0; i < device_queues; ++i) { // 1. Test for a present queue possibly one that also supports present - if (present_queue_idx == UINT32_MAX && supports_present[i]) + if (present_queue_idx == umax && supports_present[i]) { present_queue_idx = i; if (test_queue_family(i, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT)) @@ -348,7 +348,7 @@ namespace vk } } // 2. Check for graphics support - else if (graphics_queue_idx == UINT32_MAX && test_queue_family(i, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT)) + else if (graphics_queue_idx == umax && test_queue_family(i, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT)) { graphics_queue_idx = i; if (supports_present[i]) @@ -357,13 +357,13 @@ namespace vk } } // 3. Check if transfer + compute is available - else if (transfer_queue_idx == UINT32_MAX && test_queue_family(i, VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT)) + else if (transfer_queue_idx == umax && test_queue_family(i, VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT)) { transfer_queue_idx = i; } } - if (graphics_queue_idx == UINT32_MAX) + if (graphics_queue_idx == umax) { rsx_log.fatal("Failed to find a suitable graphics queue"); return nullptr; @@ -380,7 +380,7 @@ namespace vk //Native(sw) swapchain rsx_log.error("It is not possible for the currently selected GPU to present to the window (Likely caused by NVIDIA driver running the current display)"); rsx_log.warning("Falling back to software present support (native windowing API)"); - auto swapchain = new swapchain_NATIVE(dev, UINT32_MAX, graphics_queue_idx, transfer_queue_idx); + auto swapchain = new swapchain_NATIVE(dev, -1, graphics_queue_idx, transfer_queue_idx); swapchain->create(window_handle); return swapchain; } diff --git a/rpcs3/Emu/RSX/VK/vkutils/swapchain.hpp b/rpcs3/Emu/RSX/VK/vkutils/swapchain.hpp index f8f5655669..d2f201f57d 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/swapchain.hpp +++ b/rpcs3/Emu/RSX/VK/vkutils/swapchain.hpp @@ -621,7 +621,7 @@ namespace vk return false; } - if (surface_descriptors.currentExtent.width != UINT32_MAX) + if (surface_descriptors.currentExtent.width != umax) { if (surface_descriptors.currentExtent.width == 0 || surface_descriptors.currentExtent.height == 0) { diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index cde688c70d..ecc2301287 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -367,7 +367,7 @@ namespace rsx for (u8 index = 0; index < 32; ++index) { const auto address = data.vp_jump_table[index]; - if (address == UINT16_MAX) + if (address == u16{umax}) { // End of list marker break; @@ -415,7 +415,7 @@ namespace rsx else { // End of list marker - data_block.vp_jump_table[index] = UINT16_MAX; + data_block.vp_jump_table[index] = u16{umax}; break; } } diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 99eafd3398..3c06b26a1b 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -33,7 +33,6 @@ DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResoluti #include #include #include -#include #endif #ifdef __linux__ diff --git a/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp b/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp index 97d1f36098..8353cf13a7 100644 --- a/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp @@ -278,7 +278,7 @@ void AutoPauseConfigDialog::OnUpdateValue() const { bool ok; const ullong value = m_id->text().toULongLong(&ok, 16); - const bool is_ok = ok && value <= UINT32_MAX; + const bool is_ok = ok && value <= u32{umax}; m_current_converted->setText(tr("Current value: %1 (%2)").arg(value, 8, 16).arg(is_ok ? tr("OK") : tr("Conversion failed"))); } diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index 1e3971936f..0086b1b6de 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -478,7 +478,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) // Next instruction according to code flow // Known branch targets are selected over next PC for conditional branches // Indirect branches (unknown targets, such as function return) do not proceed to any instruction - std::array res{UINT32_MAX, UINT32_MAX}; + std::array res{umax, umax}; switch (cpu->id_type()) { @@ -499,7 +499,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) default: break; } - if (const size_t pos = std::basic_string_view(res.data(), 2).find_last_not_of(UINT32_MAX); pos != umax) + if (const size_t pos = std::basic_string_view(res.data(), 2).find_last_not_of(umax); pos != umax) m_debugger_list->ShowAddress(res[pos] - std::max(row, 0) * 4, true, true); return; @@ -562,7 +562,7 @@ cpu_thread* debugger_frame::get_cpu() std::function debugger_frame::make_check_cpu(cpu_thread* cpu) { - const u32 id = cpu ? cpu->id : UINT32_MAX; + const u32 id = cpu ? cpu->id : umax; const u32 type = id >> 24; std::shared_ptr shared = type == 1 ? static_cast>(idm::get>(id)) : diff --git a/rpcs3/rpcs3qt/instruction_editor_dialog.cpp b/rpcs3/rpcs3qt/instruction_editor_dialog.cpp index 43dbcc063f..241fc3a13e 100644 --- a/rpcs3/rpcs3qt/instruction_editor_dialog.cpp +++ b/rpcs3/rpcs3qt/instruction_editor_dialog.cpp @@ -84,7 +84,7 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C bool ok; const ulong opcode = m_instr->text().toULong(&ok, 16); - if (!ok || opcode > UINT32_MAX) + if (!ok || opcode > u32{umax}) { QMessageBox::critical(this, tr("Error"), tr("Failed to parse PPU instruction.")); return; diff --git a/rpcs3/rpcs3qt/kernel_explorer.cpp b/rpcs3/rpcs3qt/kernel_explorer.cpp index f92fdba5f7..e9d530c430 100644 --- a/rpcs3/rpcs3qt/kernel_explorer.cpp +++ b/rpcs3/rpcs3qt/kernel_explorer.cpp @@ -574,7 +574,7 @@ void kernel_explorer::Update() const auto first_spu = spu.group->threads[0].get(); // Always show information of the first thread in group - // Or if information differs from that thread + // Or if information differs from that thread if (&spu == first_spu || std::any_of(std::begin(spu.spup), std::end(spu.spup), [&](const auto& port) { // Flag to avoid reporting information if no SPU ports are connected @@ -597,7 +597,7 @@ void kernel_explorer::Update() // Avoid duplication of information between threads which is common add_leaf(spu_thread_tree, qstr(fmt::format("SPU Ports: As SPU 0x%07x", first_spu->lv2_id))); } - + for (const auto& [key, queue] : spu.spuq) { if (lv2_obj::check(queue)) @@ -635,7 +635,7 @@ void kernel_explorer::Update() if (!pspurs) { - if (arg < UINT32_MAX && arg % 0x80 == 0 && vm::check_addr(arg, vm::page_readable, pspurs.size())) + if (arg < u32{umax} && arg % 0x80 == 0 && vm::check_addr(arg, vm::page_readable, pspurs.size())) { pspurs.set(static_cast(arg)); } diff --git a/rpcs3/rpcs3qt/log_frame.cpp b/rpcs3/rpcs3qt/log_frame.cpp index c564d7c76f..8b6d3b9035 100644 --- a/rpcs3/rpcs3qt/log_frame.cpp +++ b/rpcs3/rpcs3qt/log_frame.cpp @@ -26,7 +26,7 @@ constexpr auto qstr = QString::fromStdString; struct gui_listener : logs::listener { - atomic_t enabled{logs::level{UCHAR_MAX}}; + atomic_t enabled{logs::level{0xff}}; struct packet_t { diff --git a/rpcs3/rpcs3qt/memory_string_searcher.cpp b/rpcs3/rpcs3qt/memory_string_searcher.cpp index 4c7fedf370..20715c5a63 100644 --- a/rpcs3/rpcs3qt/memory_string_searcher.cpp +++ b/rpcs3/rpcs3qt/memory_string_searcher.cpp @@ -254,7 +254,7 @@ void memory_string_searcher::OnSearch() u64 addr_max = addr; - const u64 end_mem = std::min(utils::align(addr + 1, block_size) + 0x1000, UINT32_MAX); + const u64 end_mem = std::min(utils::align(addr + 1, block_size) + 0x1000, u32{umax}); // Determine allocation size quickly while (addr_max < end_mem && vm::check_addr(static_cast(addr_max), vm::page_1m_size)) @@ -294,7 +294,7 @@ void memory_string_searcher::OnSearch() // Allow overlapping strings first_char++; } - } + } else { while (first_char = section.find_first_of(wstr[0], first_char), first_char != umax) diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index 5c0cf30452..3ed968736f 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -505,141 +505,170 @@ struct get_int_impl<16> using stype = s128; }; +enum class f16 : u16{}; + +using f32 = float; +using f64 = double; + +template +concept UnsignedInt = std::is_unsigned_v> || std::is_same_v, u128>; + +template +concept SignedInt = (std::is_signed_v> && std::is_integral_v>) || std::is_same_v, s128>; + +template +concept FPInt = std::is_floating_point_v> || std::is_same_v, f16>; + +template +constexpr T min_v; + +template +constexpr std::common_type_t min_v = 0; + +template +constexpr std::common_type_t min_v = static_cast>(-1) << (sizeof(std::common_type_t) * 8 - 1); + +template <> +constexpr inline f16 min_v{0xfbffu}; + +template <> +constexpr inline f32 min_v = std::bit_cast(0xff'7fffffu); + +template <> +constexpr inline f64 min_v = std::bit_cast(0xffe'7ffff'ffffffffu); + +template +constexpr std::common_type_t min_v = min_v>; + +template +constexpr T max_v; + +template +constexpr std::common_type_t max_v = -1; + +template +constexpr std::common_type_t max_v = static_cast>(~min_v); + +template <> +constexpr inline f16 max_v{0x7bffu}; + +template <> +constexpr inline f32 max_v = std::bit_cast(0x7f'7fffffu); + +template <> +constexpr inline f64 max_v = std::bit_cast(0x7fe'fffff'ffffffffu); + +template +constexpr std::common_type_t max_v = max_v>; + // Return magic value for any unsigned type constexpr struct umax_impl_t { - template - static constexpr T value = static_cast(-1); - - template > requires (std::is_unsigned_v) || (std::is_same_v) + template constexpr bool operator==(const T& rhs) const { - return rhs == value; + return rhs == max_v; } - template > requires (std::is_unsigned_v) || (std::is_same_v) + template constexpr std::strong_ordering operator<=>(const T& rhs) const { - return rhs == value ? std::strong_ordering::equal : std::strong_ordering::greater; + return rhs == max_v ? std::strong_ordering::equal : std::strong_ordering::greater; } - template > requires (std::is_unsigned_v) || (std::is_same_v) + template constexpr operator T() const { - return value; + return max_v; } } umax; constexpr struct smin_impl_t { - template - static constexpr T value = static_cast(-1) << (sizeof(T) * 8 - 1); - - template > requires (std::is_signed_v) || (std::is_same_v) + template constexpr bool operator==(const T& rhs) const { - return rhs == value; + return rhs == min_v; } - template > requires (std::is_signed_v) || (std::is_same_v) + template constexpr std::strong_ordering operator<=>(const T& rhs) const { - return rhs == value ? std::strong_ordering::equal : std::strong_ordering::less; + return rhs == min_v ? std::strong_ordering::equal : std::strong_ordering::less; } - template > requires (std::is_signed_v) || (std::is_same_v) + template constexpr operator T() const { - return value; + return min_v; } } smin; constexpr struct smax_impl_t { - template - static constexpr T value = static_cast(~smin_impl_t::value); - - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template constexpr bool operator==(const T& rhs) const { - return rhs == value; + return rhs == max_v; } - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template constexpr std::strong_ordering operator<=>(const T& rhs) const { - if constexpr (std::is_signed_v || std::is_same_v) - { - return rhs == value ? std::strong_ordering::equal : std::strong_ordering::greater; - } - else - { - return value <=> rhs; - } + return rhs == max_v ? std::strong_ordering::equal : std::strong_ordering::greater; } - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template constexpr operator T() const { - return value; + return max_v; } } smax; // Compare signed or unsigned type with its max value constexpr struct amax_impl_t { - template - static constexpr T value = (std::is_unsigned_v || std::is_same_v) ? umax_impl_t::value : smax_impl_t::value; - - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template requires SignedInt || UnsignedInt constexpr bool operator ==(const T& rhs) const { - return rhs == value; + return rhs == max_v; } - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template requires SignedInt || UnsignedInt constexpr std::strong_ordering operator <=>(const T& rhs) const { - return value <=> rhs; + return max_v <=> rhs; } - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template requires SignedInt || UnsignedInt constexpr operator T() const { - return value; + return max_v; } } amax; // Compare signed or unsigned type with its minimal value (like zero or INT_MIN) constexpr struct amin_impl_t { - template - static constexpr T value = (std::is_signed_v || std::is_same_v) ? smin_impl_t::value : 0; - - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template requires SignedInt || UnsignedInt constexpr bool operator ==(const T& rhs) const { - return rhs == value; + return rhs == min_v; } - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template requires SignedInt || UnsignedInt constexpr std::strong_ordering operator <=>(const T& rhs) const { - return value <=> rhs; + return min_v <=> rhs; } - template > requires (std::is_integral_v) || (std::is_same_v) || (std::is_same_v) + template requires SignedInt || UnsignedInt constexpr operator T() const { - return value; + return min_v; } } amin; -enum class f16 : u16{}; - -using f32 = float; -using f64 = double; - template inline u32 offset32(T T2::*const mptr) {