mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-24 12:26:26 -05:00
Misc cleanup of common and related functions
This commit is contained in:
parent
302f0b32f5
commit
4fb75d220a
4 changed files with 31 additions and 81 deletions
|
@ -35,13 +35,11 @@ private:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// The Darwin ABI requires that stack frames be aligned to 16-byte boundaries.
|
// The Darwin ABI requires that stack frames be aligned to 16-byte boundaries.
|
||||||
// This is only needed on i386 gcc - x86_64 already aligns to 16 bytes.
|
// This is only needed on i386 gcc - x86_64 already aligns to 16 bytes.
|
||||||
#if defined __i386__ && defined __GNUC__
|
#if defined __i386__ && defined __GNUC__
|
||||||
#undef STACKALIGN
|
#undef STACKALIGN
|
||||||
#define STACKALIGN __attribute__((__force_align_arg_pointer__))
|
#define STACKALIGN __attribute__((__force_align_arg_pointer__))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
|
|
||||||
// Check MSC ver
|
// Check MSC ver
|
||||||
#if defined _MSC_VER && _MSC_VER <= 1000
|
#if defined _MSC_VER && _MSC_VER <= 1000
|
||||||
#error needs at least version 1000 of MSC
|
#error needs at least version 1000 of MSC
|
||||||
|
@ -51,9 +49,6 @@ private:
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Memory leak checks
|
|
||||||
#define CHECK_HEAP_INTEGRITY()
|
|
||||||
|
|
||||||
// Alignment
|
// Alignment
|
||||||
#define MEMORY_ALIGNED16(x) __declspec(align(16)) x
|
#define MEMORY_ALIGNED16(x) __declspec(align(16)) x
|
||||||
#define MEMORY_ALIGNED32(x) __declspec(align(32)) x
|
#define MEMORY_ALIGNED32(x) __declspec(align(32)) x
|
||||||
|
@ -61,57 +56,34 @@ private:
|
||||||
#define MEMORY_ALIGNED128(x) __declspec(align(128)) x
|
#define MEMORY_ALIGNED128(x) __declspec(align(128)) x
|
||||||
#define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x
|
#define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x
|
||||||
#define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x
|
#define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x
|
||||||
|
|
||||||
// Since they are always around on windows
|
|
||||||
#define HAVE_WX 1
|
|
||||||
#define HAVE_OPENAL 1
|
|
||||||
|
|
||||||
#define HAVE_PORTAUDIO 1
|
|
||||||
|
|
||||||
// Debug definitions
|
|
||||||
#if defined(_DEBUG)
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#undef CHECK_HEAP_INTEGRITY
|
|
||||||
#define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");}
|
|
||||||
// If you want to see how much a pain in the ass singletons are, for example:
|
|
||||||
// {614} normal block at 0x030C5310, 188 bytes long.
|
|
||||||
// Data: <Master Log > 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00
|
|
||||||
struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } };
|
|
||||||
//CrtDebugBreak breakAt(614);
|
|
||||||
#endif // end DEBUG/FAST
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Windows compatibility
|
// Windows compatibility
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#ifdef _LP64
|
#ifdef _LP64
|
||||||
#define _M_X64 1
|
#define _M_X64 1
|
||||||
#else
|
#else
|
||||||
#define _M_IX86 1
|
#define _M_IX86 1
|
||||||
#endif
|
#endif
|
||||||
#define __forceinline inline __attribute__((always_inline))
|
#define __forceinline inline __attribute__((always_inline))
|
||||||
#define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
|
#define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
|
||||||
#define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
|
#define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
|
||||||
#define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
|
#define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
|
||||||
#define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
|
#define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
|
||||||
#define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
|
#define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
|
||||||
#define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
|
#define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define __strdup _strdup
|
#define __strdup _strdup
|
||||||
#define __getcwd _getcwd
|
#define __getcwd _getcwd
|
||||||
#define __chdir _chdir
|
#define __chdir _chdir
|
||||||
#else
|
#else
|
||||||
#define __strdup strdup
|
#define __strdup strdup
|
||||||
#define __getcwd getcwd
|
#define __getcwd getcwd
|
||||||
#define __chdir chdir
|
#define __chdir chdir
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Dummy macro for marking translatable strings that can not be immediately translated.
|
|
||||||
// wxWidgets does not have a true dummy macro for this.
|
|
||||||
#define _trans(a) a
|
|
||||||
|
|
||||||
#if defined _M_GENERIC
|
#if defined _M_GENERIC
|
||||||
# define _M_SSE 0x0
|
# define _M_SSE 0x0
|
||||||
#elif defined __GNUC__
|
#elif defined __GNUC__
|
||||||
|
|
|
@ -24,11 +24,6 @@ template<> struct CompileTimeAssert<true> {};
|
||||||
#define b32(x) (b16(x) | (b16(x) >>16) )
|
#define b32(x) (b16(x) | (b16(x) >>16) )
|
||||||
#define ROUND_UP_POW2(x) (b32(x - 1) + 1)
|
#define ROUND_UP_POW2(x) (b32(x - 1) + 1)
|
||||||
|
|
||||||
#define MIN(a, b) ((a)<(b)?(a):(b))
|
|
||||||
#define MAX(a, b) ((a)>(b)?(a):(b))
|
|
||||||
|
|
||||||
#define CLAMP(x, min, max) (((x) > max) ? max : (((x) < min) ? min : (x)))
|
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
|
||||||
/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
|
/// 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){
|
||||||
#define Crash() {DebugBreak();}
|
#define Crash() {DebugBreak();}
|
||||||
#endif // _MSC_VER ndef
|
#endif // _MSC_VER ndef
|
||||||
|
|
||||||
// Dolphin's min and max functions
|
|
||||||
#undef min
|
|
||||||
#undef max
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline T min(const T& a, const T& b) {return a > b ? b : a;}
|
|
||||||
template<class T>
|
|
||||||
inline T max(const T& a, const T& b) {return a > b ? a : b;}
|
|
||||||
|
|
||||||
// Generic function to get last error message.
|
// Generic function to get last error message.
|
||||||
// Call directly after the command or use the error num.
|
// Call directly after the command or use the error num.
|
||||||
// This function might change the error code.
|
// This function might change the error code.
|
||||||
|
@ -232,13 +218,4 @@ inline void swap<8>(u8* data)
|
||||||
*reinterpret_cast<u64*>(data) = swap64(data);
|
*reinterpret_cast<u64*>(data) = swap64(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline T FromBigEndian(T data)
|
|
||||||
{
|
|
||||||
//static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");
|
|
||||||
|
|
||||||
swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Namespace Common
|
} // Namespace Common
|
||||||
|
|
|
@ -156,7 +156,7 @@ u64 GetMurmurHash3(const u8 *src, int len, u32 samples)
|
||||||
const u8 * data = (const u8*)src;
|
const u8 * data = (const u8*)src;
|
||||||
const int nblocks = len / 16;
|
const int nblocks = len / 16;
|
||||||
u32 Step = (len / 8);
|
u32 Step = (len / 8);
|
||||||
if(samples == 0) samples = max(Step, 1u);
|
if(samples == 0) samples = std::max(Step, 1u);
|
||||||
Step = Step / samples;
|
Step = Step / samples;
|
||||||
if(Step < 1) Step = 1;
|
if(Step < 1) Step = 1;
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
|
||||||
u32 Step = (len / 8);
|
u32 Step = (len / 8);
|
||||||
const u64 *data = (const u64 *)src;
|
const u64 *data = (const u64 *)src;
|
||||||
const u64 *end = data + Step;
|
const u64 *end = data + Step;
|
||||||
if(samples == 0) samples = max(Step, 1u);
|
if(samples == 0) samples = std::max(Step, 1u);
|
||||||
Step = Step / samples;
|
Step = Step / samples;
|
||||||
if(Step < 1) Step = 1;
|
if(Step < 1) Step = 1;
|
||||||
while(data < end)
|
while(data < end)
|
||||||
|
@ -266,7 +266,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
|
||||||
u32 Step = (len / 8);
|
u32 Step = (len / 8);
|
||||||
const u64 *data = (const u64 *)src;
|
const u64 *data = (const u64 *)src;
|
||||||
const u64 *end = data + Step;
|
const u64 *end = data + Step;
|
||||||
if(samples == 0) samples = max(Step, 1u);
|
if(samples == 0) samples = std::max(Step, 1u);
|
||||||
Step = Step / samples;
|
Step = Step / samples;
|
||||||
if(Step < 1) Step = 1;
|
if(Step < 1) Step = 1;
|
||||||
while(data < end)
|
while(data < end)
|
||||||
|
@ -309,7 +309,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
|
||||||
u32 Step = (len/4);
|
u32 Step = (len/4);
|
||||||
const u32 *data = (const u32 *)src;
|
const u32 *data = (const u32 *)src;
|
||||||
const u32 *end = data + Step;
|
const u32 *end = data + Step;
|
||||||
if(samples == 0) samples = max(Step, 1u);
|
if(samples == 0) samples = std::max(Step, 1u);
|
||||||
Step = Step / samples;
|
Step = Step / samples;
|
||||||
if(Step < 1) Step = 1;
|
if(Step < 1) Step = 1;
|
||||||
while(data < end)
|
while(data < end)
|
||||||
|
@ -381,7 +381,7 @@ u64 GetMurmurHash3(const u8* src, int len, u32 samples)
|
||||||
u32 out[2];
|
u32 out[2];
|
||||||
const int nblocks = len / 8;
|
const int nblocks = len / 8;
|
||||||
u32 Step = (len / 4);
|
u32 Step = (len / 4);
|
||||||
if(samples == 0) samples = max(Step, 1u);
|
if(samples == 0) samples = std::max(Step, 1u);
|
||||||
Step = Step / samples;
|
Step = Step / samples;
|
||||||
if(Step < 1) Step = 1;
|
if(Step < 1) Step = 1;
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
|
||||||
u32 Step = (len / 8);
|
u32 Step = (len / 8);
|
||||||
const u64 *data = (const u64 *)src;
|
const u64 *data = (const u64 *)src;
|
||||||
const u64 *end = data + Step;
|
const u64 *end = data + Step;
|
||||||
if(samples == 0) samples = max(Step, 1u);
|
if(samples == 0) samples = std::max(Step, 1u);
|
||||||
Step = Step / samples;
|
Step = Step / samples;
|
||||||
if(Step < 1) Step = 1;
|
if(Step < 1) Step = 1;
|
||||||
while(data < end)
|
while(data < end)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
#include "common/math_util.h"
|
||||||
#include "common/thread_queue_list.h"
|
#include "common/thread_queue_list.h"
|
||||||
|
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
|
@ -339,7 +340,7 @@ static void DebugThreadQueue() {
|
||||||
ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority,
|
ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority,
|
||||||
u32 arg, s32 processor_id, VAddr stack_top) {
|
u32 arg, s32 processor_id, VAddr stack_top) {
|
||||||
if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
|
if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
|
||||||
s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
|
s32 new_priority = MathUtil::Clamp<s32>(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
|
||||||
LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
|
LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
|
||||||
name.c_str(), priority, new_priority);
|
name.c_str(), priority, new_priority);
|
||||||
// TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
|
// 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) {
|
||||||
if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) {
|
if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) {
|
||||||
DEBUG_ASSERT_MSG(false, "Application passed an out of range priority. An error should be returned.");
|
DEBUG_ASSERT_MSG(false, "Application passed an out of range priority. An error should be returned.");
|
||||||
|
|
||||||
s32 new_priority = CLAMP(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
|
s32 new_priority = MathUtil::Clamp<s32>(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
|
||||||
LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
|
LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
|
||||||
thread->name.c_str(), *priority, new_priority);
|
thread->name.c_str(), *priority, new_priority);
|
||||||
// TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
|
// TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
|
||||||
|
|
Loading…
Reference in a new issue