From a8e0d261b7b8ce14d7a731f7f803cfded895c4d2 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Tue, 22 Dec 2020 18:04:08 +0300 Subject: [PATCH] types.hpp: more cleanup Also fix compilation. --- Utilities/File.cpp | 2 +- Utilities/StrFmt.cpp | 6 +++ Utilities/StrFmt.h | 22 -------- Utilities/sync.h | 2 +- rpcs3/Emu/Cell/Modules/libmixer.cpp | 2 +- rpcs3/Emu/Io/KeyboardHandler.h | 1 + rpcs3/Emu/Io/MouseHandler.h | 1 + rpcs3/Emu/Io/PadHandler.h | 8 ++- rpcs3/Emu/NP/np_handler.h | 1 + rpcs3/Emu/RSX/Capture/rsx_replay.h | 1 + rpcs3/Emu/RSX/Common/ProgramStateCache.h | 1 + rpcs3/Emu/RSX/Common/ShaderParam.h | 2 + rpcs3/Emu/RSX/Common/surface_store.h | 2 + rpcs3/Emu/RSX/Common/texture_cache.h | 2 + .../Emu/RSX/Common/texture_cache_predictor.h | 2 + rpcs3/Emu/RSX/GL/GLCompute.h | 1 + rpcs3/Emu/RSX/GL/GLGSRender.h | 1 + rpcs3/Emu/RSX/GL/GLHelpers.cpp | 2 + rpcs3/Emu/RSX/GL/GLOverlays.h | 1 + rpcs3/Emu/RSX/GL/GLShaderInterpreter.h | 2 + rpcs3/Emu/RSX/GL/GLTextOut.h | 1 + rpcs3/Emu/RSX/GL/GLTexture.h | 2 + rpcs3/Emu/RSX/GL/GLVertexProgram.h | 2 + rpcs3/Emu/RSX/Overlays/overlay_utils.cpp | 2 + rpcs3/Emu/RSX/RSXThread.h | 1 + rpcs3/Emu/RSX/VK/VKCompute.h | 1 + rpcs3/Emu/RSX/VK/VKDMA.cpp | 1 + rpcs3/Emu/RSX/VK/VKFramebuffer.cpp | 1 + rpcs3/Emu/RSX/VK/VKHelpers.cpp | 1 + rpcs3/Emu/RSX/VK/VKOverlays.h | 1 + rpcs3/Emu/RSX/VK/VKResourceManager.h | 4 ++ rpcs3/Emu/RSX/VK/VKShaderInterpreter.h | 1 + rpcs3/Emu/RSX/VK/VKTextOut.h | 1 + rpcs3/Emu/RSX/rsx_cache.h | 2 +- rpcs3/Input/ds3_pad_handler.h | 2 + rpcs3/Input/ds4_pad_handler.h | 2 + rpcs3/Input/dualsense_pad_handler.h | 2 + rpcs3/Input/xinput_pad_handler.h | 3 ++ rpcs3/rpcs3qt/game_list_frame.cpp | 1 + rpcs3/rpcs3qt/patch_manager_dialog.h | 1 + rpcs3/rpcs3qt/rsx_debugger.cpp | 19 +++++-- rpcs3/util/types.hpp | 53 ++----------------- 42 files changed, 88 insertions(+), 78 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index f1f52ae816..9ea37fbad0 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1715,7 +1715,7 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment) if (!root_dir) { - return static_cast(umax); + return -1; } for (const auto& entry : root_dir) diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 488508a862..4420e76d7c 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -236,6 +236,12 @@ void fmt_class_string::format(std::string& out, u64 arg) out += arg ? "true" : "false"; } +template <> +void fmt_class_string::format(std::string& out, u64 arg) +{ + out += get_object(arg) ? "true" : "false"; +} + template <> void fmt_class_string::format(std::string& out, u64 arg) { diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 599b0f86df..551344aac3 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -64,17 +64,6 @@ struct fmt_unveil::value && sizeof } }; -template <> -struct fmt_unveil -{ - using type = f16; - - static inline u64 get(const f16& arg) - { - return fmt_unveil::get(arg.operator float()); - } -}; - template struct fmt_unveil::value>> { @@ -108,17 +97,6 @@ struct fmt_unveil } }; -template <> -struct fmt_unveil -{ - using type = bool; - - static inline u64 get(const b8& value) - { - return fmt_unveil::get(value); - } -}; - template struct fmt_unveil, void> { diff --git a/Utilities/sync.h b/Utilities/sync.h index 8370369c04..96b610ddb2 100644 --- a/Utilities/sync.h +++ b/Utilities/sync.h @@ -71,7 +71,7 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t }; std::mutex mutex; - std::unordered_multimap> map; + std::unordered_multimap map; int operator()(volatile void* uaddr, int futex_op, uint val, const timespec* timeout, uint mask) { diff --git a/rpcs3/Emu/Cell/Modules/libmixer.cpp b/rpcs3/Emu/Cell/Modules/libmixer.cpp index ec3b3dba60..813a127656 100644 --- a/rpcs3/Emu/Cell/Modules/libmixer.cpp +++ b/rpcs3/Emu/Cell/Modules/libmixer.cpp @@ -433,7 +433,7 @@ struct surmixer_thread : ppu_thread g_surmx.mixdata[i * 8 + 1] += right; } if ((p.m_position == p.m_samples && p.m_speed > 0.0f) || - (p.m_position = umax && p.m_speed < 0.0f)) // loop or stop + (p.m_position == umax && p.m_speed < 0.0f)) // loop or stop { if (p.m_loop_mode == CELL_SSPLAYER_LOOP_ON) { diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 33c948f34c..53ff9dfa6c 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -3,6 +3,7 @@ #include "Keyboard.h" #include +#include #include "util/init_mutex.hpp" diff --git a/rpcs3/Emu/Io/MouseHandler.h b/rpcs3/Emu/Io/MouseHandler.h index dc312900ce..e836c8c890 100644 --- a/rpcs3/Emu/Io/MouseHandler.h +++ b/rpcs3/Emu/Io/MouseHandler.h @@ -2,6 +2,7 @@ #include #include +#include #include "Utilities/mutex.h" #include "util/init_mutex.hpp" diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index 0de911141a..887123fddf 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -1,11 +1,17 @@ #pragma once -#include #include "pad_types.h" #include "pad_config.h" #include "pad_config_types.h" #include "util/types.hpp" +#include +#include +#include +#include +#include +#include + struct PadDevice { pad_config* config{ nullptr }; diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index 190895da5d..002e2f3f4a 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -2,6 +2,7 @@ #include #include +#include #include "Emu/Memory/vm_ptr.h" #include "Emu/Cell/Modules/sceNp.h" diff --git a/rpcs3/Emu/RSX/Capture/rsx_replay.h b/rpcs3/Emu/RSX/Capture/rsx_replay.h index 2c2a7519e9..ff3422f2d1 100644 --- a/rpcs3/Emu/RSX/Capture/rsx_replay.h +++ b/rpcs3/Emu/RSX/Capture/rsx_replay.h @@ -2,6 +2,7 @@ #include "Emu/CPU/CPUThread.h" #include "Emu/RSX/rsx_methods.h" +#include #include #include diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.h b/rpcs3/Emu/RSX/Common/ProgramStateCache.h index fcfda0b811..0c83bdccb9 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.h +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.h @@ -9,6 +9,7 @@ #include "Utilities/span.h" #include +#include enum class SHADER_TYPE { diff --git a/rpcs3/Emu/RSX/Common/ShaderParam.h b/rpcs3/Emu/RSX/Common/ShaderParam.h index 5ff5d46537..1a2d0f9290 100644 --- a/rpcs3/Emu/RSX/Common/ShaderParam.h +++ b/rpcs3/Emu/RSX/Common/ShaderParam.h @@ -6,6 +6,8 @@ #include "Utilities/StrUtil.h" #include "util/types.hpp" +#include + enum class FUNCTION { FUNCTION_DP2, diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index 90fde1bd3c..266110347b 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -7,6 +7,8 @@ #include "util/asm.hpp" +#include + namespace rsx { namespace utility diff --git a/rpcs3/Emu/RSX/Common/texture_cache.h b/rpcs3/Emu/RSX/Common/texture_cache.h index 7809e6b30d..cf09949752 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache.h +++ b/rpcs3/Emu/RSX/Common/texture_cache.h @@ -4,6 +4,8 @@ #include "texture_cache_predictor.h" #include "texture_cache_helpers.h" +#include + extern u64 get_system_time(); #define RSX_GCM_FORMAT_IGNORED 0 diff --git a/rpcs3/Emu/RSX/Common/texture_cache_predictor.h b/rpcs3/Emu/RSX/Common/texture_cache_predictor.h index 8f33cf722b..133e98088b 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_predictor.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_predictor.h @@ -4,6 +4,8 @@ #include "../rsx_utils.h" #include "TextureUtils.h" +#include + namespace rsx { /** diff --git a/rpcs3/Emu/RSX/GL/GLCompute.h b/rpcs3/Emu/RSX/GL/GLCompute.h index 9ccfd21d69..3a7c394f0f 100644 --- a/rpcs3/Emu/RSX/GL/GLCompute.h +++ b/rpcs3/Emu/RSX/GL/GLCompute.h @@ -5,6 +5,7 @@ #include "GLHelpers.h" #include "util/asm.hpp" +#include namespace gl { diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.h b/rpcs3/Emu/RSX/GL/GLGSRender.h index 17420a4171..c56bd9cee6 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.h +++ b/rpcs3/Emu/RSX/GL/GLGSRender.h @@ -10,6 +10,7 @@ #include "GLShaderInterpreter.h" #include +#include #ifdef _WIN32 #pragma comment(lib, "opengl32.lib") diff --git a/rpcs3/Emu/RSX/GL/GLHelpers.cpp b/rpcs3/Emu/RSX/GL/GLHelpers.cpp index c346d61c0b..d20dfebcb2 100644 --- a/rpcs3/Emu/RSX/GL/GLHelpers.cpp +++ b/rpcs3/Emu/RSX/GL/GLHelpers.cpp @@ -4,6 +4,8 @@ #include "GLCompute.h" #include "util/logs.hpp" +#include + namespace gl { std::unordered_map> g_compute_tasks; diff --git a/rpcs3/Emu/RSX/GL/GLOverlays.h b/rpcs3/Emu/RSX/GL/GLOverlays.h index 52b9f60523..d5c93420b5 100644 --- a/rpcs3/Emu/RSX/GL/GLOverlays.h +++ b/rpcs3/Emu/RSX/GL/GLOverlays.h @@ -4,6 +4,7 @@ #include "GLHelpers.h" #include "../Overlays/overlays.h" #include +#include extern u64 get_system_time(); diff --git a/rpcs3/Emu/RSX/GL/GLShaderInterpreter.h b/rpcs3/Emu/RSX/GL/GLShaderInterpreter.h index cad5c8ab8e..25102cd1db 100644 --- a/rpcs3/Emu/RSX/GL/GLShaderInterpreter.h +++ b/rpcs3/Emu/RSX/GL/GLShaderInterpreter.h @@ -3,6 +3,8 @@ #include "../Common/ProgramStateCache.h" #include "../Common/TextureUtils.h" +#include + namespace gl { using namespace ::glsl; diff --git a/rpcs3/Emu/RSX/GL/GLTextOut.h b/rpcs3/Emu/RSX/GL/GLTextOut.h index 9c8a5021b8..52e5ab1b34 100644 --- a/rpcs3/Emu/RSX/GL/GLTextOut.h +++ b/rpcs3/Emu/RSX/GL/GLTextOut.h @@ -5,6 +5,7 @@ #include "../Common/TextGlyphs.h" #include #include +#include namespace gl { diff --git a/rpcs3/Emu/RSX/GL/GLTexture.h b/rpcs3/Emu/RSX/GL/GLTexture.h index 19a51eddda..cecc13b90a 100644 --- a/rpcs3/Emu/RSX/GL/GLTexture.h +++ b/rpcs3/Emu/RSX/GL/GLTexture.h @@ -5,6 +5,8 @@ #include "../Common/TextureUtils.h" #include "GLHelpers.h" +#include + namespace rsx { class vertex_texture; diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.h b/rpcs3/Emu/RSX/GL/GLVertexProgram.h index bf3b11ab48..bf95df95e0 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.h +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.h @@ -3,6 +3,8 @@ #include "Emu/RSX/RSXVertexProgram.h" #include "GLHelpers.h" +#include + enum { GL_VP_FORCE_ATTRIB_SCALING = 1, //Scale vertex read result diff --git a/rpcs3/Emu/RSX/Overlays/overlay_utils.cpp b/rpcs3/Emu/RSX/Overlays/overlay_utils.cpp index 0db4b3440e..4be5d07c79 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_utils.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_utils.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "overlay_utils.h" +#include + LOG_CHANNEL(overlays); static auto s_ascii_lowering_map = []() diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index 9477337fba..dec6dba0ba 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "GCM.h" #include "rsx_cache.h" diff --git a/rpcs3/Emu/RSX/VK/VKCompute.h b/rpcs3/Emu/RSX/VK/VKCompute.h index b09a91f3f0..d3d044cae4 100644 --- a/rpcs3/Emu/RSX/VK/VKCompute.h +++ b/rpcs3/Emu/RSX/VK/VKCompute.h @@ -6,6 +6,7 @@ #include "Emu/IdManager.h" #include "util/asm.hpp" +#include #define VK_MAX_COMPUTE_TASKS 4096 // Max number of jobs per frame diff --git a/rpcs3/Emu/RSX/VK/VKDMA.cpp b/rpcs3/Emu/RSX/VK/VKDMA.cpp index 81437cef28..1c9e824451 100644 --- a/rpcs3/Emu/RSX/VK/VKDMA.cpp +++ b/rpcs3/Emu/RSX/VK/VKDMA.cpp @@ -4,6 +4,7 @@ #include "VKDMA.h" #include "util/asm.hpp" +#include namespace vk { diff --git a/rpcs3/Emu/RSX/VK/VKFramebuffer.cpp b/rpcs3/Emu/RSX/VK/VKFramebuffer.cpp index 39dfe54c12..3a3f286fd3 100644 --- a/rpcs3/Emu/RSX/VK/VKFramebuffer.cpp +++ b/rpcs3/Emu/RSX/VK/VKFramebuffer.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "VKFramebuffer.h" +#include namespace vk { diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.cpp b/rpcs3/Emu/RSX/VK/VKHelpers.cpp index 673a54b53d..e68157318a 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.cpp +++ b/rpcs3/Emu/RSX/VK/VKHelpers.cpp @@ -13,6 +13,7 @@ #include "Emu/RSX/rsx_methods.h" #include "Utilities/mutex.h" #include "Utilities/lockless.h" +#include namespace vk { diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.h b/rpcs3/Emu/RSX/VK/VKOverlays.h index a337094e40..19e4fb09fa 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.h +++ b/rpcs3/Emu/RSX/VK/VKOverlays.h @@ -11,6 +11,7 @@ #include "../Overlays/overlays.h" #include "Utilities/hash.h" +#include #define VK_OVERLAY_MAX_DRAW_CALLS 1024 diff --git a/rpcs3/Emu/RSX/VK/VKResourceManager.h b/rpcs3/Emu/RSX/VK/VKResourceManager.h index b563198070..3110cd6803 100644 --- a/rpcs3/Emu/RSX/VK/VKResourceManager.h +++ b/rpcs3/Emu/RSX/VK/VKResourceManager.h @@ -1,6 +1,10 @@ #pragma once #include "VKHelpers.h" +#include +#include +#include + namespace vk { u64 get_event_id(); diff --git a/rpcs3/Emu/RSX/VK/VKShaderInterpreter.h b/rpcs3/Emu/RSX/VK/VKShaderInterpreter.h index c62e7cdc6c..f06daab348 100644 --- a/rpcs3/Emu/RSX/VK/VKShaderInterpreter.h +++ b/rpcs3/Emu/RSX/VK/VKShaderInterpreter.h @@ -1,5 +1,6 @@ #pragma once #include "VKProgramBuffer.h" +#include namespace vk { diff --git a/rpcs3/Emu/RSX/VK/VKTextOut.h b/rpcs3/Emu/RSX/VK/VKTextOut.h index aecfe26d93..165a177907 100644 --- a/rpcs3/Emu/RSX/VK/VKTextOut.h +++ b/rpcs3/Emu/RSX/VK/VKTextOut.h @@ -5,6 +5,7 @@ #include "VKRenderPass.h" #include "VKPipelineCompiler.h" #include "../Common/TextGlyphs.h" +#include namespace vk { diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index df25937f00..6fedcf5753 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -13,7 +13,7 @@ #include "rsx_utils.h" #include #include - +#include #include "util/vm.hpp" diff --git a/rpcs3/Input/ds3_pad_handler.h b/rpcs3/Input/ds3_pad_handler.h index 52a10d2175..a727fe661c 100644 --- a/rpcs3/Input/ds3_pad_handler.h +++ b/rpcs3/Input/ds3_pad_handler.h @@ -4,6 +4,8 @@ #include "hidapi.h" +#include + class ds3_pad_handler final : public PadHandlerBase { enum DS3KeyCodes diff --git a/rpcs3/Input/ds4_pad_handler.h b/rpcs3/Input/ds4_pad_handler.h index f47f25d9b2..06d557df6b 100644 --- a/rpcs3/Input/ds4_pad_handler.h +++ b/rpcs3/Input/ds4_pad_handler.h @@ -4,6 +4,8 @@ #include "Utilities/CRC.h" #include "hidapi.h" +#include + class ds4_pad_handler final : public PadHandlerBase { // These are all the possible buttons on a standard DS4 controller diff --git a/rpcs3/Input/dualsense_pad_handler.h b/rpcs3/Input/dualsense_pad_handler.h index f254047161..e3fd60eb65 100644 --- a/rpcs3/Input/dualsense_pad_handler.h +++ b/rpcs3/Input/dualsense_pad_handler.h @@ -4,6 +4,8 @@ #include "Utilities/CRC.h" #include "hidapi.h" +#include + class dualsense_pad_handler final : public PadHandlerBase { enum DualSenseKeyCodes diff --git a/rpcs3/Input/xinput_pad_handler.h b/rpcs3/Input/xinput_pad_handler.h index 686a4094d2..8ca0c82680 100644 --- a/rpcs3/Input/xinput_pad_handler.h +++ b/rpcs3/Input/xinput_pad_handler.h @@ -1,6 +1,9 @@ #pragma once #include "Emu/Io/PadHandler.h" + +#include + #ifndef NOMINMAX #define NOMINMAX #endif diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index c35a2f9794..5e7ae67015 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.h b/rpcs3/rpcs3qt/patch_manager_dialog.h index b779235394..13a0bcb822 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.h +++ b/rpcs3/rpcs3qt/patch_manager_dialog.h @@ -6,6 +6,7 @@ #include #include "Utilities/bin_patch.h" +#include namespace Ui { diff --git a/rpcs3/rpcs3qt/rsx_debugger.cpp b/rpcs3/rpcs3qt/rsx_debugger.cpp index 8cd7440f8b..8435e0c0d3 100644 --- a/rpcs3/rpcs3qt/rsx_debugger.cpp +++ b/rpcs3/rpcs3qt/rsx_debugger.cpp @@ -401,6 +401,19 @@ void Buffer::ShowWindowed() namespace { + f32 f16_to_f32(f16 val) + { + // See http://stackoverflow.com/a/26779139 + // The conversion doesn't handle NaN/Inf + + const u16 _u16 = static_cast(val); + const u32 raw = ((_u16 & 0x8000) << 16) | // Sign (just moved) + (((_u16 & 0x7c00) + 0x1C000) << 13) | // Exponent ( exp - 15 + 127) + ((_u16 & 0x03FF) << 13); // Mantissa + + return std::bit_cast(raw); + } + std::array get_value(gsl::span orig_buffer, rsx::surface_color_format format, usz idx) { switch (format) @@ -438,9 +451,9 @@ namespace const f16 h0 = f16(ptr[4 * idx]); const f16 h1 = f16(ptr[4 * idx + 1]); const f16 h2 = f16(ptr[4 * idx + 2]); - const f32 f0 = float(h0); - const f32 f1 = float(h1); - const f32 f2 = float(h2); + const f32 f0 = f16_to_f32(h0); + const f32 f1 = f16_to_f32(h1); + const f32 f2 = f16_to_f32(h2); const u8 val0 = f0 * 255.; const u8 val1 = f1 * 255.; diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index e4bd3bf7fa..ae0e8b7d27 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -48,9 +48,7 @@ using namespace std::literals; #define AUDIT(...) (static_cast(0)) #endif -#if __cpp_lib_bit_cast >= 201806L -#include -#else +#if __cpp_lib_bit_cast < 201806L namespace std { template > @@ -64,7 +62,7 @@ namespace std } To result{}; - std::memcpy(&result, &from, sizeof(From)); + __builtin_memcpy(&result, &from, sizeof(From)); return result; } } @@ -152,36 +150,29 @@ template <> struct get_int_impl { using utype = u8; - using stype = s8; }; template <> struct get_int_impl { using utype = u16; - using stype = s16; }; template <> struct get_int_impl { using utype = u32; - using stype = s32; }; template <> struct get_int_impl { using utype = u64; - using stype = s64; }; template using get_uint_t = typename get_int_impl::utype; -template -using get_sint_t = typename get_int_impl::stype; - template std::remove_cvref_t as_rvalue(T&& obj) { @@ -529,12 +520,6 @@ constexpr inline struct umax_helper { constexpr umax_helper() noexcept = default; - template , typename = std::enable_if_t>> - explicit constexpr operator T() const - { - return static_cast(-1); - } - template , typename = std::enable_if_t>> constexpr bool operator==(const T& rhs) const { @@ -566,30 +551,11 @@ constexpr inline struct umax_helper #endif } umax; +enum class f16 : u16{}; + using f32 = float; using f64 = double; -struct f16 -{ - u16 _u16; - - explicit f16(u16 raw) - { - _u16 = raw; - } - - explicit operator f32() const - { - // See http://stackoverflow.com/a/26779139 - // The conversion doesn't handle NaN/Inf - u32 raw = ((_u16 & 0x8000) << 16) | // Sign (just moved) - (((_u16 & 0x7c00) + 0x1C000) << 13) | // Exponent ( exp - 15 + 127) - ((_u16 & 0x03FF) << 13); // Mantissa - - return std::bit_cast(raw); - } -}; - template inline u32 offset32(T T2::*const mptr) { @@ -855,16 +821,7 @@ template return static_cast(Size); } -// Simplified hash algorithm for pointers. May be used in std::unordered_(map|set). -template -struct pointer_hash -{ - usz operator()(T* ptr) const - { - return reinterpret_cast(ptr) / Align; - } -}; - +// Simplified hash algorithm. May be used in std::unordered_(map|set). template struct value_hash {