From 03414e8e848fd99e2ea83f4466a1cf34c2ad6807 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Jun 2018 11:34:43 -0400 Subject: [PATCH 1/4] Common: Add header for compiler-specifics Instead of globbing things under an ambiguous Common.h header, move compiler-specifics over to Compiler.h. This gives us a dedicated home for anything related to compilers that we want to make functional across all compilers that we support. This moves us a little closer to eliminating Common.h entirely. --- Source/Core/Common/BitField.h | 2 +- Source/Core/Common/ChunkFile.h | 2 +- Source/Core/Common/Common.h | 10 ---------- Source/Core/Common/Common.vcxproj | 1 + Source/Core/Common/Common.vcxproj.filters | 1 + Source/Core/Common/Compiler.h | 17 +++++++++++++++++ Source/Core/Common/Crypto/ec.cpp | 7 ++----- .../HW/WiimoteEmu/Attachment/Attachment.cpp | 2 +- Source/Core/VideoCommon/BPMemory.h | 1 + Source/Core/VideoCommon/DataReader.h | 2 +- Source/Core/VideoCommon/IndexGenerator.cpp | 2 +- Source/Core/VideoCommon/VertexLoaderUtils.h | 2 +- Source/Core/VideoCommon/VertexLoader_Normal.cpp | 2 +- 13 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 Source/Core/Common/Compiler.h diff --git a/Source/Core/Common/BitField.h b/Source/Core/Common/BitField.h index 108921bdf0..74683e9c96 100644 --- a/Source/Core/Common/BitField.h +++ b/Source/Core/Common/BitField.h @@ -35,7 +35,7 @@ #include #include -#include "Common.h" +#include "Common/Compiler.h" /* * Abstract bitfield class diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index 43d194c3ac..c8e50938a9 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -26,8 +26,8 @@ #include #include "Common/Assert.h" -#include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" #include "Common/File.h" #include "Common/FileUtil.h" #include "Common/Flag.h" diff --git a/Source/Core/Common/Common.h b/Source/Core/Common/Common.h index d6a2210158..0b09b9ec19 100644 --- a/Source/Core/Common/Common.h +++ b/Source/Core/Common/Common.h @@ -4,14 +4,6 @@ #pragma once -#if defined(__GNUC__) || __clang__ -// Disable "unused function" warnings for the ones manually marked as such. -#define UNUSED __attribute__((unused)) -#else -// Not sure MSVC even checks this... -#define UNUSED -#endif - #if defined _WIN32 // Memory leak checks @@ -42,8 +34,6 @@ struct CrtDebugBreak #ifndef _WIN32 #include #define MAX_PATH PATH_MAX - -#define __forceinline inline __attribute__((always_inline)) #endif #ifdef _MSC_VER diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index b1a7261f11..2a38dd721c 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -54,6 +54,7 @@ + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index a5163abff6..76793bd9ae 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -37,6 +37,7 @@ + diff --git a/Source/Core/Common/Compiler.h b/Source/Core/Common/Compiler.h new file mode 100644 index 0000000000..06313b375a --- /dev/null +++ b/Source/Core/Common/Compiler.h @@ -0,0 +1,17 @@ +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#if defined(__GNUC__) || __clang__ +// Disable "unused function" warnings for the ones manually marked as such. +#define UNUSED __attribute__((unused)) +#else +// Not sure MSVC even checks this... +#define UNUSED +#endif + +#ifndef _WIN32 +#define __forceinline inline __attribute__((always_inline)) +#endif diff --git a/Source/Core/Common/Crypto/ec.cpp b/Source/Core/Common/Crypto/ec.cpp index 78cd346ebd..4668293fc4 100644 --- a/Source/Core/Common/Crypto/ec.cpp +++ b/Source/Core/Common/Crypto/ec.cpp @@ -7,12 +7,9 @@ // http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt #include -#include -#include -#include -#include +#include -#include "Common/Common.h" +#include "Common/Compiler.h" #include "Common/Crypto/bn.h" #include "Common/Crypto/ec.h" #include "Common/Random.h" diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp index 479806fbb7..9f8325e679 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp @@ -8,8 +8,8 @@ #include #include -#include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "InputCommon/ControllerEmu/ControlGroup/Extension.h" diff --git a/Source/Core/VideoCommon/BPMemory.h b/Source/Core/VideoCommon/BPMemory.h index db4a5b5382..e0ff53f542 100644 --- a/Source/Core/VideoCommon/BPMemory.h +++ b/Source/Core/VideoCommon/BPMemory.h @@ -9,6 +9,7 @@ #include "Common/BitField.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" enum class EFBCopyFormat; diff --git a/Source/Core/VideoCommon/DataReader.h b/Source/Core/VideoCommon/DataReader.h index fef031206f..91434fdc55 100644 --- a/Source/Core/VideoCommon/DataReader.h +++ b/Source/Core/VideoCommon/DataReader.h @@ -6,8 +6,8 @@ #include -#include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" #include "Common/Swap.h" class DataReader diff --git a/Source/Core/VideoCommon/IndexGenerator.cpp b/Source/Core/VideoCommon/IndexGenerator.cpp index 74f6a8a728..2d9ec0d098 100644 --- a/Source/Core/VideoCommon/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/IndexGenerator.cpp @@ -4,8 +4,8 @@ #include -#include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" #include "Common/Logging/Log.h" #include "VideoCommon/IndexGenerator.h" #include "VideoCommon/OpcodeDecoding.h" diff --git a/Source/Core/VideoCommon/VertexLoaderUtils.h b/Source/Core/VideoCommon/VertexLoaderUtils.h index c8b1e2e54a..e32831d4dc 100644 --- a/Source/Core/VideoCommon/VertexLoaderUtils.h +++ b/Source/Core/VideoCommon/VertexLoaderUtils.h @@ -6,8 +6,8 @@ #include -#include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" extern u8* g_video_buffer_read_ptr; extern u8* g_vertex_manager_write_ptr; diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index 305fd85a6e..2676bc9ba4 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -7,8 +7,8 @@ #include #include -#include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Compiler.h" #include "VideoCommon/DataReader.h" #include "VideoCommon/VertexLoader.h" From 3f210836ad330bcb6bca5dee73c5c542ac18af32 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Jun 2018 11:47:01 -0400 Subject: [PATCH 2/4] Compiler: Rename __forceinline define to DOLPHIN_FORCE_INLINE This is much better as prefixed double underscores are reserved for the implementation when it comes to identifiers. Another reason its better, is that, on Windows, where __forceinline is a compiler built-in, with the previous define, header inclusion software that detects unnecessary includes will erroneously flag usages of Compiler.h as unnecessary (despite being necessary on other platforms). So we define a macro that's used by Windows and other platforms to ensure this doesn't happen. --- Source/Core/Common/BitField.h | 2 +- Source/Core/Common/ChunkFile.h | 2 +- Source/Core/Common/Compiler.h | 6 ++++-- Source/Core/VideoCommon/BPMemory.h | 2 +- Source/Core/VideoCommon/DataReader.h | 6 +++--- Source/Core/VideoCommon/IndexGenerator.cpp | 3 ++- Source/Core/VideoCommon/VertexLoaderUtils.h | 14 +++++++------- Source/Core/VideoCommon/VertexLoader_Normal.cpp | 8 ++++---- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Source/Core/Common/BitField.h b/Source/Core/Common/BitField.h index 74683e9c96..8815d6f870 100644 --- a/Source/Core/Common/BitField.h +++ b/Source/Core/Common/BitField.h @@ -137,7 +137,7 @@ public: BitField& operator=(const BitField&) = delete; #endif - __forceinline BitField& operator=(T val) + DOLPHIN_FORCE_INLINE BitField& operator=(T val) { storage = (storage & ~GetMask()) | ((static_cast(val) << position) & GetMask()); return *this; diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index c8e50938a9..9576c8ee35 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -257,7 +257,7 @@ private: DoEachElement(x, [](PointerWrap& p, typename T::value_type& elem) { p.Do(elem); }); } - __forceinline void DoVoid(void* data, u32 size) + DOLPHIN_FORCE_INLINE void DoVoid(void* data, u32 size) { switch (mode) { diff --git a/Source/Core/Common/Compiler.h b/Source/Core/Common/Compiler.h index 06313b375a..91ba02dac6 100644 --- a/Source/Core/Common/Compiler.h +++ b/Source/Core/Common/Compiler.h @@ -12,6 +12,8 @@ #define UNUSED #endif -#ifndef _WIN32 -#define __forceinline inline __attribute__((always_inline)) +#ifdef _WIN32 +#define DOLPHIN_FORCE_INLINE __forceinline +#else +#define DOLPHIN_FORCE_INLINE inline __attribute__((always_inline)) #endif diff --git a/Source/Core/VideoCommon/BPMemory.h b/Source/Core/VideoCommon/BPMemory.h index e0ff53f542..677a250043 100644 --- a/Source/Core/VideoCommon/BPMemory.h +++ b/Source/Core/VideoCommon/BPMemory.h @@ -903,7 +903,7 @@ union AlphaTest PASS = 2, }; - __forceinline TEST_RESULT TestResult() const + DOLPHIN_FORCE_INLINE TEST_RESULT TestResult() const { switch (logic) { diff --git a/Source/Core/VideoCommon/DataReader.h b/Source/Core/VideoCommon/DataReader.h index 91434fdc55..4e64bb4e60 100644 --- a/Source/Core/VideoCommon/DataReader.h +++ b/Source/Core/VideoCommon/DataReader.h @@ -25,7 +25,7 @@ public: size_t size() const { return end - buffer; } template - __forceinline T Peek(int offset = 0) const + DOLPHIN_FORCE_INLINE T Peek(int offset = 0) const { T data; std::memcpy(&data, &buffer[offset], sizeof(T)); @@ -37,7 +37,7 @@ public: } template - __forceinline T Read() + DOLPHIN_FORCE_INLINE T Read() { const T result = Peek(); buffer += sizeof(T); @@ -45,7 +45,7 @@ public: } template - __forceinline void Write(T data) + DOLPHIN_FORCE_INLINE void Write(T data) { if (swapped) data = Common::FromBigEndian(data); diff --git a/Source/Core/VideoCommon/IndexGenerator.cpp b/Source/Core/VideoCommon/IndexGenerator.cpp index 2d9ec0d098..6cb49aceba 100644 --- a/Source/Core/VideoCommon/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/IndexGenerator.cpp @@ -58,7 +58,8 @@ void IndexGenerator::AddIndices(int primitive, u32 numVerts) // Triangles template -__forceinline u16* IndexGenerator::WriteTriangle(u16* Iptr, u32 index1, u32 index2, u32 index3) +DOLPHIN_FORCE_INLINE u16* IndexGenerator::WriteTriangle(u16* Iptr, u32 index1, u32 index2, + u32 index3) { *Iptr++ = index1; *Iptr++ = index2; diff --git a/Source/Core/VideoCommon/VertexLoaderUtils.h b/Source/Core/VideoCommon/VertexLoaderUtils.h index e32831d4dc..2d0a982c33 100644 --- a/Source/Core/VideoCommon/VertexLoaderUtils.h +++ b/Source/Core/VideoCommon/VertexLoaderUtils.h @@ -12,20 +12,20 @@ extern u8* g_video_buffer_read_ptr; extern u8* g_vertex_manager_write_ptr; -__forceinline void DataSkip(u32 skip) +DOLPHIN_FORCE_INLINE void DataSkip(u32 skip) { g_video_buffer_read_ptr += skip; } // probably unnecessary template -__forceinline void DataSkip() +DOLPHIN_FORCE_INLINE void DataSkip() { g_video_buffer_read_ptr += count; } template -__forceinline T DataPeek(int _uOffset, u8* bufp = g_video_buffer_read_ptr) +DOLPHIN_FORCE_INLINE T DataPeek(int _uOffset, u8* bufp = g_video_buffer_read_ptr) { T result; std::memcpy(&result, &bufp[_uOffset], sizeof(T)); @@ -33,14 +33,14 @@ __forceinline T DataPeek(int _uOffset, u8* bufp = g_video_buffer_read_ptr) } template -__forceinline T DataRead(u8** bufp = &g_video_buffer_read_ptr) +DOLPHIN_FORCE_INLINE T DataRead(u8** bufp = &g_video_buffer_read_ptr) { auto const result = DataPeek(0, *bufp); *bufp += sizeof(T); return result; } -__forceinline u32 DataReadU32Unswapped() +DOLPHIN_FORCE_INLINE u32 DataReadU32Unswapped() { u32 result; std::memcpy(&result, g_video_buffer_read_ptr, sizeof(u32)); @@ -48,13 +48,13 @@ __forceinline u32 DataReadU32Unswapped() return result; } -__forceinline u8* DataGetPosition() +DOLPHIN_FORCE_INLINE u8* DataGetPosition() { return g_video_buffer_read_ptr; } template -__forceinline void DataWrite(T data) +DOLPHIN_FORCE_INLINE void DataWrite(T data) { std::memcpy(g_vertex_manager_write_ptr, &data, sizeof(T)); g_vertex_manager_write_ptr += sizeof(T); diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index 2676bc9ba4..b746f4f5d0 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -26,7 +26,7 @@ VertexLoader_Normal::Set VertexLoader_Normal::m_Table[NUM_NRM_TYPE][NUM_NRM_INDI namespace { template -__forceinline float FracAdjust(T val) +DOLPHIN_FORCE_INLINE float FracAdjust(T val) { // auto const S8FRAC = 1.f / (1u << 6); // auto const U8FRAC = 1.f / (1u << 7); @@ -38,13 +38,13 @@ __forceinline float FracAdjust(T val) } template <> -__forceinline float FracAdjust(float val) +DOLPHIN_FORCE_INLINE float FracAdjust(float val) { return val; } template -__forceinline void ReadIndirect(const T* data) +DOLPHIN_FORCE_INLINE void ReadIndirect(const T* data) { static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!"); DataReader dst(g_vertex_manager_write_ptr, nullptr); @@ -72,7 +72,7 @@ struct Normal_Direct }; template -__forceinline void Normal_Index_Offset() +DOLPHIN_FORCE_INLINE void Normal_Index_Offset() { static_assert(std::is_unsigned::value, "Only unsigned I is sane!"); From d8f6d601894ab73a3db199e6325692561a5ec702 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Jun 2018 11:54:52 -0400 Subject: [PATCH 3/4] Compiler: Rename UNUSED macro to DOLPHIN_UNUSED UNUSED is quite a generic macro name and has potential to clash with other libraries, so rename it to DOLPHIN_UNUSED to prevent that, as well as make its naming consistent with the force inline macro --- Source/Core/Common/Compiler.h | 4 ++-- Source/Core/Common/Crypto/ec.cpp | 6 +++--- Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/Compiler.h b/Source/Core/Common/Compiler.h index 91ba02dac6..194aae90ce 100644 --- a/Source/Core/Common/Compiler.h +++ b/Source/Core/Common/Compiler.h @@ -6,10 +6,10 @@ #if defined(__GNUC__) || __clang__ // Disable "unused function" warnings for the ones manually marked as such. -#define UNUSED __attribute__((unused)) +#define DOLPHIN_UNUSED __attribute__((unused)) #else // Not sure MSVC even checks this... -#define UNUSED +#define DOLPHIN_UNUSED #endif #ifdef _WIN32 diff --git a/Source/Core/Common/Crypto/ec.cpp b/Source/Core/Common/Crypto/ec.cpp index 4668293fc4..098d3e30c6 100644 --- a/Source/Core/Common/Crypto/ec.cpp +++ b/Source/Core/Common/Crypto/ec.cpp @@ -173,9 +173,9 @@ private: }; // y**2 + x*y = x**3 + x + b -UNUSED static const u8 ec_b[30] = {0x00, 0x66, 0x64, 0x7e, 0xde, 0x6c, 0x33, 0x2c, 0x7f, 0x8c, - 0x09, 0x23, 0xbb, 0x58, 0x21, 0x3b, 0x33, 0x3b, 0x20, 0xe9, - 0xce, 0x42, 0x81, 0xfe, 0x11, 0x5f, 0x7d, 0x8f, 0x90, 0xad}; +DOLPHIN_UNUSED static const u8 ec_b[30] = { + 0x00, 0x66, 0x64, 0x7e, 0xde, 0x6c, 0x33, 0x2c, 0x7f, 0x8c, 0x09, 0x23, 0xbb, 0x58, 0x21, + 0x3b, 0x33, 0x3b, 0x20, 0xe9, 0xce, 0x42, 0x81, 0xfe, 0x11, 0x5f, 0x7d, 0x8f, 0x90, 0xad}; // order of the addition group of points static const u8 ec_N[30] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp index 9f8325e679..a9185125b1 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp @@ -19,7 +19,7 @@ namespace WiimoteEmu // The id for nothing inserted constexpr std::array nothing_id{{0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e}}; // The id for a partially inserted extension (currently unused) -UNUSED constexpr std::array partially_id{{0x00, 0x00, 0x00, 0x00, 0xff, 0xff}}; +DOLPHIN_UNUSED constexpr std::array partially_id{{0x00, 0x00, 0x00, 0x00, 0xff, 0xff}}; Attachment::Attachment(const char* const name, ExtensionReg& reg) : m_name(name), m_reg(reg) { From 7b11ce3dd290b2f34164074cc493ea9e0c197fdf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Jun 2018 12:00:34 -0400 Subject: [PATCH 4/4] Compiler: Use [[maybe_unused]] in the Windows DOLPHIN_UNUSED macro The required version of MSVC already supports [[maybe_unused]], so we can utilize this here. When GCC 7 and clang 3.9 become hard requirements, we can eliminate this macro entirely and replace it with [[maybe_unused]]. --- Source/Core/Common/Compiler.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/Compiler.h b/Source/Core/Common/Compiler.h index 194aae90ce..0cd3836330 100644 --- a/Source/Core/Common/Compiler.h +++ b/Source/Core/Common/Compiler.h @@ -4,12 +4,13 @@ #pragma once +// TODO: Replace this with [[maybe_unused]] directly when GCC 7 and clang 3.9 +// are hard requirements. #if defined(__GNUC__) || __clang__ // Disable "unused function" warnings for the ones manually marked as such. #define DOLPHIN_UNUSED __attribute__((unused)) #else -// Not sure MSVC even checks this... -#define DOLPHIN_UNUSED +#define DOLPHIN_UNUSED [[maybe_unused]] #endif #ifdef _WIN32