summaryrefslogtreecommitdiff
path: root/src/common/common_funcs.h
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-07 11:45:45 -0700
committerGravatar Yuri Kunde Schlesner2015-05-07 11:45:45 -0700
commit4f4d230dac936f32cceb8be35fe09822d85bb2b6 (patch)
treea180a736708834708e0e5b95fd1720f37722b429 /src/common/common_funcs.h
parentMerge pull request #695 from Subv/crash_f (diff)
parentFix printf format warning (diff)
downloadyuzu-4f4d230dac936f32cceb8be35fe09822d85bb2b6.tar.gz
yuzu-4f4d230dac936f32cceb8be35fe09822d85bb2b6.tar.xz
yuzu-4f4d230dac936f32cceb8be35fe09822d85bb2b6.zip
Merge pull request #721 from yuriks/more-cleanups
More cleanups
Diffstat (limited to '')
-rw-r--r--src/common/common_funcs.h82
1 files changed, 23 insertions, 59 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index e76cb7d68..4f9e514c9 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -7,13 +7,6 @@
7#include "common_types.h" 7#include "common_types.h"
8#include <cstdlib> 8#include <cstdlib>
9 9
10#ifdef _WIN32
11#define SLEEP(x) Sleep(x)
12#else
13#include <unistd.h>
14#define SLEEP(x) usleep(x*1000)
15#endif
16
17 10
18#define b2(x) ( (x) | ( (x) >> 1) ) 11#define b2(x) ( (x) | ( (x) >> 1) )
19#define b4(x) ( b2(x) | ( b2(x) >> 2) ) 12#define b4(x) ( b2(x) | ( b2(x) >> 2) )
@@ -34,6 +27,27 @@
34#define INSERT_PADDING_BYTES(num_bytes) u8 CONCAT2(pad, __LINE__)[(num_bytes)] 27#define INSERT_PADDING_BYTES(num_bytes) u8 CONCAT2(pad, __LINE__)[(num_bytes)]
35#define INSERT_PADDING_WORDS(num_words) u32 CONCAT2(pad, __LINE__)[(num_words)] 28#define INSERT_PADDING_WORDS(num_words) u32 CONCAT2(pad, __LINE__)[(num_words)]
36 29
30#ifdef _WIN32
31 // Alignment
32 #define MEMORY_ALIGNED16(x) __declspec(align(16)) x
33 #define MEMORY_ALIGNED32(x) __declspec(align(32)) x
34 #define MEMORY_ALIGNED64(x) __declspec(align(64)) x
35 #define MEMORY_ALIGNED128(x) __declspec(align(128)) x
36#else
37 // Windows compatibility
38 #ifdef _LP64
39 #define _M_X64 1
40 #else
41 #define _M_IX86 1
42 #endif
43
44 #define __forceinline inline __attribute__((always_inline))
45 #define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
46 #define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
47 #define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
48 #define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
49#endif
50
37#ifndef _MSC_VER 51#ifndef _MSC_VER
38 52
39#include <errno.h> 53#include <errno.h>
@@ -73,61 +87,11 @@ inline u64 _rotr64(u64 x, unsigned int shift){
73} 87}
74 88
75#else // _MSC_VER 89#else // _MSC_VER
76#include <locale.h> 90 // Function Cross-Compatibility
77
78// Function Cross-Compatibility
79 #define strcasecmp _stricmp
80 #define strncasecmp _strnicmp
81 #define unlink _unlink
82 #define snprintf _snprintf 91 #define snprintf _snprintf
83 #define vscprintf _vscprintf
84 92
85// Locale Cross-Compatibility 93 // Locale Cross-Compatibility
86 #define locale_t _locale_t 94 #define locale_t _locale_t
87 #define freelocale _free_locale
88 #define newlocale(mask, locale, base) _create_locale(mask, locale)
89
90 #define LC_GLOBAL_LOCALE ((locale_t)-1)
91 #define LC_ALL_MASK LC_ALL
92 #define LC_COLLATE_MASK LC_COLLATE
93 #define LC_CTYPE_MASK LC_CTYPE
94 #define LC_MONETARY_MASK LC_MONETARY
95 #define LC_NUMERIC_MASK LC_NUMERIC
96 #define LC_TIME_MASK LC_TIME
97
98 inline locale_t uselocale(locale_t new_locale)
99 {
100 // Retrieve the current per thread locale setting
101 bool bIsPerThread = (_configthreadlocale(0) == _ENABLE_PER_THREAD_LOCALE);
102
103 // Retrieve the current thread-specific locale
104 locale_t old_locale = bIsPerThread ? _get_current_locale() : LC_GLOBAL_LOCALE;
105
106 if(new_locale == LC_GLOBAL_LOCALE)
107 {
108 // Restore the global locale
109 _configthreadlocale(_DISABLE_PER_THREAD_LOCALE);
110 }
111 else if(new_locale != nullptr)
112 {
113 // Configure the thread to set the locale only for this thread
114 _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
115
116 // Set all locale categories
117 for(int i = LC_MIN; i <= LC_MAX; i++)
118 setlocale(i, new_locale->locinfo->lc_category[i].locale);
119 }
120
121 return old_locale;
122 }
123
124// 64 bit offsets for windows
125 #define fseeko _fseeki64
126 #define ftello _ftelli64
127 #define atoll _atoi64
128 #define stat64 _stat64
129 #define fstat64 _fstat64
130 #define fileno _fileno
131 95
132 extern "C" { 96 extern "C" {
133 __declspec(dllimport) void __stdcall DebugBreak(void); 97 __declspec(dllimport) void __stdcall DebugBreak(void);