mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-13 07:14:49 +00:00
Remove ASSUME macro
It's dangerous and sometimes bluntly misused feature. Its optimization potential is near-zero.
This commit is contained in:
parent
61b882b2a6
commit
b382d3b3e9
@ -372,8 +372,6 @@ public:
|
||||
// Try to abort by assigning thread_state::aborting (UB if assigning different state)
|
||||
named_thread& operator=(thread_state s)
|
||||
{
|
||||
ASSUME(s == thread_state::aborting);
|
||||
|
||||
if (s == thread_state::aborting && thread::m_sync.fetch_op([](u64& v){ return !(v & 3) && (v |= 1); }).second)
|
||||
{
|
||||
if (s == thread_state::aborting)
|
||||
|
@ -372,7 +372,6 @@ namespace utils
|
||||
template <typename D = std::remove_reference_t<T>>
|
||||
auto get() const noexcept
|
||||
{
|
||||
ASSUME(m_block->m_type != 0);
|
||||
return m_block->get_ptr<T>();
|
||||
}
|
||||
|
||||
|
@ -29,28 +29,13 @@
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define ASSUME(...) ((__VA_ARGS__) ? void() : __assume(0)) // MSVC __assume ignores side-effects
|
||||
#define SAFE_BUFFERS __declspec(safebuffers)
|
||||
#define NEVER_INLINE __declspec(noinline)
|
||||
#define FORCE_INLINE __forceinline
|
||||
|
||||
#else // not _MSC_VER
|
||||
|
||||
#ifdef __clang__
|
||||
#if defined(__has_builtin) && __has_builtin(__builtin_assume)
|
||||
#define ASSUME(...) ((__VA_ARGS__) ? void() : __builtin_assume(0)) // __builtin_assume (supported by modern clang) ignores side-effects
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ASSUME // gcc and old clang
|
||||
#define ASSUME(...) ((__VA_ARGS__) ? void() : __builtin_unreachable()) // note: the compiler will generate code to evaluate "cond" if the expression is opaque
|
||||
#endif
|
||||
|
||||
#define SAFE_BUFFERS __attribute__((no_stack_protector))
|
||||
#define NEVER_INLINE __attribute__((noinline)) inline
|
||||
#define FORCE_INLINE __attribute__((always_inline)) inline
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
#define CHECK_SIZE(type, size) static_assert(sizeof(type) == size, "Invalid " #type " type size")
|
||||
|
@ -18,7 +18,7 @@ protected:
|
||||
|
||||
virtual void Write(const std::string& value)
|
||||
{
|
||||
switch(m_mode)
|
||||
switch (m_mode)
|
||||
{
|
||||
case CPUDisAsm_DumpMode:
|
||||
{
|
||||
@ -50,7 +50,7 @@ protected:
|
||||
last_opcode = value;
|
||||
break;
|
||||
}
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -594,7 +594,7 @@ error_code cellGameDataCheck(u32 type, vm::cptr<char> dirName, vm::ptr<CellGameC
|
||||
case CELL_GAME_GAMETYPE_HDD: return "HG"sv;
|
||||
case CELL_GAME_GAMETYPE_GAMEDATA: return "GD"sv;
|
||||
case CELL_GAME_GAMETYPE_DISC: return "DG"sv;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}())
|
||||
{
|
||||
|
@ -367,7 +367,7 @@ static s32 savedata_check_args(u32 operation, u32 version, vm::cptr<char> dirNam
|
||||
return 4;
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,7 +426,7 @@ static s32 savedata_check_args(u32 operation, u32 version, vm::cptr<char> dirNam
|
||||
return 17;
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -776,7 +776,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
|
||||
break;
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
selected_list.emplace(listSet->fixedList[i].dirName);
|
||||
@ -826,7 +826,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
|
||||
break;
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -858,7 +858,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
|
||||
break;
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
const std::string dirStr = listSet->focusDirName.get_ptr();
|
||||
@ -1114,7 +1114,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
|
||||
return {CELL_SAVEDATA_ERROR_PARAM, "28"};
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
const std::string dirStr = fixedSet->dirName.get_ptr();
|
||||
@ -1973,7 +1973,7 @@ static NEVER_INLINE error_code savedata_get_list_item(vm::cptr<char> dirName, vm
|
||||
return {CELL_SAVEDATA_ERROR_PARAM, "109"};
|
||||
}
|
||||
case 0: break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
const std::string base_dir = fmt::format("/dev_hdd0/home/%08u/savedata/", userId);
|
||||
|
@ -69,7 +69,7 @@ constexpr std::pair<const char*, char> get_BC_info(u32 bo, u32 bi)
|
||||
case 0x1: info.first = "ble"; break;
|
||||
case 0x2: info.first = "bne"; break;
|
||||
case 0x3: info.first = "bns"; break;
|
||||
default: ASSUME(0); break;
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -82,7 +82,7 @@ constexpr std::pair<const char*, char> get_BC_info(u32 bo, u32 bi)
|
||||
case 0x1: info.first = "ble"; break;
|
||||
case 0x2: info.first = "bne"; break;
|
||||
case 0x3: info.first = "bns"; break;
|
||||
default: ASSUME(0); break;
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -95,7 +95,7 @@ constexpr std::pair<const char*, char> get_BC_info(u32 bo, u32 bi)
|
||||
case 0x1: info.first = "ble"; break;
|
||||
case 0x2: info.first = "bne"; break;
|
||||
case 0x3: info.first = "bns"; break;
|
||||
default: ASSUME(0); break;
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -107,7 +107,7 @@ constexpr std::pair<const char*, char> get_BC_info(u32 bo, u32 bi)
|
||||
case 0x1: info.first = "bgt"; break;
|
||||
case 0x2: info.first = "beq"; break;
|
||||
case 0x3: info.first = "bso"; break;
|
||||
default: ASSUME(0); break;
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -120,7 +120,7 @@ constexpr std::pair<const char*, char> get_BC_info(u32 bo, u32 bi)
|
||||
case 0x1: info.first = "bgt"; break;
|
||||
case 0x2: info.first = "beq"; break;
|
||||
case 0x3: info.first = "bso"; break;
|
||||
default: ASSUME(0); break;
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -133,7 +133,7 @@ constexpr std::pair<const char*, char> get_BC_info(u32 bo, u32 bi)
|
||||
case 0x1: info.first = "bgt"; break;
|
||||
case 0x2: info.first = "beq"; break;
|
||||
case 0x3: info.first = "bso"; break;
|
||||
default: ASSUME(0); break;
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ private:
|
||||
case 0x1: return "gt";
|
||||
case 0x2: return "eq";
|
||||
case 0x3: return "so";
|
||||
default: ASSUME(0); return {};
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ private:
|
||||
{
|
||||
Write(fmt::format("%s cr%d[%s],0x%x ", FixOp(op), bi / 4, get_partial_BI_field(bi), pc));
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
u32 disasm(u32 pc) override;
|
||||
|
||||
|
@ -88,7 +88,7 @@ std::pair<bool, v128> SPUDisAsm::try_get_const_value(u32 reg, u32 pc) const
|
||||
case spu_itype::CHD: size = 2; break;
|
||||
case spu_itype::CWD: size = 4; break;
|
||||
case spu_itype::CDD: size = 8; break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
const u32 index = (~op0.i7 & 0xf) / size;
|
||||
@ -100,7 +100,7 @@ std::pair<bool, v128> SPUDisAsm::try_get_const_value(u32 reg, u32 pc) const
|
||||
case 2: res._u16[index] = 0x0203; break;
|
||||
case 4: res._u32[index] = 0x00010203; break;
|
||||
case 8: res._u64[index] = 0x0001020304050607ull; break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
return {true, res};
|
||||
|
@ -3516,8 +3516,6 @@ retry:
|
||||
|
||||
void spu_thread::set_events(u32 bits)
|
||||
{
|
||||
ASSUME(!(bits & ~0xffff));
|
||||
|
||||
if (ch_events.atomic_op([&](ch_events_t& events)
|
||||
{
|
||||
events.events |= bits;
|
||||
|
@ -1271,7 +1271,7 @@ error_code sys_spu_thread_write_ls(ppu_thread& ppu, u32 id, u32 lsa, u64 value,
|
||||
case 2: thread->_ref<u16>(lsa) = static_cast<u16>(value); break;
|
||||
case 4: thread->_ref<u32>(lsa) = static_cast<u32>(value); break;
|
||||
case 8: thread->_ref<u64>(lsa) = value; break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
return CELL_OK;
|
||||
@ -1314,7 +1314,7 @@ error_code sys_spu_thread_read_ls(ppu_thread& ppu, u32 id, u32 lsa, vm::ptr<u64>
|
||||
case 2: *value = thread->_ref<u16>(lsa); break;
|
||||
case 4: *value = thread->_ref<u32>(lsa); break;
|
||||
case 8: *value = thread->_ref<u64>(lsa); break;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
return CELL_OK;
|
||||
|
@ -310,8 +310,6 @@ namespace vm
|
||||
{
|
||||
to_clear = for_all_range_locks(to_clear, [&](u32 addr2, u32 size2)
|
||||
{
|
||||
ASSUME(size2);
|
||||
|
||||
if (range.overlaps(utils::address_range::start_length(addr2, size2))) [[unlikely]]
|
||||
{
|
||||
return 1;
|
||||
|
@ -862,8 +862,7 @@ namespace rsx
|
||||
case rsx::surface_antialiasing::square_rotated_4_samples:
|
||||
return 4;
|
||||
default:
|
||||
ASSUME(0);
|
||||
return 0;
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1083,7 +1082,7 @@ namespace rsx
|
||||
case rsx::surface_depth_format2::z24s8_float:
|
||||
return{ CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT, true };
|
||||
default:
|
||||
ASSUME(0);
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace rsx {
|
||||
case utils::protection::no: return no > 0;
|
||||
case utils::protection::ro: return no == 0 && ro > 0;
|
||||
case utils::protection::rw: return no == 0 && ro == 0;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ namespace rsx {
|
||||
{
|
||||
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;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ namespace rsx {
|
||||
{
|
||||
case utils::protection::no: if (no-- == 0) fmt::throw_exception("remove(protection::no) overflow with NO==0"); return;
|
||||
case utils::protection::ro: if (ro-- == 0) fmt::throw_exception("remove(protection::ro) overflow with RO==0"); return;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -694,7 +694,6 @@ namespace gl
|
||||
}
|
||||
default:
|
||||
{
|
||||
ASSUME(0);
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ namespace rsx
|
||||
rsx::get_current_renderer()->renderctl(job.aux_param0, job.src);
|
||||
break;
|
||||
}
|
||||
default: ASSUME(0); fmt::throw_exception("Unreachable");
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
m_processed_count.release(m_processed_count + 1);
|
||||
@ -224,7 +224,6 @@ namespace rsx
|
||||
range = get_index_count(static_cast<rsx::primitive_type>(m_current_job->aux_param0), m_current_job->length);
|
||||
break;
|
||||
default:
|
||||
ASSUME(0);
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ namespace rsx
|
||||
case rsx::texture_dimension::dimension3d: return rsx::texture_dimension_extended::texture_dimension_3d;
|
||||
case rsx::texture_dimension::dimension2d: return cubemap() ? rsx::texture_dimension_extended::texture_dimension_cubemap : rsx::texture_dimension_extended::texture_dimension_2d;
|
||||
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,7 +351,7 @@ namespace rsx
|
||||
case rsx::texture_dimension::dimension3d: return rsx::texture_dimension_extended::texture_dimension_3d;
|
||||
case rsx::texture_dimension::dimension2d: return cubemap() ? rsx::texture_dimension_extended::texture_dimension_cubemap : rsx::texture_dimension_extended::texture_dimension_2d;
|
||||
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace vk
|
||||
return VK_IMAGE_VIEW_TYPE_CUBE;
|
||||
case rsx::texture_dimension_extended::texture_dimension_3d:
|
||||
return VK_IMAGE_VIEW_TYPE_3D;
|
||||
default: ASSUME(0);
|
||||
default: fmt::throw_exception("Unreachable");
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,9 @@ namespace vk
|
||||
case rsx::texture_minify_filter::linear_linear: return { VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_LINEAR, true };
|
||||
case rsx::texture_minify_filter::convolution_min: return { VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST, false };
|
||||
default:
|
||||
ASSUME(0);
|
||||
break;
|
||||
}
|
||||
|
||||
fmt::throw_exception("Invalid min filter");
|
||||
}
|
||||
|
||||
@ -93,9 +93,9 @@ namespace vk
|
||||
case rsx::texture_magnify_filter::linear: return VK_FILTER_LINEAR;
|
||||
case rsx::texture_magnify_filter::convolution_mag: return VK_FILTER_LINEAR;
|
||||
default:
|
||||
ASSUME(0);
|
||||
break;
|
||||
}
|
||||
|
||||
fmt::throw_exception("Invalid mag filter (0x%x)", static_cast<u32>(mag_filter));
|
||||
}
|
||||
|
||||
@ -147,10 +147,10 @@ namespace vk
|
||||
case rsx::texture_wrap_mode::mirror_once_border: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
|
||||
case rsx::texture_wrap_mode::mirror_once_clamp: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
|
||||
default:
|
||||
ASSUME(0);
|
||||
break;
|
||||
}
|
||||
fmt::throw_exception("unhandled texture clamp mode");
|
||||
|
||||
fmt::throw_exception("Unhandled texture clamp mode");
|
||||
}
|
||||
|
||||
float max_aniso(rsx::texture_max_anisotropy gcm_aniso)
|
||||
@ -166,7 +166,6 @@ namespace vk
|
||||
case rsx::texture_max_anisotropy::x12: return 12.0f;
|
||||
case rsx::texture_max_anisotropy::x16: return 16.0f;
|
||||
default:
|
||||
ASSUME(0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1662,8 +1662,7 @@ private:
|
||||
info.viewType = VK_IMAGE_VIEW_TYPE_3D;
|
||||
break;
|
||||
default:
|
||||
ASSUME(0);
|
||||
break;
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
info.subresourceRange.layerCount = resource->info.arrayLayers;
|
||||
|
@ -1146,8 +1146,7 @@ namespace vk
|
||||
layer = 1;
|
||||
break;
|
||||
default:
|
||||
ASSUME(0);
|
||||
break;
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
|
||||
auto *image = new vk::viewable_image(*m_device, m_memory_types.device_local, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
|
@ -76,8 +76,8 @@ namespace rsx
|
||||
return (rhs == surface_depth_format2::z16_uint || rhs == surface_depth_format2::z16_float);
|
||||
case surface_depth_format::z24s8:
|
||||
return (rhs == surface_depth_format2::z24s8_uint || rhs == surface_depth_format2::z24s8_float);
|
||||
default:
|
||||
ASSUME(0);
|
||||
[[unlikely]] default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ namespace rsx
|
||||
case section_bounds::confirmed_range:
|
||||
return confirmed_range.valid() ? confirmed_range : cpu_range;
|
||||
default:
|
||||
ASSUME(0);
|
||||
fmt::throw_exception("Unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user