Skip to content

Commit

Permalink
Compiler: Rename __forceinline define to DOLPHIN_FORCE_INLINE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lioncash committed Jun 9, 2018
1 parent 03414e8 commit 3f21083
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Common/BitField.h
Expand Up @@ -137,7 +137,7 @@ struct BitField
BitField& operator=(const BitField&) = delete; BitField& operator=(const BitField&) = delete;
#endif #endif


__forceinline BitField& operator=(T val) DOLPHIN_FORCE_INLINE BitField& operator=(T val)
{ {
storage = (storage & ~GetMask()) | ((static_cast<StorageType>(val) << position) & GetMask()); storage = (storage & ~GetMask()) | ((static_cast<StorageType>(val) << position) & GetMask());
return *this; return *this;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/ChunkFile.h
Expand Up @@ -257,7 +257,7 @@ class PointerWrap
DoEachElement(x, [](PointerWrap& p, typename T::value_type& elem) { p.Do(elem); }); 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) switch (mode)
{ {
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Common/Compiler.h
Expand Up @@ -12,6 +12,8 @@
#define UNUSED #define UNUSED
#endif #endif


#ifndef _WIN32 #ifdef _WIN32
#define __forceinline inline __attribute__((always_inline)) #define DOLPHIN_FORCE_INLINE __forceinline
#else
#define DOLPHIN_FORCE_INLINE inline __attribute__((always_inline))
#endif #endif
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/BPMemory.h
Expand Up @@ -903,7 +903,7 @@ union AlphaTest
PASS = 2, PASS = 2,
}; };


__forceinline TEST_RESULT TestResult() const DOLPHIN_FORCE_INLINE TEST_RESULT TestResult() const
{ {
switch (logic) switch (logic)
{ {
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoCommon/DataReader.h
Expand Up @@ -25,7 +25,7 @@ class DataReader


size_t size() const { return end - buffer; } size_t size() const { return end - buffer; }
template <typename T, bool swapped = true> template <typename T, bool swapped = true>
__forceinline T Peek(int offset = 0) const DOLPHIN_FORCE_INLINE T Peek(int offset = 0) const
{ {
T data; T data;
std::memcpy(&data, &buffer[offset], sizeof(T)); std::memcpy(&data, &buffer[offset], sizeof(T));
Expand All @@ -37,15 +37,15 @@ class DataReader
} }


template <typename T, bool swapped = true> template <typename T, bool swapped = true>
__forceinline T Read() DOLPHIN_FORCE_INLINE T Read()
{ {
const T result = Peek<T, swapped>(); const T result = Peek<T, swapped>();
buffer += sizeof(T); buffer += sizeof(T);
return result; return result;
} }


template <typename T, bool swapped = false> template <typename T, bool swapped = false>
__forceinline void Write(T data) DOLPHIN_FORCE_INLINE void Write(T data)
{ {
if (swapped) if (swapped)
data = Common::FromBigEndian(data); data = Common::FromBigEndian(data);
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoCommon/IndexGenerator.cpp
Expand Up @@ -58,7 +58,8 @@ void IndexGenerator::AddIndices(int primitive, u32 numVerts)


// Triangles // Triangles
template <bool pr> 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++ = index1;
*Iptr++ = index2; *Iptr++ = index2;
Expand Down
14 changes: 7 additions & 7 deletions Source/Core/VideoCommon/VertexLoaderUtils.h
Expand Up @@ -12,49 +12,49 @@
extern u8* g_video_buffer_read_ptr; extern u8* g_video_buffer_read_ptr;
extern u8* g_vertex_manager_write_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; g_video_buffer_read_ptr += skip;
} }


// probably unnecessary // probably unnecessary
template <int count> template <int count>
__forceinline void DataSkip() DOLPHIN_FORCE_INLINE void DataSkip()
{ {
g_video_buffer_read_ptr += count; g_video_buffer_read_ptr += count;
} }


template <typename T> 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; T result;
std::memcpy(&result, &bufp[_uOffset], sizeof(T)); std::memcpy(&result, &bufp[_uOffset], sizeof(T));
return Common::FromBigEndian(result); return Common::FromBigEndian(result);
} }


template <typename T> 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); auto const result = DataPeek<T>(0, *bufp);
*bufp += sizeof(T); *bufp += sizeof(T);
return result; return result;
} }


__forceinline u32 DataReadU32Unswapped() DOLPHIN_FORCE_INLINE u32 DataReadU32Unswapped()
{ {
u32 result; u32 result;
std::memcpy(&result, g_video_buffer_read_ptr, sizeof(u32)); std::memcpy(&result, g_video_buffer_read_ptr, sizeof(u32));
g_video_buffer_read_ptr += sizeof(u32); g_video_buffer_read_ptr += sizeof(u32);
return result; return result;
} }


__forceinline u8* DataGetPosition() DOLPHIN_FORCE_INLINE u8* DataGetPosition()
{ {
return g_video_buffer_read_ptr; return g_video_buffer_read_ptr;
} }


template <typename T> 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)); std::memcpy(g_vertex_manager_write_ptr, &data, sizeof(T));
g_vertex_manager_write_ptr += sizeof(T); g_vertex_manager_write_ptr += sizeof(T);
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/VideoCommon/VertexLoader_Normal.cpp
Expand Up @@ -26,7 +26,7 @@ VertexLoader_Normal::Set VertexLoader_Normal::m_Table[NUM_NRM_TYPE][NUM_NRM_INDI
namespace namespace
{ {
template <typename T> template <typename T>
__forceinline float FracAdjust(T val) DOLPHIN_FORCE_INLINE float FracAdjust(T val)
{ {
// auto const S8FRAC = 1.f / (1u << 6); // auto const S8FRAC = 1.f / (1u << 6);
// auto const U8FRAC = 1.f / (1u << 7); // auto const U8FRAC = 1.f / (1u << 7);
Expand All @@ -38,13 +38,13 @@ __forceinline float FracAdjust(T val)
} }


template <> template <>
__forceinline float FracAdjust(float val) DOLPHIN_FORCE_INLINE float FracAdjust(float val)
{ {
return val; return val;
} }


template <typename T, int N> 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!"); static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader dst(g_vertex_manager_write_ptr, nullptr);
Expand Down Expand Up @@ -72,7 +72,7 @@ struct Normal_Direct
}; };


template <typename I, typename T, int N, int Offset> 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!"); static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!");


Expand Down

0 comments on commit 3f21083

Please sign in to comment.