Skip to content

Commit

Permalink
Merge pull request #2931 from unknownbrackets/endian
Browse files Browse the repository at this point in the history
Improve endian define handling and fix a couple typos
  • Loading branch information
hrydgard committed Jul 26, 2013
2 parents cc8bba1 + a740888 commit 3c86141
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
46 changes: 42 additions & 4 deletions Common/CommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,51 @@ typedef signed long long s64;

#endif // _WIN32

// Android
#if defined(ANDROID)
#include <sys/endian.h>

#if _BYTE_ORDER == _LITTLE_ENDIAN && !defined(COMMON_LITTLE_ENDIAN)
#define COMMON_LITTLE_ENDIAN 1
#elif _BYTE_ORDER == _BIG_ENDIAN && !defined(COMMON_BIG_ENDIAN)
#define COMMON_BIG_ENDIAN 1
#endif

// GCC 4.6+
#elif __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)

#if __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) && !defined(COMMON_LITTLE_ENDIAN)
#define COMMON_LITTLE_ENDIAN 1
#elif __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) && !defined(COMMON_BIG_ENDIAN)
#define COMMON_BIG_ENDIAN 1
#endif

// LLVM/clang
#elif __clang__

#if __LITTLE_ENDIAN__ && !defined(COMMON_LITTLE_ENDIAN)
#define COMMON_LITTLE_ENDIAN 1
#elif __BIG_ENDIAN__ && !defined(COMMON_BIG_ENDIAN)
#define COMMON_BIG_ENDIAN 1
#endif

// MSVC
#elif defined(_MSC_VER) && !defined(COMMON_BIG_ENDIAN) && !defined(COMMON_LITTLE_ENDIAN)

#ifdef _XBOX
#define COMMON_BIG_ENDIAN 1
#else
#define COMMON_LITTLE_ENDIAN 1
#endif

#endif

#ifdef ANDROID
#undef BIG_ENDIAN
#undef __BIG_ENDIAN__
// Worst case, default to little endian.
#if !COMMON_BIG_ENDIAN && !COMMON_LITTLE_ENDIAN
#define COMMON_LITTLE_ENDIAN 1
#endif

#if !BIG_ENDIAN && !__BIG_ENDIAN__
#if COMMON_LITTLE_ENDIAN
typedef u32 u32_le;
typedef u16 u16_le;
typedef u64 u64_le;
Expand Down
2 changes: 1 addition & 1 deletion Core/FileSystems/DirectoryFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ VirtualDiscFileSystem::VirtualDiscFileSystem(IHandleAllocator *_hAlloc, std::str

VirtualDiscFileSystem::~VirtualDiscFileSystem() {
for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
if (!iter->second.type != VFILETYPE_ISO)
if (iter->second.type != VFILETYPE_ISO)
iter->second.hFile.Close();
}
}
Expand Down
7 changes: 1 addition & 6 deletions Core/Font/PGF.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ struct Glyph {
};


#ifdef ANDROID
#undef BIG_ENDIAN
#undef __BIG_ENDIAN__
#endif

#if !BIG_ENDIAN && !__BIG_ENDIAN__
#if COMMON_LITTLE_ENDIAN
typedef FontPixelFormat FontPixelFormat_le;
#else
#error FIX ME
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/__sceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const int hostAttemptBlockSize = 256;
#else
const int hwBlockSize = 64;
const int hostAttemptBlockSize = 512;
#endif;
#endif

const int audioIntervalUs = (int)(1000000ULL * hwBlockSize / hwSampleRate);
const int audioHostIntervalUs = (int)(1000000ULL * hostAttemptBlockSize / hwSampleRate);
Expand Down
3 changes: 2 additions & 1 deletion Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <algorithm>

#include "Common/LogManager.h"
#include "Common/CommonTypes.h"
#include "HLE.h"
#include "HLETables.h"
#include "../MIPS/MIPSInt.h"
Expand Down Expand Up @@ -149,7 +150,7 @@ class Callback : public KernelObject
u32 savedIdRegister;
};

#if !defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN__)
#if COMMON_LITTLE_ENDIAN
typedef WaitType WaitType_le;
#else
#error FIX ME
Expand Down
2 changes: 1 addition & 1 deletion native

0 comments on commit 3c86141

Please sign in to comment.