diff options
| author | 2015-02-18 22:46:21 -0800 | |
|---|---|---|
| committer | 2015-02-19 22:26:25 -0800 | |
| commit | 4fb75d220aeaa66d3e907cc2311acf6c29433800 (patch) | |
| tree | 8fa12b7d7dd3fde83ce126c0ffe3c8011d839f4f /src | |
| parent | Remove duplication of INSERT_PADDING_WORDS between pica.h and gpu.h (diff) | |
| download | yuzu-4fb75d220aeaa66d3e907cc2311acf6c29433800.tar.gz yuzu-4fb75d220aeaa66d3e907cc2311acf6c29433800.tar.xz yuzu-4fb75d220aeaa66d3e907cc2311acf6c29433800.zip | |
Misc cleanup of common and related functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/common.h | 72 | ||||
| -rw-r--r-- | src/common/common_funcs.h | 23 | ||||
| -rw-r--r-- | src/common/hash.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 5 |
4 files changed, 31 insertions, 81 deletions
diff --git a/src/common/common.h b/src/common/common.h index f5f2f8c34..948dc536a 100644 --- a/src/common/common.h +++ b/src/common/common.h | |||
| @@ -35,13 +35,11 @@ private: | |||
| 35 | #ifdef __APPLE__ | 35 | #ifdef __APPLE__ |
| 36 | // The Darwin ABI requires that stack frames be aligned to 16-byte boundaries. | 36 | // The Darwin ABI requires that stack frames be aligned to 16-byte boundaries. |
| 37 | // This is only needed on i386 gcc - x86_64 already aligns to 16 bytes. | 37 | // This is only needed on i386 gcc - x86_64 already aligns to 16 bytes. |
| 38 | #if defined __i386__ && defined __GNUC__ | 38 | #if defined __i386__ && defined __GNUC__ |
| 39 | #undef STACKALIGN | 39 | #undef STACKALIGN |
| 40 | #define STACKALIGN __attribute__((__force_align_arg_pointer__)) | 40 | #define STACKALIGN __attribute__((__force_align_arg_pointer__)) |
| 41 | #endif | 41 | #endif |
| 42 | |||
| 43 | #elif defined _WIN32 | 42 | #elif defined _WIN32 |
| 44 | |||
| 45 | // Check MSC ver | 43 | // Check MSC ver |
| 46 | #if defined _MSC_VER && _MSC_VER <= 1000 | 44 | #if defined _MSC_VER && _MSC_VER <= 1000 |
| 47 | #error needs at least version 1000 of MSC | 45 | #error needs at least version 1000 of MSC |
| @@ -51,9 +49,6 @@ private: | |||
| 51 | #define NOMINMAX | 49 | #define NOMINMAX |
| 52 | #endif | 50 | #endif |
| 53 | 51 | ||
| 54 | // Memory leak checks | ||
| 55 | #define CHECK_HEAP_INTEGRITY() | ||
| 56 | |||
| 57 | // Alignment | 52 | // Alignment |
| 58 | #define MEMORY_ALIGNED16(x) __declspec(align(16)) x | 53 | #define MEMORY_ALIGNED16(x) __declspec(align(16)) x |
| 59 | #define MEMORY_ALIGNED32(x) __declspec(align(32)) x | 54 | #define MEMORY_ALIGNED32(x) __declspec(align(32)) x |
| @@ -61,57 +56,34 @@ private: | |||
| 61 | #define MEMORY_ALIGNED128(x) __declspec(align(128)) x | 56 | #define MEMORY_ALIGNED128(x) __declspec(align(128)) x |
| 62 | #define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x | 57 | #define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x |
| 63 | #define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x | 58 | #define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x |
| 64 | |||
| 65 | // Since they are always around on windows | ||
| 66 | #define HAVE_WX 1 | ||
| 67 | #define HAVE_OPENAL 1 | ||
| 68 | |||
| 69 | #define HAVE_PORTAUDIO 1 | ||
| 70 | |||
| 71 | // Debug definitions | ||
| 72 | #if defined(_DEBUG) | ||
| 73 | #include <crtdbg.h> | ||
| 74 | #undef CHECK_HEAP_INTEGRITY | ||
| 75 | #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");} | ||
| 76 | // If you want to see how much a pain in the ass singletons are, for example: | ||
| 77 | // {614} normal block at 0x030C5310, 188 bytes long. | ||
| 78 | // Data: <Master Log > 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00 | ||
| 79 | struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } }; | ||
| 80 | //CrtDebugBreak breakAt(614); | ||
| 81 | #endif // end DEBUG/FAST | ||
| 82 | |||
| 83 | #endif | 59 | #endif |
| 84 | 60 | ||
| 85 | // Windows compatibility | 61 | // Windows compatibility |
| 86 | #ifndef _WIN32 | 62 | #ifndef _WIN32 |
| 87 | #ifdef _LP64 | 63 | #ifdef _LP64 |
| 88 | #define _M_X64 1 | 64 | #define _M_X64 1 |
| 89 | #else | 65 | #else |
| 90 | #define _M_IX86 1 | 66 | #define _M_IX86 1 |
| 91 | #endif | 67 | #endif |
| 92 | #define __forceinline inline __attribute__((always_inline)) | 68 | #define __forceinline inline __attribute__((always_inline)) |
| 93 | #define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x | 69 | #define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x |
| 94 | #define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x | 70 | #define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x |
| 95 | #define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x | 71 | #define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x |
| 96 | #define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x | 72 | #define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x |
| 97 | #define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x | 73 | #define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x |
| 98 | #define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x | 74 | #define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x |
| 99 | #endif | 75 | #endif |
| 100 | 76 | ||
| 101 | #ifdef _MSC_VER | 77 | #ifdef _MSC_VER |
| 102 | #define __strdup _strdup | 78 | #define __strdup _strdup |
| 103 | #define __getcwd _getcwd | 79 | #define __getcwd _getcwd |
| 104 | #define __chdir _chdir | 80 | #define __chdir _chdir |
| 105 | #else | 81 | #else |
| 106 | #define __strdup strdup | 82 | #define __strdup strdup |
| 107 | #define __getcwd getcwd | 83 | #define __getcwd getcwd |
| 108 | #define __chdir chdir | 84 | #define __chdir chdir |
| 109 | #endif | 85 | #endif |
| 110 | 86 | ||
| 111 | // Dummy macro for marking translatable strings that can not be immediately translated. | ||
| 112 | // wxWidgets does not have a true dummy macro for this. | ||
| 113 | #define _trans(a) a | ||
| 114 | |||
| 115 | #if defined _M_GENERIC | 87 | #if defined _M_GENERIC |
| 116 | # define _M_SSE 0x0 | 88 | # define _M_SSE 0x0 |
| 117 | #elif defined __GNUC__ | 89 | #elif defined __GNUC__ |
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index daec8f0ff..bc296ed3e 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -24,11 +24,6 @@ template<> struct CompileTimeAssert<true> {}; | |||
| 24 | #define b32(x) (b16(x) | (b16(x) >>16) ) | 24 | #define b32(x) (b16(x) | (b16(x) >>16) ) |
| 25 | #define ROUND_UP_POW2(x) (b32(x - 1) + 1) | 25 | #define ROUND_UP_POW2(x) (b32(x - 1) + 1) |
| 26 | 26 | ||
| 27 | #define MIN(a, b) ((a)<(b)?(a):(b)) | ||
| 28 | #define MAX(a, b) ((a)>(b)?(a):(b)) | ||
| 29 | |||
| 30 | #define CLAMP(x, min, max) (((x) > max) ? max : (((x) < min) ? min : (x))) | ||
| 31 | |||
| 32 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) | 27 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 33 | 28 | ||
| 34 | /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor. | 29 | /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor. |
| @@ -147,15 +142,6 @@ inline u64 _rotr64(u64 x, unsigned int shift){ | |||
| 147 | #define Crash() {DebugBreak();} | 142 | #define Crash() {DebugBreak();} |
| 148 | #endif // _MSC_VER ndef | 143 | #endif // _MSC_VER ndef |
| 149 | 144 | ||
| 150 | // Dolphin's min and max functions | ||
| 151 | #undef min | ||
| 152 | #undef max | ||
| 153 | |||
| 154 | template<class T> | ||
| 155 | inline T min(const T& a, const T& b) {return a > b ? b : a;} | ||
| 156 | template<class T> | ||
| 157 | inline T max(const T& a, const T& b) {return a > b ? a : b;} | ||
| 158 | |||
| 159 | // Generic function to get last error message. | 145 | // Generic function to get last error message. |
| 160 | // Call directly after the command or use the error num. | 146 | // Call directly after the command or use the error num. |
| 161 | // This function might change the error code. | 147 | // This function might change the error code. |
| @@ -232,13 +218,4 @@ inline void swap<8>(u8* data) | |||
| 232 | *reinterpret_cast<u64*>(data) = swap64(data); | 218 | *reinterpret_cast<u64*>(data) = swap64(data); |
| 233 | } | 219 | } |
| 234 | 220 | ||
| 235 | template <typename T> | ||
| 236 | inline T FromBigEndian(T data) | ||
| 237 | { | ||
| 238 | //static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types"); | ||
| 239 | |||
| 240 | swap<sizeof(data)>(reinterpret_cast<u8*>(&data)); | ||
| 241 | return data; | ||
| 242 | } | ||
| 243 | |||
| 244 | } // Namespace Common | 221 | } // Namespace Common |
diff --git a/src/common/hash.cpp b/src/common/hash.cpp index 50c7cb5f9..0624dab8d 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp | |||
| @@ -156,7 +156,7 @@ u64 GetMurmurHash3(const u8 *src, int len, u32 samples) | |||
| 156 | const u8 * data = (const u8*)src; | 156 | const u8 * data = (const u8*)src; |
| 157 | const int nblocks = len / 16; | 157 | const int nblocks = len / 16; |
| 158 | u32 Step = (len / 8); | 158 | u32 Step = (len / 8); |
| 159 | if(samples == 0) samples = max(Step, 1u); | 159 | if(samples == 0) samples = std::max(Step, 1u); |
| 160 | Step = Step / samples; | 160 | Step = Step / samples; |
| 161 | if(Step < 1) Step = 1; | 161 | if(Step < 1) Step = 1; |
| 162 | 162 | ||
| @@ -234,7 +234,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples) | |||
| 234 | u32 Step = (len / 8); | 234 | u32 Step = (len / 8); |
| 235 | const u64 *data = (const u64 *)src; | 235 | const u64 *data = (const u64 *)src; |
| 236 | const u64 *end = data + Step; | 236 | const u64 *end = data + Step; |
| 237 | if(samples == 0) samples = max(Step, 1u); | 237 | if(samples == 0) samples = std::max(Step, 1u); |
| 238 | Step = Step / samples; | 238 | Step = Step / samples; |
| 239 | if(Step < 1) Step = 1; | 239 | if(Step < 1) Step = 1; |
| 240 | while(data < end) | 240 | while(data < end) |
| @@ -266,7 +266,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples) | |||
| 266 | u32 Step = (len / 8); | 266 | u32 Step = (len / 8); |
| 267 | const u64 *data = (const u64 *)src; | 267 | const u64 *data = (const u64 *)src; |
| 268 | const u64 *end = data + Step; | 268 | const u64 *end = data + Step; |
| 269 | if(samples == 0) samples = max(Step, 1u); | 269 | if(samples == 0) samples = std::max(Step, 1u); |
| 270 | Step = Step / samples; | 270 | Step = Step / samples; |
| 271 | if(Step < 1) Step = 1; | 271 | if(Step < 1) Step = 1; |
| 272 | while(data < end) | 272 | while(data < end) |
| @@ -309,7 +309,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples) | |||
| 309 | u32 Step = (len/4); | 309 | u32 Step = (len/4); |
| 310 | const u32 *data = (const u32 *)src; | 310 | const u32 *data = (const u32 *)src; |
| 311 | const u32 *end = data + Step; | 311 | const u32 *end = data + Step; |
| 312 | if(samples == 0) samples = max(Step, 1u); | 312 | if(samples == 0) samples = std::max(Step, 1u); |
| 313 | Step = Step / samples; | 313 | Step = Step / samples; |
| 314 | if(Step < 1) Step = 1; | 314 | if(Step < 1) Step = 1; |
| 315 | while(data < end) | 315 | while(data < end) |
| @@ -381,7 +381,7 @@ u64 GetMurmurHash3(const u8* src, int len, u32 samples) | |||
| 381 | u32 out[2]; | 381 | u32 out[2]; |
| 382 | const int nblocks = len / 8; | 382 | const int nblocks = len / 8; |
| 383 | u32 Step = (len / 4); | 383 | u32 Step = (len / 4); |
| 384 | if(samples == 0) samples = max(Step, 1u); | 384 | if(samples == 0) samples = std::max(Step, 1u); |
| 385 | Step = Step / samples; | 385 | Step = Step / samples; |
| 386 | if(Step < 1) Step = 1; | 386 | if(Step < 1) Step = 1; |
| 387 | 387 | ||
| @@ -457,7 +457,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples) | |||
| 457 | u32 Step = (len / 8); | 457 | u32 Step = (len / 8); |
| 458 | const u64 *data = (const u64 *)src; | 458 | const u64 *data = (const u64 *)src; |
| 459 | const u64 *end = data + Step; | 459 | const u64 *end = data + Step; |
| 460 | if(samples == 0) samples = max(Step, 1u); | 460 | if(samples == 0) samples = std::max(Step, 1u); |
| 461 | Step = Step / samples; | 461 | Step = Step / samples; |
| 462 | if(Step < 1) Step = 1; | 462 | if(Step < 1) Step = 1; |
| 463 | while(data < end) | 463 | while(data < end) |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f8c834a8d..be1aed615 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <vector> | 7 | #include <vector> |
| 8 | 8 | ||
| 9 | #include "common/common.h" | 9 | #include "common/common.h" |
| 10 | #include "common/math_util.h" | ||
| 10 | #include "common/thread_queue_list.h" | 11 | #include "common/thread_queue_list.h" |
| 11 | 12 | ||
| 12 | #include "core/arm/arm_interface.h" | 13 | #include "core/arm/arm_interface.h" |
| @@ -339,7 +340,7 @@ static void DebugThreadQueue() { | |||
| 339 | ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority, | 340 | ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority, |
| 340 | u32 arg, s32 processor_id, VAddr stack_top) { | 341 | u32 arg, s32 processor_id, VAddr stack_top) { |
| 341 | if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { | 342 | if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { |
| 342 | s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); | 343 | s32 new_priority = MathUtil::Clamp<s32>(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); |
| 343 | LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", | 344 | LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", |
| 344 | name.c_str(), priority, new_priority); | 345 | name.c_str(), priority, new_priority); |
| 345 | // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm | 346 | // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm |
| @@ -387,7 +388,7 @@ static void ClampPriority(const Thread* thread, s32* priority) { | |||
| 387 | if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) { | 388 | if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) { |
| 388 | DEBUG_ASSERT_MSG(false, "Application passed an out of range priority. An error should be returned."); | 389 | DEBUG_ASSERT_MSG(false, "Application passed an out of range priority. An error should be returned."); |
| 389 | 390 | ||
| 390 | s32 new_priority = CLAMP(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); | 391 | s32 new_priority = MathUtil::Clamp<s32>(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); |
| 391 | LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", | 392 | LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", |
| 392 | thread->name.c_str(), *priority, new_priority); | 393 | thread->name.c_str(), *priority, new_priority); |
| 393 | // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm | 394 | // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm |