Merge pull request #7099 from lioncash/compiler

Common: Add Compiler.h header for compiler-specifics
This commit is contained in:
Léo Lam 2018-06-09 20:19:49 +02:00 committed by GitHub
commit f564c28040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 55 additions and 44 deletions

View File

@ -35,7 +35,7 @@
#include <limits>
#include <type_traits>
#include "Common.h"
#include "Common/Compiler.h"
/*
* Abstract bitfield class
@ -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<StorageType>(val) << position) & GetMask());
return *this;

View File

@ -26,8 +26,8 @@
#include <vector>
#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"
@ -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)
{

View File

@ -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 <limits.h>
#define MAX_PATH PATH_MAX
#define __forceinline inline __attribute__((always_inline))
#endif
#ifdef _MSC_VER

View File

@ -54,6 +54,7 @@
<ClInclude Include="CommonFuncs.h" />
<ClInclude Include="CommonPaths.h" />
<ClInclude Include="CommonTypes.h" />
<ClInclude Include="Compiler.h" />
<ClInclude Include="Config\Config.h" />
<ClInclude Include="Config\ConfigInfo.h" />
<ClInclude Include="Config\Enums.h" />

View File

@ -37,6 +37,7 @@
<ClInclude Include="CommonFuncs.h" />
<ClInclude Include="CommonPaths.h" />
<ClInclude Include="CommonTypes.h" />
<ClInclude Include="Compiler.h" />
<ClInclude Include="Config\Config.h" />
<ClInclude Include="Config\Enums.h" />
<ClInclude Include="Config\Layer.h" />

View File

@ -0,0 +1,20 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#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
#define DOLPHIN_UNUSED [[maybe_unused]]
#endif
#ifdef _WIN32
#define DOLPHIN_FORCE_INLINE __forceinline
#else
#define DOLPHIN_FORCE_INLINE inline __attribute__((always_inline))
#endif

View File

@ -7,12 +7,9 @@
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <cstring>
#include "Common/Common.h"
#include "Common/Compiler.h"
#include "Common/Crypto/bn.h"
#include "Common/Crypto/ec.h"
#include "Common/Random.h"
@ -176,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,

View File

@ -8,8 +8,8 @@
#include <array>
#include <cstring>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Compiler.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
@ -19,7 +19,7 @@ namespace WiimoteEmu
// The id for nothing inserted
constexpr std::array<u8, 6> nothing_id{{0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e}};
// The id for a partially inserted extension (currently unused)
UNUSED constexpr std::array<u8, 6> partially_id{{0x00, 0x00, 0x00, 0x00, 0xff, 0xff}};
DOLPHIN_UNUSED constexpr std::array<u8, 6> partially_id{{0x00, 0x00, 0x00, 0x00, 0xff, 0xff}};
Attachment::Attachment(const char* const name, ExtensionReg& reg) : m_name(name), m_reg(reg)
{

View File

@ -9,6 +9,7 @@
#include "Common/BitField.h"
#include "Common/CommonTypes.h"
#include "Common/Compiler.h"
enum class EFBCopyFormat;
@ -902,7 +903,7 @@ union AlphaTest
PASS = 2,
};
__forceinline TEST_RESULT TestResult() const
DOLPHIN_FORCE_INLINE TEST_RESULT TestResult() const
{
switch (logic)
{

View File

@ -6,8 +6,8 @@
#include <cstring>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Compiler.h"
#include "Common/Swap.h"
class DataReader
@ -25,7 +25,7 @@ public:
size_t size() const { return end - buffer; }
template <typename T, bool swapped = true>
__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 <typename T, bool swapped = true>
__forceinline T Read()
DOLPHIN_FORCE_INLINE T Read()
{
const T result = Peek<T, swapped>();
buffer += sizeof(T);
@ -45,7 +45,7 @@ public:
}
template <typename T, bool swapped = false>
__forceinline void Write(T data)
DOLPHIN_FORCE_INLINE void Write(T data)
{
if (swapped)
data = Common::FromBigEndian(data);

View File

@ -4,8 +4,8 @@
#include <cstddef>
#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"
@ -58,7 +58,8 @@ void IndexGenerator::AddIndices(int primitive, u32 numVerts)
// Triangles
template <bool pr>
__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;

View File

@ -6,26 +6,26 @@
#include <cstring>
#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;
__forceinline void DataSkip(u32 skip)
DOLPHIN_FORCE_INLINE void DataSkip(u32 skip)
{
g_video_buffer_read_ptr += skip;
}
// probably unnecessary
template <int count>
__forceinline void DataSkip()
DOLPHIN_FORCE_INLINE void DataSkip()
{
g_video_buffer_read_ptr += count;
}
template <typename T>
__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 <typename T>
__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<T>(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 <typename T>
__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);

View File

@ -7,8 +7,8 @@
#include <cmath>
#include <type_traits>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Compiler.h"
#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h"
@ -26,7 +26,7 @@ VertexLoader_Normal::Set VertexLoader_Normal::m_Table[NUM_NRM_TYPE][NUM_NRM_INDI
namespace
{
template <typename T>
__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 <typename T, int N>
__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 <typename I, typename T, int N, int Offset>
__forceinline void Normal_Index_Offset()
DOLPHIN_FORCE_INLINE void Normal_Index_Offset()
{
static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!");