diff --git a/Utilities/types.h b/Utilities/types.h index 5f31d636eb..4afabdf508 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -365,6 +366,9 @@ struct alignas(16) s128 CHECK_SIZE_ALIGN(u128, 16, 16); CHECK_SIZE_ALIGN(s128, 16, 16); +using f32 = float; +using f64 = double; + union alignas(2) f16 { u16 _u16; @@ -375,22 +379,28 @@ union alignas(2) f16 _u16 = raw; } - explicit operator float() const + 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 (float&)raw; + + union + { + char data[4]; + u32 data32; + f32 res; + }; + + data32 = raw; + return res; } }; CHECK_SIZE_ALIGN(f16, 2, 2); -using f32 = float; -using f64 = double; - template ::value>> constexpr T align(const T& value, ullong align) { @@ -400,12 +410,21 @@ constexpr T align(const T& value, ullong align) template inline u32 offset32(T T2::*const mptr) { + union + { + char data[sizeof(std::size_t)]; + std::size_t data_; + u32 data32; + }; + #ifdef _MSC_VER static_assert(sizeof(mptr) == sizeof(u32), "Invalid pointer-to-member size"); - return reinterpret_cast(mptr); + std::memcpy(data, &mptr, sizeof(u32)); + return data32; #elif __GNUG__ static_assert(sizeof(mptr) == sizeof(std::size_t), "Invalid pointer-to-member size"); - return static_cast(reinterpret_cast(mptr)); + std::memcpy(data, &mptr, sizeof(std::size_t)); + return data_; #else static_assert(sizeof(mptr) == 0, "Invalid pointer-to-member size"); #endif diff --git a/rpcs3/Emu/Cell/Common.h b/rpcs3/Emu/Cell/Common.h index 72a0145767..d67c35a5e6 100644 --- a/rpcs3/Emu/Cell/Common.h +++ b/rpcs3/Emu/Cell/Common.h @@ -12,5 +12,13 @@ enum FPSCR_RN // Get the exponent of a float inline int fexpf(float x) { - return ((u32&)x >> 23) & 0xFF; + union + { + char data[4]; + u32 data32; + float arg; + }; + + arg = x; + return (data32 >> 23) & 0xFF; } diff --git a/rpcs3/Emu/Cell/PPUInterpreter.cpp b/rpcs3/Emu/Cell/PPUInterpreter.cpp index 339e5dff47..3462ffa41e 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/PPUInterpreter.cpp @@ -3,6 +3,7 @@ #include "PPUThread.h" #include "PPUInterpreter.h" #include "Utilities/asm.h" +#include "Emu/Cell/Common.h" #include diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index b4c7178dd5..65f6ead43c 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -1,6 +1,5 @@ #pragma once -#include "Common.h" #include "../CPU/CPUThread.h" #include "../Memory/vm.h" #include "Utilities/lockless.h" diff --git a/rpcs3/Emu/Cell/SPUInterpreter.cpp b/rpcs3/Emu/Cell/SPUInterpreter.cpp index d8d4039fe2..574650487a 100644 --- a/rpcs3/Emu/Cell/SPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/SPUInterpreter.cpp @@ -6,6 +6,7 @@ #include "Utilities/asm.h" #include "SPUThread.h" #include "SPUInterpreter.h" +#include "Emu/Cell/Common.h" #include #include diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index 8cdce4e74e..177ed87d9b 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -1,6 +1,5 @@ #pragma once -#include "Emu/Cell/Common.h" #include "Emu/CPU/CPUThread.h" #include "Emu/Cell/SPUInterpreter.h" #include "Emu/Memory/vm.h" diff --git a/rpcs3/cmake_modules/ConfigureCompiler.cmake b/rpcs3/cmake_modules/ConfigureCompiler.cmake index 7495e8a311..196e7cef22 100644 --- a/rpcs3/cmake_modules/ConfigureCompiler.cmake +++ b/rpcs3/cmake_modules/ConfigureCompiler.cmake @@ -9,7 +9,9 @@ if(CMAKE_COMPILER_IS_GNUCXX) # Set compiler options here # Warnings + add_compile_options(-Wall) add_compile_options(-Wno-attributes -Wno-enum-compare -Wno-invalid-offsetof) + add_compile_options(-Wno-unknown-pragmas -Wno-unused-variable -Wno-reorder -Wno-comment) elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") # Clang 5.0 or latter is required @@ -20,6 +22,7 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") # Set compiler options here add_compile_options(-ftemplate-depth=1024) + add_compile_options(-Wunused-value -Wunused-comparison) if(APPLE) add_compile_options(-stdlib=libc++) endif()