summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/alignment.h4
-rw-r--r--src/common/bit_field.h4
-rw-r--r--src/common/bit_set.h6
-rw-r--r--src/common/cityhash.cpp22
-rw-r--r--src/common/cityhash.h12
-rw-r--r--src/common/file_util.cpp16
-rw-r--r--src/common/file_util.h25
-rw-r--r--src/common/hash.h4
-rw-r--r--src/common/hex_util.cpp4
-rw-r--r--src/common/hex_util.h12
-rw-r--r--src/common/logging/backend.cpp2
-rw-r--r--src/common/logging/backend.h2
-rw-r--r--src/common/logging/filter.cpp5
-rw-r--r--src/common/logging/filter.h2
-rw-r--r--src/common/memory_util.cpp12
-rw-r--r--src/common/memory_util.h12
-rw-r--r--src/common/misc.cpp2
-rw-r--r--src/common/ring_buffer.h50
-rw-r--r--src/common/string_util.cpp42
-rw-r--r--src/common/string_util.h4
-rw-r--r--src/common/thread.h10
-rw-r--r--src/common/x64/xbyak_abi.h21
-rw-r--r--src/common/x64/xbyak_util.h2
23 files changed, 140 insertions, 135 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h
index b9dd38746..225770fab 100644
--- a/src/common/alignment.h
+++ b/src/common/alignment.h
@@ -8,13 +8,13 @@
8namespace Common { 8namespace Common {
9 9
10template <typename T> 10template <typename T>
11constexpr T AlignUp(T value, size_t size) { 11constexpr T AlignUp(T value, std::size_t size) {
12 static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); 12 static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
13 return static_cast<T>(value + (size - value % size) % size); 13 return static_cast<T>(value + (size - value % size) % size);
14} 14}
15 15
16template <typename T> 16template <typename T>
17constexpr T AlignDown(T value, size_t size) { 17constexpr T AlignDown(T value, std::size_t size) {
18 static_assert(std::is_unsigned_v<T>, "T must be an unsigned value."); 18 static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
19 return static_cast<T>(value - value % size); 19 return static_cast<T>(value - value % size);
20} 20}
diff --git a/src/common/bit_field.h b/src/common/bit_field.h
index 732201de7..bf803da8d 100644
--- a/src/common/bit_field.h
+++ b/src/common/bit_field.h
@@ -129,8 +129,8 @@ private:
129 129
130public: 130public:
131 /// Constants to allow limited introspection of fields if needed 131 /// Constants to allow limited introspection of fields if needed
132 static constexpr size_t position = Position; 132 static constexpr std::size_t position = Position;
133 static constexpr size_t bits = Bits; 133 static constexpr std::size_t bits = Bits;
134 static constexpr StorageType mask = (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position; 134 static constexpr StorageType mask = (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position;
135 135
136 /** 136 /**
diff --git a/src/common/bit_set.h b/src/common/bit_set.h
index 5a197d8c1..5cd1352b2 100644
--- a/src/common/bit_set.h
+++ b/src/common/bit_set.h
@@ -170,14 +170,14 @@ public:
170 m_val |= (IntTy)1 << bit; 170 m_val |= (IntTy)1 << bit;
171 } 171 }
172 172
173 static BitSet AllTrue(size_t count) { 173 static BitSet AllTrue(std::size_t count) {
174 return BitSet(count == sizeof(IntTy) * 8 ? ~(IntTy)0 : (((IntTy)1 << count) - 1)); 174 return BitSet(count == sizeof(IntTy) * 8 ? ~(IntTy)0 : (((IntTy)1 << count) - 1));
175 } 175 }
176 176
177 Ref operator[](size_t bit) { 177 Ref operator[](std::size_t bit) {
178 return Ref(this, (IntTy)1 << bit); 178 return Ref(this, (IntTy)1 << bit);
179 } 179 }
180 const Ref operator[](size_t bit) const { 180 const Ref operator[](std::size_t bit) const {
181 return (*const_cast<BitSet*>(this))[bit]; 181 return (*const_cast<BitSet*>(this))[bit];
182 } 182 }
183 bool operator==(BitSet other) const { 183 bool operator==(BitSet other) const {
diff --git a/src/common/cityhash.cpp b/src/common/cityhash.cpp
index de31ffbd8..4e1d874b5 100644
--- a/src/common/cityhash.cpp
+++ b/src/common/cityhash.cpp
@@ -114,7 +114,7 @@ static uint64 HashLen16(uint64 u, uint64 v, uint64 mul) {
114 return b; 114 return b;
115} 115}
116 116
117static uint64 HashLen0to16(const char* s, size_t len) { 117static uint64 HashLen0to16(const char* s, std::size_t len) {
118 if (len >= 8) { 118 if (len >= 8) {
119 uint64 mul = k2 + len * 2; 119 uint64 mul = k2 + len * 2;
120 uint64 a = Fetch64(s) + k2; 120 uint64 a = Fetch64(s) + k2;
@@ -141,7 +141,7 @@ static uint64 HashLen0to16(const char* s, size_t len) {
141 141
142// This probably works well for 16-byte strings as well, but it may be overkill 142// This probably works well for 16-byte strings as well, but it may be overkill
143// in that case. 143// in that case.
144static uint64 HashLen17to32(const char* s, size_t len) { 144static uint64 HashLen17to32(const char* s, std::size_t len) {
145 uint64 mul = k2 + len * 2; 145 uint64 mul = k2 + len * 2;
146 uint64 a = Fetch64(s) * k1; 146 uint64 a = Fetch64(s) * k1;
147 uint64 b = Fetch64(s + 8); 147 uint64 b = Fetch64(s + 8);
@@ -170,7 +170,7 @@ static pair<uint64, uint64> WeakHashLen32WithSeeds(const char* s, uint64 a, uint
170} 170}
171 171
172// Return an 8-byte hash for 33 to 64 bytes. 172// Return an 8-byte hash for 33 to 64 bytes.
173static uint64 HashLen33to64(const char* s, size_t len) { 173static uint64 HashLen33to64(const char* s, std::size_t len) {
174 uint64 mul = k2 + len * 2; 174 uint64 mul = k2 + len * 2;
175 uint64 a = Fetch64(s) * k2; 175 uint64 a = Fetch64(s) * k2;
176 uint64 b = Fetch64(s + 8); 176 uint64 b = Fetch64(s + 8);
@@ -191,7 +191,7 @@ static uint64 HashLen33to64(const char* s, size_t len) {
191 return b + x; 191 return b + x;
192} 192}
193 193
194uint64 CityHash64(const char* s, size_t len) { 194uint64 CityHash64(const char* s, std::size_t len) {
195 if (len <= 32) { 195 if (len <= 32) {
196 if (len <= 16) { 196 if (len <= 16) {
197 return HashLen0to16(s, len); 197 return HashLen0to16(s, len);
@@ -212,7 +212,7 @@ uint64 CityHash64(const char* s, size_t len) {
212 x = x * k1 + Fetch64(s); 212 x = x * k1 + Fetch64(s);
213 213
214 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. 214 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
215 len = (len - 1) & ~static_cast<size_t>(63); 215 len = (len - 1) & ~static_cast<std::size_t>(63);
216 do { 216 do {
217 x = Rotate(x + y + v.first + Fetch64(s + 8), 37) * k1; 217 x = Rotate(x + y + v.first + Fetch64(s + 8), 37) * k1;
218 y = Rotate(y + v.second + Fetch64(s + 48), 42) * k1; 218 y = Rotate(y + v.second + Fetch64(s + 48), 42) * k1;
@@ -229,17 +229,17 @@ uint64 CityHash64(const char* s, size_t len) {
229 HashLen16(v.second, w.second) + x); 229 HashLen16(v.second, w.second) + x);
230} 230}
231 231
232uint64 CityHash64WithSeed(const char* s, size_t len, uint64 seed) { 232uint64 CityHash64WithSeed(const char* s, std::size_t len, uint64 seed) {
233 return CityHash64WithSeeds(s, len, k2, seed); 233 return CityHash64WithSeeds(s, len, k2, seed);
234} 234}
235 235
236uint64 CityHash64WithSeeds(const char* s, size_t len, uint64 seed0, uint64 seed1) { 236uint64 CityHash64WithSeeds(const char* s, std::size_t len, uint64 seed0, uint64 seed1) {
237 return HashLen16(CityHash64(s, len) - seed0, seed1); 237 return HashLen16(CityHash64(s, len) - seed0, seed1);
238} 238}
239 239
240// A subroutine for CityHash128(). Returns a decent 128-bit hash for strings 240// A subroutine for CityHash128(). Returns a decent 128-bit hash for strings
241// of any length representable in signed long. Based on City and Murmur. 241// of any length representable in signed long. Based on City and Murmur.
242static uint128 CityMurmur(const char* s, size_t len, uint128 seed) { 242static uint128 CityMurmur(const char* s, std::size_t len, uint128 seed) {
243 uint64 a = Uint128Low64(seed); 243 uint64 a = Uint128Low64(seed);
244 uint64 b = Uint128High64(seed); 244 uint64 b = Uint128High64(seed);
245 uint64 c = 0; 245 uint64 c = 0;
@@ -269,7 +269,7 @@ static uint128 CityMurmur(const char* s, size_t len, uint128 seed) {
269 return uint128(a ^ b, HashLen16(b, a)); 269 return uint128(a ^ b, HashLen16(b, a));
270} 270}
271 271
272uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed) { 272uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed) {
273 if (len < 128) { 273 if (len < 128) {
274 return CityMurmur(s, len, seed); 274 return CityMurmur(s, len, seed);
275 } 275 }
@@ -313,7 +313,7 @@ uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed) {
313 w.first *= 9; 313 w.first *= 9;
314 v.first *= k0; 314 v.first *= k0;
315 // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s. 315 // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s.
316 for (size_t tail_done = 0; tail_done < len;) { 316 for (std::size_t tail_done = 0; tail_done < len;) {
317 tail_done += 32; 317 tail_done += 32;
318 y = Rotate(x + y, 42) * k0 + v.second; 318 y = Rotate(x + y, 42) * k0 + v.second;
319 w.first += Fetch64(s + len - tail_done + 16); 319 w.first += Fetch64(s + len - tail_done + 16);
@@ -331,7 +331,7 @@ uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed) {
331 return uint128(HashLen16(x + v.second, w.second) + y, HashLen16(x + w.second, y + v.second)); 331 return uint128(HashLen16(x + v.second, w.second) + y, HashLen16(x + w.second, y + v.second));
332} 332}
333 333
334uint128 CityHash128(const char* s, size_t len) { 334uint128 CityHash128(const char* s, std::size_t len) {
335 return len >= 16 335 return len >= 16
336 ? CityHash128WithSeed(s + 16, len - 16, uint128(Fetch64(s), Fetch64(s + 8) + k0)) 336 ? CityHash128WithSeed(s + 16, len - 16, uint128(Fetch64(s), Fetch64(s + 8) + k0))
337 : CityHash128WithSeed(s, len, uint128(k0, k1)); 337 : CityHash128WithSeed(s, len, uint128(k0, k1));
diff --git a/src/common/cityhash.h b/src/common/cityhash.h
index bcebdb150..4b94f8e18 100644
--- a/src/common/cityhash.h
+++ b/src/common/cityhash.h
@@ -63,7 +63,7 @@
63 63
64#include <utility> 64#include <utility>
65#include <stdint.h> 65#include <stdint.h>
66#include <stdlib.h> // for size_t. 66#include <stdlib.h> // for std::size_t.
67 67
68namespace Common { 68namespace Common {
69 69
@@ -77,22 +77,22 @@ inline uint64_t Uint128High64(const uint128& x) {
77} 77}
78 78
79// Hash function for a byte array. 79// Hash function for a byte array.
80uint64_t CityHash64(const char* buf, size_t len); 80uint64_t CityHash64(const char* buf, std::size_t len);
81 81
82// Hash function for a byte array. For convenience, a 64-bit seed is also 82// Hash function for a byte array. For convenience, a 64-bit seed is also
83// hashed into the result. 83// hashed into the result.
84uint64_t CityHash64WithSeed(const char* buf, size_t len, uint64_t seed); 84uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed);
85 85
86// Hash function for a byte array. For convenience, two seeds are also 86// Hash function for a byte array. For convenience, two seeds are also
87// hashed into the result. 87// hashed into the result.
88uint64_t CityHash64WithSeeds(const char* buf, size_t len, uint64_t seed0, uint64_t seed1); 88uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, uint64_t seed1);
89 89
90// Hash function for a byte array. 90// Hash function for a byte array.
91uint128 CityHash128(const char* s, size_t len); 91uint128 CityHash128(const char* s, std::size_t len);
92 92
93// Hash function for a byte array. For convenience, a 128-bit seed is also 93// Hash function for a byte array. For convenience, a 128-bit seed is also
94// hashed into the result. 94// hashed into the result.
95uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed); 95uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed);
96 96
97// Hash 128 input bits down to 64 bits of output. 97// Hash 128 input bits down to 64 bits of output.
98// This is intended to be a reasonably good hash function. 98// This is intended to be a reasonably good hash function.
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index baa721481..21a0b9738 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -76,7 +76,7 @@ namespace FileUtil {
76// Modifies argument. 76// Modifies argument.
77static void StripTailDirSlashes(std::string& fname) { 77static void StripTailDirSlashes(std::string& fname) {
78 if (fname.length() > 1) { 78 if (fname.length() > 1) {
79 size_t i = fname.length(); 79 std::size_t i = fname.length();
80 while (i > 0 && fname[i - 1] == DIR_SEP_CHR) 80 while (i > 0 && fname[i - 1] == DIR_SEP_CHR)
81 --i; 81 --i;
82 fname.resize(i); 82 fname.resize(i);
@@ -201,7 +201,7 @@ bool CreateFullPath(const std::string& fullPath) {
201 return true; 201 return true;
202 } 202 }
203 203
204 size_t position = 0; 204 std::size_t position = 0;
205 while (true) { 205 while (true) {
206 // Find next sub path 206 // Find next sub path
207 position = fullPath.find(DIR_SEP_CHR, position); 207 position = fullPath.find(DIR_SEP_CHR, position);
@@ -299,7 +299,7 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
299 std::array<char, 1024> buffer; 299 std::array<char, 1024> buffer;
300 while (!feof(input.get())) { 300 while (!feof(input.get())) {
301 // read input 301 // read input
302 size_t rnum = fread(buffer.data(), sizeof(char), buffer.size(), input.get()); 302 std::size_t rnum = fread(buffer.data(), sizeof(char), buffer.size(), input.get());
303 if (rnum != buffer.size()) { 303 if (rnum != buffer.size()) {
304 if (ferror(input.get()) != 0) { 304 if (ferror(input.get()) != 0) {
305 LOG_ERROR(Common_Filesystem, "failed reading from source, {} --> {}: {}", 305 LOG_ERROR(Common_Filesystem, "failed reading from source, {} --> {}: {}",
@@ -309,7 +309,7 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
309 } 309 }
310 310
311 // write output 311 // write output
312 size_t wnum = fwrite(buffer.data(), sizeof(char), rnum, output.get()); 312 std::size_t wnum = fwrite(buffer.data(), sizeof(char), rnum, output.get());
313 if (wnum != rnum) { 313 if (wnum != rnum) {
314 LOG_ERROR(Common_Filesystem, "failed writing to output, {} --> {}: {}", srcFilename, 314 LOG_ERROR(Common_Filesystem, "failed writing to output, {} --> {}: {}", srcFilename,
315 destFilename, GetLastErrorMsg()); 315 destFilename, GetLastErrorMsg());
@@ -756,11 +756,11 @@ std::string GetNANDRegistrationDir(bool system) {
756 return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/"; 756 return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/";
757} 757}
758 758
759size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) { 759std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) {
760 return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); 760 return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
761} 761}
762 762
763size_t ReadFileToString(bool text_file, const char* filename, std::string& str) { 763std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str) {
764 IOFile file(filename, text_file ? "r" : "rb"); 764 IOFile file(filename, text_file ? "r" : "rb");
765 765
766 if (!file.IsOpen()) 766 if (!file.IsOpen())
@@ -829,7 +829,7 @@ std::vector<std::string> SplitPathComponents(std::string_view filename) {
829std::string_view GetParentPath(std::string_view path) { 829std::string_view GetParentPath(std::string_view path) {
830 const auto name_bck_index = path.rfind('\\'); 830 const auto name_bck_index = path.rfind('\\');
831 const auto name_fwd_index = path.rfind('/'); 831 const auto name_fwd_index = path.rfind('/');
832 size_t name_index; 832 std::size_t name_index;
833 833
834 if (name_bck_index == std::string_view::npos || name_fwd_index == std::string_view::npos) { 834 if (name_bck_index == std::string_view::npos || name_fwd_index == std::string_view::npos) {
835 name_index = std::min(name_bck_index, name_fwd_index); 835 name_index = std::min(name_bck_index, name_fwd_index);
@@ -868,7 +868,7 @@ std::string_view GetFilename(std::string_view path) {
868} 868}
869 869
870std::string_view GetExtensionFromFilename(std::string_view name) { 870std::string_view GetExtensionFromFilename(std::string_view name) {
871 const size_t index = name.rfind('.'); 871 const std::size_t index = name.rfind('.');
872 872
873 if (index == std::string_view::npos) { 873 if (index == std::string_view::npos) {
874 return {}; 874 return {};
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 2f13d0b6b..24c1e413c 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -143,8 +143,9 @@ const std::string& GetExeDirectory();
143std::string AppDataRoamingDirectory(); 143std::string AppDataRoamingDirectory();
144#endif 144#endif
145 145
146size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename); 146std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename);
147size_t ReadFileToString(bool text_file, const char* filename, std::string& str); 147
148std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str);
148 149
149/** 150/**
150 * Splits the filename into 8.3 format 151 * Splits the filename into 8.3 format
@@ -177,10 +178,10 @@ std::string_view RemoveTrailingSlash(std::string_view path);
177 178
178// Creates a new vector containing indices [first, last) from the original. 179// Creates a new vector containing indices [first, last) from the original.
179template <typename T> 180template <typename T>
180std::vector<T> SliceVector(const std::vector<T>& vector, size_t first, size_t last) { 181std::vector<T> SliceVector(const std::vector<T>& vector, std::size_t first, std::size_t last) {
181 if (first >= last) 182 if (first >= last)
182 return {}; 183 return {};
183 last = std::min<size_t>(last, vector.size()); 184 last = std::min<std::size_t>(last, vector.size());
184 return std::vector<T>(vector.begin() + first, vector.begin() + first + last); 185 return std::vector<T>(vector.begin() + first, vector.begin() + first + last);
185} 186}
186 187
@@ -213,47 +214,47 @@ public:
213 bool Close(); 214 bool Close();
214 215
215 template <typename T> 216 template <typename T>
216 size_t ReadArray(T* data, size_t length) const { 217 std::size_t ReadArray(T* data, std::size_t length) const {
217 static_assert(std::is_trivially_copyable_v<T>, 218 static_assert(std::is_trivially_copyable_v<T>,
218 "Given array does not consist of trivially copyable objects"); 219 "Given array does not consist of trivially copyable objects");
219 220
220 if (!IsOpen()) { 221 if (!IsOpen()) {
221 return std::numeric_limits<size_t>::max(); 222 return std::numeric_limits<std::size_t>::max();
222 } 223 }
223 224
224 return std::fread(data, sizeof(T), length, m_file); 225 return std::fread(data, sizeof(T), length, m_file);
225 } 226 }
226 227
227 template <typename T> 228 template <typename T>
228 size_t WriteArray(const T* data, size_t length) { 229 std::size_t WriteArray(const T* data, std::size_t length) {
229 static_assert(std::is_trivially_copyable_v<T>, 230 static_assert(std::is_trivially_copyable_v<T>,
230 "Given array does not consist of trivially copyable objects"); 231 "Given array does not consist of trivially copyable objects");
231 if (!IsOpen()) { 232 if (!IsOpen()) {
232 return std::numeric_limits<size_t>::max(); 233 return std::numeric_limits<std::size_t>::max();
233 } 234 }
234 235
235 return std::fwrite(data, sizeof(T), length, m_file); 236 return std::fwrite(data, sizeof(T), length, m_file);
236 } 237 }
237 238
238 template <typename T> 239 template <typename T>
239 size_t ReadBytes(T* data, size_t length) const { 240 std::size_t ReadBytes(T* data, std::size_t length) const {
240 static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable"); 241 static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
241 return ReadArray(reinterpret_cast<char*>(data), length); 242 return ReadArray(reinterpret_cast<char*>(data), length);
242 } 243 }
243 244
244 template <typename T> 245 template <typename T>
245 size_t WriteBytes(const T* data, size_t length) { 246 std::size_t WriteBytes(const T* data, std::size_t length) {
246 static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable"); 247 static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
247 return WriteArray(reinterpret_cast<const char*>(data), length); 248 return WriteArray(reinterpret_cast<const char*>(data), length);
248 } 249 }
249 250
250 template <typename T> 251 template <typename T>
251 size_t WriteObject(const T& object) { 252 std::size_t WriteObject(const T& object) {
252 static_assert(!std::is_pointer_v<T>, "WriteObject arguments must not be a pointer"); 253 static_assert(!std::is_pointer_v<T>, "WriteObject arguments must not be a pointer");
253 return WriteArray(&object, 1); 254 return WriteArray(&object, 1);
254 } 255 }
255 256
256 size_t WriteString(const std::string& str) { 257 std::size_t WriteString(const std::string& str) {
257 return WriteArray(str.c_str(), str.length()); 258 return WriteArray(str.c_str(), str.length());
258 } 259 }
259 260
diff --git a/src/common/hash.h b/src/common/hash.h
index 2c761e545..40194d1ee 100644
--- a/src/common/hash.h
+++ b/src/common/hash.h
@@ -17,7 +17,7 @@ namespace Common {
17 * @param len Length of data (in bytes) to compute hash over 17 * @param len Length of data (in bytes) to compute hash over
18 * @returns 64-bit hash value that was computed over the data block 18 * @returns 64-bit hash value that was computed over the data block
19 */ 19 */
20static inline u64 ComputeHash64(const void* data, size_t len) { 20static inline u64 ComputeHash64(const void* data, std::size_t len) {
21 return CityHash64(static_cast<const char*>(data), len); 21 return CityHash64(static_cast<const char*>(data), len);
22} 22}
23 23
@@ -63,7 +63,7 @@ struct HashableStruct {
63 return !(*this == o); 63 return !(*this == o);
64 }; 64 };
65 65
66 size_t Hash() const { 66 std::size_t Hash() const {
67 return Common::ComputeStructHash64(state); 67 return Common::ComputeStructHash64(state);
68 } 68 }
69}; 69};
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp
index 8e0a9e46f..589ae5cbf 100644
--- a/src/common/hex_util.cpp
+++ b/src/common/hex_util.cpp
@@ -18,7 +18,7 @@ u8 ToHexNibble(char c1) {
18 return 0; 18 return 0;
19} 19}
20 20
21std::array<u8, 16> operator""_array16(const char* str, size_t len) { 21std::array<u8, 16> operator""_array16(const char* str, std::size_t len) {
22 if (len != 32) { 22 if (len != 32) {
23 LOG_ERROR(Common, 23 LOG_ERROR(Common,
24 "Attempting to parse string to array that is not of correct size (expected=32, " 24 "Attempting to parse string to array that is not of correct size (expected=32, "
@@ -29,7 +29,7 @@ std::array<u8, 16> operator""_array16(const char* str, size_t len) {
29 return HexStringToArray<16>(str); 29 return HexStringToArray<16>(str);
30} 30}
31 31
32std::array<u8, 32> operator""_array32(const char* str, size_t len) { 32std::array<u8, 32> operator""_array32(const char* str, std::size_t len) {
33 if (len != 64) { 33 if (len != 64) {
34 LOG_ERROR(Common, 34 LOG_ERROR(Common,
35 "Attempting to parse string to array that is not of correct size (expected=64, " 35 "Attempting to parse string to array that is not of correct size (expected=64, "
diff --git a/src/common/hex_util.h b/src/common/hex_util.h
index 5fb79bb72..863a5ccd9 100644
--- a/src/common/hex_util.h
+++ b/src/common/hex_util.h
@@ -14,20 +14,20 @@ namespace Common {
14 14
15u8 ToHexNibble(char c1); 15u8 ToHexNibble(char c1);
16 16
17template <size_t Size, bool le = false> 17template <std::size_t Size, bool le = false>
18std::array<u8, Size> HexStringToArray(std::string_view str) { 18std::array<u8, Size> HexStringToArray(std::string_view str) {
19 std::array<u8, Size> out{}; 19 std::array<u8, Size> out{};
20 if constexpr (le) { 20 if constexpr (le) {
21 for (size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) 21 for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2)
22 out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); 22 out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
23 } else { 23 } else {
24 for (size_t i = 0; i < 2 * Size; i += 2) 24 for (std::size_t i = 0; i < 2 * Size; i += 2)
25 out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); 25 out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
26 } 26 }
27 return out; 27 return out;
28} 28}
29 29
30template <size_t Size> 30template <std::size_t Size>
31std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) { 31std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
32 std::string out; 32 std::string out;
33 for (u8 c : array) 33 for (u8 c : array)
@@ -35,7 +35,7 @@ std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
35 return out; 35 return out;
36} 36}
37 37
38std::array<u8, 0x10> operator"" _array16(const char* str, size_t len); 38std::array<u8, 0x10> operator"" _array16(const char* str, std::size_t len);
39std::array<u8, 0x20> operator"" _array32(const char* str, size_t len); 39std::array<u8, 0x20> operator"" _array32(const char* str, std::size_t len);
40 40
41} // namespace Common 41} // namespace Common
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 1323f8d0f..efd776db6 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -135,7 +135,7 @@ FileBackend::FileBackend(const std::string& filename)
135void FileBackend::Write(const Entry& entry) { 135void FileBackend::Write(const Entry& entry) {
136 // prevent logs from going over the maximum size (in case its spamming and the user doesn't 136 // prevent logs from going over the maximum size (in case its spamming and the user doesn't
137 // know) 137 // know)
138 constexpr size_t MAX_BYTES_WRITTEN = 50 * 1024L * 1024L; 138 constexpr std::size_t MAX_BYTES_WRITTEN = 50 * 1024L * 1024L;
139 if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { 139 if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) {
140 return; 140 return;
141 } 141 }
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index b3f4b9cef..11edbf1b6 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -100,7 +100,7 @@ public:
100 100
101private: 101private:
102 FileUtil::IOFile file; 102 FileUtil::IOFile file;
103 size_t bytes_written; 103 std::size_t bytes_written;
104}; 104};
105 105
106void AddBackend(std::unique_ptr<Backend> backend); 106void AddBackend(std::unique_ptr<Backend> backend);
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
index 2dd331152..2eccbcd8d 100644
--- a/src/common/logging/filter.cpp
+++ b/src/common/logging/filter.cpp
@@ -71,7 +71,7 @@ void Filter::ResetAll(Level level) {
71} 71}
72 72
73void Filter::SetClassLevel(Class log_class, Level level) { 73void Filter::SetClassLevel(Class log_class, Level level) {
74 class_levels[static_cast<size_t>(log_class)] = level; 74 class_levels[static_cast<std::size_t>(log_class)] = level;
75} 75}
76 76
77void Filter::ParseFilterString(std::string_view filter_view) { 77void Filter::ParseFilterString(std::string_view filter_view) {
@@ -93,7 +93,8 @@ void Filter::ParseFilterString(std::string_view filter_view) {
93} 93}
94 94
95bool Filter::CheckMessage(Class log_class, Level level) const { 95bool Filter::CheckMessage(Class log_class, Level level) const {
96 return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); 96 return static_cast<u8>(level) >=
97 static_cast<u8>(class_levels[static_cast<std::size_t>(log_class)]);
97} 98}
98 99
99bool Filter::IsDebug() const { 100bool Filter::IsDebug() const {
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h
index f7e3b87c9..773df6f2c 100644
--- a/src/common/logging/filter.h
+++ b/src/common/logging/filter.h
@@ -49,6 +49,6 @@ public:
49 bool IsDebug() const; 49 bool IsDebug() const;
50 50
51private: 51private:
52 std::array<Level, static_cast<size_t>(Class::Count)> class_levels; 52 std::array<Level, static_cast<std::size_t>(Class::Count)> class_levels;
53}; 53};
54} // namespace Log 54} // namespace Log
diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp
index 09462ccee..9736fb12a 100644
--- a/src/common/memory_util.cpp
+++ b/src/common/memory_util.cpp
@@ -25,7 +25,7 @@
25// This is purposely not a full wrapper for virtualalloc/mmap, but it 25// This is purposely not a full wrapper for virtualalloc/mmap, but it
26// provides exactly the primitive operations that Dolphin needs. 26// provides exactly the primitive operations that Dolphin needs.
27 27
28void* AllocateExecutableMemory(size_t size, bool low) { 28void* AllocateExecutableMemory(std::size_t size, bool low) {
29#if defined(_WIN32) 29#if defined(_WIN32)
30 void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 30 void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
31#else 31#else
@@ -74,7 +74,7 @@ void* AllocateExecutableMemory(size_t size, bool low) {
74 return ptr; 74 return ptr;
75} 75}
76 76
77void* AllocateMemoryPages(size_t size) { 77void* AllocateMemoryPages(std::size_t size) {
78#ifdef _WIN32 78#ifdef _WIN32
79 void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); 79 void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
80#else 80#else
@@ -90,7 +90,7 @@ void* AllocateMemoryPages(size_t size) {
90 return ptr; 90 return ptr;
91} 91}
92 92
93void* AllocateAlignedMemory(size_t size, size_t alignment) { 93void* AllocateAlignedMemory(std::size_t size, std::size_t alignment) {
94#ifdef _WIN32 94#ifdef _WIN32
95 void* ptr = _aligned_malloc(size, alignment); 95 void* ptr = _aligned_malloc(size, alignment);
96#else 96#else
@@ -109,7 +109,7 @@ void* AllocateAlignedMemory(size_t size, size_t alignment) {
109 return ptr; 109 return ptr;
110} 110}
111 111
112void FreeMemoryPages(void* ptr, size_t size) { 112void FreeMemoryPages(void* ptr, std::size_t size) {
113 if (ptr) { 113 if (ptr) {
114#ifdef _WIN32 114#ifdef _WIN32
115 if (!VirtualFree(ptr, 0, MEM_RELEASE)) 115 if (!VirtualFree(ptr, 0, MEM_RELEASE))
@@ -130,7 +130,7 @@ void FreeAlignedMemory(void* ptr) {
130 } 130 }
131} 131}
132 132
133void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) { 133void WriteProtectMemory(void* ptr, std::size_t size, bool allowExecute) {
134#ifdef _WIN32 134#ifdef _WIN32
135 DWORD oldValue; 135 DWORD oldValue;
136 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) 136 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
@@ -140,7 +140,7 @@ void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) {
140#endif 140#endif
141} 141}
142 142
143void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) { 143void UnWriteProtectMemory(void* ptr, std::size_t size, bool allowExecute) {
144#ifdef _WIN32 144#ifdef _WIN32
145 DWORD oldValue; 145 DWORD oldValue;
146 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, 146 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE,
diff --git a/src/common/memory_util.h b/src/common/memory_util.h
index 76ca5a30c..aad071979 100644
--- a/src/common/memory_util.h
+++ b/src/common/memory_util.h
@@ -7,13 +7,13 @@
7#include <cstddef> 7#include <cstddef>
8#include <string> 8#include <string>
9 9
10void* AllocateExecutableMemory(size_t size, bool low = true); 10void* AllocateExecutableMemory(std::size_t size, bool low = true);
11void* AllocateMemoryPages(size_t size); 11void* AllocateMemoryPages(std::size_t size);
12void FreeMemoryPages(void* ptr, size_t size); 12void FreeMemoryPages(void* ptr, std::size_t size);
13void* AllocateAlignedMemory(size_t size, size_t alignment); 13void* AllocateAlignedMemory(std::size_t size, std::size_t alignment);
14void FreeAlignedMemory(void* ptr); 14void FreeAlignedMemory(void* ptr);
15void WriteProtectMemory(void* ptr, size_t size, bool executable = false); 15void WriteProtectMemory(void* ptr, std::size_t size, bool executable = false);
16void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute = false); 16void UnWriteProtectMemory(void* ptr, std::size_t size, bool allowExecute = false);
17std::string MemUsage(); 17std::string MemUsage();
18 18
19inline int GetPageSize() { 19inline int GetPageSize() {
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
index 3fa8a3bc4..68cb86cd1 100644
--- a/src/common/misc.cpp
+++ b/src/common/misc.cpp
@@ -16,7 +16,7 @@
16// Call directly after the command or use the error num. 16// Call directly after the command or use the error num.
17// This function might change the error code. 17// This function might change the error code.
18std::string GetLastErrorMsg() { 18std::string GetLastErrorMsg() {
19 static const size_t buff_size = 255; 19 static const std::size_t buff_size = 255;
20 char err_str[buff_size]; 20 char err_str[buff_size];
21 21
22#ifdef _WIN32 22#ifdef _WIN32
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h
index 30d934a38..45926c9ec 100644
--- a/src/common/ring_buffer.h
+++ b/src/common/ring_buffer.h
@@ -19,31 +19,31 @@ namespace Common {
19/// @tparam T Element type 19/// @tparam T Element type
20/// @tparam capacity Number of slots in ring buffer 20/// @tparam capacity Number of slots in ring buffer
21/// @tparam granularity Slot size in terms of number of elements 21/// @tparam granularity Slot size in terms of number of elements
22template <typename T, size_t capacity, size_t granularity = 1> 22template <typename T, std::size_t capacity, std::size_t granularity = 1>
23class RingBuffer { 23class RingBuffer {
24 /// A "slot" is made of `granularity` elements of `T`. 24 /// A "slot" is made of `granularity` elements of `T`.
25 static constexpr size_t slot_size = granularity * sizeof(T); 25 static constexpr std::size_t slot_size = granularity * sizeof(T);
26 // T must be safely memcpy-able and have a trivial default constructor. 26 // T must be safely memcpy-able and have a trivial default constructor.
27 static_assert(std::is_trivial_v<T>); 27 static_assert(std::is_trivial_v<T>);
28 // Ensure capacity is sensible. 28 // Ensure capacity is sensible.
29 static_assert(capacity < std::numeric_limits<size_t>::max() / 2 / granularity); 29 static_assert(capacity < std::numeric_limits<std::size_t>::max() / 2 / granularity);
30 static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two"); 30 static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two");
31 // Ensure lock-free. 31 // Ensure lock-free.
32 static_assert(std::atomic<size_t>::is_always_lock_free); 32 static_assert(std::atomic<std::size_t>::is_always_lock_free);
33 33
34public: 34public:
35 /// Pushes slots into the ring buffer 35 /// Pushes slots into the ring buffer
36 /// @param new_slots Pointer to the slots to push 36 /// @param new_slots Pointer to the slots to push
37 /// @param slot_count Number of slots to push 37 /// @param slot_count Number of slots to push
38 /// @returns The number of slots actually pushed 38 /// @returns The number of slots actually pushed
39 size_t Push(const void* new_slots, size_t slot_count) { 39 std::size_t Push(const void* new_slots, std::size_t slot_count) {
40 const size_t write_index = m_write_index.load(); 40 const std::size_t write_index = m_write_index.load();
41 const size_t slots_free = capacity + m_read_index.load() - write_index; 41 const std::size_t slots_free = capacity + m_read_index.load() - write_index;
42 const size_t push_count = std::min(slot_count, slots_free); 42 const std::size_t push_count = std::min(slot_count, slots_free);
43 43
44 const size_t pos = write_index % capacity; 44 const std::size_t pos = write_index % capacity;
45 const size_t first_copy = std::min(capacity - pos, push_count); 45 const std::size_t first_copy = std::min(capacity - pos, push_count);
46 const size_t second_copy = push_count - first_copy; 46 const std::size_t second_copy = push_count - first_copy;
47 47
48 const char* in = static_cast<const char*>(new_slots); 48 const char* in = static_cast<const char*>(new_slots);
49 std::memcpy(m_data.data() + pos * granularity, in, first_copy * slot_size); 49 std::memcpy(m_data.data() + pos * granularity, in, first_copy * slot_size);
@@ -55,7 +55,7 @@ public:
55 return push_count; 55 return push_count;
56 } 56 }
57 57
58 size_t Push(const std::vector<T>& input) { 58 std::size_t Push(const std::vector<T>& input) {
59 return Push(input.data(), input.size()); 59 return Push(input.data(), input.size());
60 } 60 }
61 61
@@ -63,14 +63,14 @@ public:
63 /// @param output Where to store the popped slots 63 /// @param output Where to store the popped slots
64 /// @param max_slots Maximum number of slots to pop 64 /// @param max_slots Maximum number of slots to pop
65 /// @returns The number of slots actually popped 65 /// @returns The number of slots actually popped
66 size_t Pop(void* output, size_t max_slots = ~size_t(0)) { 66 std::size_t Pop(void* output, std::size_t max_slots = ~std::size_t(0)) {
67 const size_t read_index = m_read_index.load(); 67 const std::size_t read_index = m_read_index.load();
68 const size_t slots_filled = m_write_index.load() - read_index; 68 const std::size_t slots_filled = m_write_index.load() - read_index;
69 const size_t pop_count = std::min(slots_filled, max_slots); 69 const std::size_t pop_count = std::min(slots_filled, max_slots);
70 70
71 const size_t pos = read_index % capacity; 71 const std::size_t pos = read_index % capacity;
72 const size_t first_copy = std::min(capacity - pos, pop_count); 72 const std::size_t first_copy = std::min(capacity - pos, pop_count);
73 const size_t second_copy = pop_count - first_copy; 73 const std::size_t second_copy = pop_count - first_copy;
74 74
75 char* out = static_cast<char*>(output); 75 char* out = static_cast<char*>(output);
76 std::memcpy(out, m_data.data() + pos * granularity, first_copy * slot_size); 76 std::memcpy(out, m_data.data() + pos * granularity, first_copy * slot_size);
@@ -82,28 +82,28 @@ public:
82 return pop_count; 82 return pop_count;
83 } 83 }
84 84
85 std::vector<T> Pop(size_t max_slots = ~size_t(0)) { 85 std::vector<T> Pop(std::size_t max_slots = ~std::size_t(0)) {
86 std::vector<T> out(std::min(max_slots, capacity) * granularity); 86 std::vector<T> out(std::min(max_slots, capacity) * granularity);
87 const size_t count = Pop(out.data(), out.size() / granularity); 87 const std::size_t count = Pop(out.data(), out.size() / granularity);
88 out.resize(count * granularity); 88 out.resize(count * granularity);
89 return out; 89 return out;
90 } 90 }
91 91
92 /// @returns Number of slots used 92 /// @returns Number of slots used
93 size_t Size() const { 93 std::size_t Size() const {
94 return m_write_index.load() - m_read_index.load(); 94 return m_write_index.load() - m_read_index.load();
95 } 95 }
96 96
97 /// @returns Maximum size of ring buffer 97 /// @returns Maximum size of ring buffer
98 constexpr size_t Capacity() const { 98 constexpr std::size_t Capacity() const {
99 return capacity; 99 return capacity;
100 } 100 }
101 101
102private: 102private:
103 // It is important to align the below variables for performance reasons: 103 // It is important to align the below variables for performance reasons:
104 // Having them on the same cache-line would result in false-sharing between them. 104 // Having them on the same cache-line would result in false-sharing between them.
105 alignas(128) std::atomic<size_t> m_read_index{0}; 105 alignas(128) std::atomic<std::size_t> m_read_index{0};
106 alignas(128) std::atomic<size_t> m_write_index{0}; 106 alignas(128) std::atomic<std::size_t> m_write_index{0};
107 107
108 std::array<T, granularity * capacity> m_data; 108 std::array<T, granularity * capacity> m_data;
109}; 109};
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 0ca663032..c9a5425a7 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -37,7 +37,7 @@ std::string ToUpper(std::string str) {
37} 37}
38 38
39// For Debugging. Read out an u8 array. 39// For Debugging. Read out an u8 array.
40std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { 40std::string ArrayToString(const u8* data, std::size_t size, int line_len, bool spaces) {
41 std::ostringstream oss; 41 std::ostringstream oss;
42 oss << std::setfill('0') << std::hex; 42 oss << std::setfill('0') << std::hex;
43 43
@@ -60,7 +60,7 @@ std::string StringFromBuffer(const std::vector<u8>& data) {
60 60
61// Turns " hej " into "hej". Also handles tabs. 61// Turns " hej " into "hej". Also handles tabs.
62std::string StripSpaces(const std::string& str) { 62std::string StripSpaces(const std::string& str) {
63 const size_t s = str.find_first_not_of(" \t\r\n"); 63 const std::size_t s = str.find_first_not_of(" \t\r\n");
64 64
65 if (str.npos != s) 65 if (str.npos != s)
66 return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); 66 return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1);
@@ -121,10 +121,10 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
121 if (full_path.empty()) 121 if (full_path.empty())
122 return false; 122 return false;
123 123
124 size_t dir_end = full_path.find_last_of("/" 124 std::size_t dir_end = full_path.find_last_of("/"
125// windows needs the : included for something like just "C:" to be considered a directory 125// windows needs the : included for something like just "C:" to be considered a directory
126#ifdef _WIN32 126#ifdef _WIN32
127 "\\:" 127 "\\:"
128#endif 128#endif
129 ); 129 );
130 if (std::string::npos == dir_end) 130 if (std::string::npos == dir_end)
@@ -132,7 +132,7 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
132 else 132 else
133 dir_end += 1; 133 dir_end += 1;
134 134
135 size_t fname_end = full_path.rfind('.'); 135 std::size_t fname_end = full_path.rfind('.');
136 if (fname_end < dir_end || std::string::npos == fname_end) 136 if (fname_end < dir_end || std::string::npos == fname_end)
137 fname_end = full_path.size(); 137 fname_end = full_path.size();
138 138
@@ -172,7 +172,7 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
172} 172}
173 173
174std::string TabsToSpaces(int tab_size, std::string in) { 174std::string TabsToSpaces(int tab_size, std::string in) {
175 size_t i = 0; 175 std::size_t i = 0;
176 176
177 while ((i = in.find('\t')) != std::string::npos) { 177 while ((i = in.find('\t')) != std::string::npos) {
178 in.replace(i, 1, tab_size, ' '); 178 in.replace(i, 1, tab_size, ' ');
@@ -182,7 +182,7 @@ std::string TabsToSpaces(int tab_size, std::string in) {
182} 182}
183 183
184std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { 184std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) {
185 size_t pos = 0; 185 std::size_t pos = 0;
186 186
187 if (src == dest) 187 if (src == dest)
188 return result; 188 return result;
@@ -280,22 +280,22 @@ static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>&
280 return {}; 280 return {};
281 } 281 }
282 282
283 const size_t in_bytes = sizeof(T) * input.size(); 283 const std::size_t in_bytes = sizeof(T) * input.size();
284 // Multiply by 4, which is the max number of bytes to encode a codepoint 284 // Multiply by 4, which is the max number of bytes to encode a codepoint
285 const size_t out_buffer_size = 4 * in_bytes; 285 const std::size_t out_buffer_size = 4 * in_bytes;
286 286
287 std::string out_buffer(out_buffer_size, '\0'); 287 std::string out_buffer(out_buffer_size, '\0');
288 288
289 auto src_buffer = &input[0]; 289 auto src_buffer = &input[0];
290 size_t src_bytes = in_bytes; 290 std::size_t src_bytes = in_bytes;
291 auto dst_buffer = &out_buffer[0]; 291 auto dst_buffer = &out_buffer[0];
292 size_t dst_bytes = out_buffer.size(); 292 std::size_t dst_bytes = out_buffer.size();
293 293
294 while (0 != src_bytes) { 294 while (0 != src_bytes) {
295 size_t const iconv_result = 295 std::size_t const iconv_result =
296 iconv(conv_desc, (char**)(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes); 296 iconv(conv_desc, (char**)(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes);
297 297
298 if (static_cast<size_t>(-1) == iconv_result) { 298 if (static_cast<std::size_t>(-1) == iconv_result) {
299 if (EILSEQ == errno || EINVAL == errno) { 299 if (EILSEQ == errno || EINVAL == errno) {
300 // Try to skip the bad character 300 // Try to skip the bad character
301 if (0 != src_bytes) { 301 if (0 != src_bytes) {
@@ -326,22 +326,22 @@ std::u16string UTF8ToUTF16(const std::string& input) {
326 return {}; 326 return {};
327 } 327 }
328 328
329 const size_t in_bytes = sizeof(char) * input.size(); 329 const std::size_t in_bytes = sizeof(char) * input.size();
330 // Multiply by 4, which is the max number of bytes to encode a codepoint 330 // Multiply by 4, which is the max number of bytes to encode a codepoint
331 const size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; 331 const std::size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes;
332 332
333 std::u16string out_buffer(out_buffer_size, char16_t{}); 333 std::u16string out_buffer(out_buffer_size, char16_t{});
334 334
335 char* src_buffer = const_cast<char*>(&input[0]); 335 char* src_buffer = const_cast<char*>(&input[0]);
336 size_t src_bytes = in_bytes; 336 std::size_t src_bytes = in_bytes;
337 char* dst_buffer = (char*)(&out_buffer[0]); 337 char* dst_buffer = (char*)(&out_buffer[0]);
338 size_t dst_bytes = out_buffer.size(); 338 std::size_t dst_bytes = out_buffer.size();
339 339
340 while (0 != src_bytes) { 340 while (0 != src_bytes) {
341 size_t const iconv_result = 341 std::size_t const iconv_result =
342 iconv(conv_desc, &src_buffer, &src_bytes, &dst_buffer, &dst_bytes); 342 iconv(conv_desc, &src_buffer, &src_bytes, &dst_buffer, &dst_bytes);
343 343
344 if (static_cast<size_t>(-1) == iconv_result) { 344 if (static_cast<std::size_t>(-1) == iconv_result) {
345 if (EILSEQ == errno || EINVAL == errno) { 345 if (EILSEQ == errno || EINVAL == errno) {
346 // Try to skip the bad character 346 // Try to skip the bad character
347 if (0 != src_bytes) { 347 if (0 != src_bytes) {
@@ -381,8 +381,8 @@ std::string SHIFTJISToUTF8(const std::string& input) {
381 381
382#endif 382#endif
383 383
384std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_len) { 384std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) {
385 size_t len = 0; 385 std::size_t len = 0;
386 while (len < max_len && buffer[len] != '\0') 386 while (len < max_len && buffer[len] != '\0')
387 ++len; 387 ++len;
388 388
diff --git a/src/common/string_util.h b/src/common/string_util.h
index 4a2143b59..dcca6bc38 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -19,7 +19,7 @@ std::string ToLower(std::string str);
19/// Make a string uppercase 19/// Make a string uppercase
20std::string ToUpper(std::string str); 20std::string ToUpper(std::string str);
21 21
22std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true); 22std::string ArrayToString(const u8* data, std::size_t size, int line_len = 20, bool spaces = true);
23 23
24std::string StringFromBuffer(const std::vector<u8>& data); 24std::string StringFromBuffer(const std::vector<u8>& data);
25 25
@@ -118,7 +118,7 @@ bool ComparePartialString(InIt begin, InIt end, const char* other) {
118 * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't 118 * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
119 * NUL-terminated then the string ends at max_len characters. 119 * NUL-terminated then the string ends at max_len characters.
120 */ 120 */
121std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, size_t max_len); 121std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len);
122 122
123/** 123/**
124 * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's 124 * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's
diff --git a/src/common/thread.h b/src/common/thread.h
index 9465e1de7..12a1c095c 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -60,12 +60,12 @@ private:
60 60
61class Barrier { 61class Barrier {
62public: 62public:
63 explicit Barrier(size_t count_) : count(count_), waiting(0), generation(0) {} 63 explicit Barrier(std::size_t count_) : count(count_), waiting(0), generation(0) {}
64 64
65 /// Blocks until all "count" threads have called Sync() 65 /// Blocks until all "count" threads have called Sync()
66 void Sync() { 66 void Sync() {
67 std::unique_lock<std::mutex> lk(mutex); 67 std::unique_lock<std::mutex> lk(mutex);
68 const size_t current_generation = generation; 68 const std::size_t current_generation = generation;
69 69
70 if (++waiting == count) { 70 if (++waiting == count) {
71 generation++; 71 generation++;
@@ -80,9 +80,9 @@ public:
80private: 80private:
81 std::condition_variable condvar; 81 std::condition_variable condvar;
82 std::mutex mutex; 82 std::mutex mutex;
83 const size_t count; 83 const std::size_t count;
84 size_t waiting; 84 std::size_t waiting;
85 size_t generation; // Incremented once each time the barrier is used 85 std::size_t generation; // Incremented once each time the barrier is used
86}; 86};
87 87
88void SleepCurrentThread(int ms); 88void SleepCurrentThread(int ms);
diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h
index 927da9187..636a5c0f9 100644
--- a/src/common/x64/xbyak_abi.h
+++ b/src/common/x64/xbyak_abi.h
@@ -97,7 +97,7 @@ const BitSet32 ABI_ALL_CALLEE_SAVED = BuildRegSet({
97 Xbyak::util::xmm15, 97 Xbyak::util::xmm15,
98}); 98});
99 99
100constexpr size_t ABI_SHADOW_SPACE = 0x20; 100constexpr std::size_t ABI_SHADOW_SPACE = 0x20;
101 101
102#else 102#else
103 103
@@ -147,22 +147,23 @@ const BitSet32 ABI_ALL_CALLEE_SAVED = BuildRegSet({
147 Xbyak::util::r15, 147 Xbyak::util::r15,
148}); 148});
149 149
150constexpr size_t ABI_SHADOW_SPACE = 0; 150constexpr std::size_t ABI_SHADOW_SPACE = 0;
151 151
152#endif 152#endif
153 153
154inline void ABI_CalculateFrameSize(BitSet32 regs, size_t rsp_alignment, size_t needed_frame_size, 154inline void ABI_CalculateFrameSize(BitSet32 regs, std::size_t rsp_alignment,
155 s32* out_subtraction, s32* out_xmm_offset) { 155 std::size_t needed_frame_size, s32* out_subtraction,
156 s32* out_xmm_offset) {
156 int count = (regs & ABI_ALL_GPRS).Count(); 157 int count = (regs & ABI_ALL_GPRS).Count();
157 rsp_alignment -= count * 8; 158 rsp_alignment -= count * 8;
158 size_t subtraction = 0; 159 std::size_t subtraction = 0;
159 int xmm_count = (regs & ABI_ALL_XMMS).Count(); 160 int xmm_count = (regs & ABI_ALL_XMMS).Count();
160 if (xmm_count) { 161 if (xmm_count) {
161 // If we have any XMMs to save, we must align the stack here. 162 // If we have any XMMs to save, we must align the stack here.
162 subtraction = rsp_alignment & 0xF; 163 subtraction = rsp_alignment & 0xF;
163 } 164 }
164 subtraction += 0x10 * xmm_count; 165 subtraction += 0x10 * xmm_count;
165 size_t xmm_base_subtraction = subtraction; 166 std::size_t xmm_base_subtraction = subtraction;
166 subtraction += needed_frame_size; 167 subtraction += needed_frame_size;
167 subtraction += ABI_SHADOW_SPACE; 168 subtraction += ABI_SHADOW_SPACE;
168 // Final alignment. 169 // Final alignment.
@@ -173,8 +174,9 @@ inline void ABI_CalculateFrameSize(BitSet32 regs, size_t rsp_alignment, size_t n
173 *out_xmm_offset = (s32)(subtraction - xmm_base_subtraction); 174 *out_xmm_offset = (s32)(subtraction - xmm_base_subtraction);
174} 175}
175 176
176inline size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet32 regs, 177inline std::size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet32 regs,
177 size_t rsp_alignment, size_t needed_frame_size = 0) { 178 std::size_t rsp_alignment,
179 std::size_t needed_frame_size = 0) {
178 s32 subtraction, xmm_offset; 180 s32 subtraction, xmm_offset;
179 ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset); 181 ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset);
180 182
@@ -195,7 +197,8 @@ inline size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet
195} 197}
196 198
197inline void ABI_PopRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet32 regs, 199inline void ABI_PopRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet32 regs,
198 size_t rsp_alignment, size_t needed_frame_size = 0) { 200 std::size_t rsp_alignment,
201 std::size_t needed_frame_size = 0) {
199 s32 subtraction, xmm_offset; 202 s32 subtraction, xmm_offset;
200 ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset); 203 ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset);
201 204
diff --git a/src/common/x64/xbyak_util.h b/src/common/x64/xbyak_util.h
index 02323a017..5cc8a8c76 100644
--- a/src/common/x64/xbyak_util.h
+++ b/src/common/x64/xbyak_util.h
@@ -34,7 +34,7 @@ inline bool IsWithin2G(const Xbyak::CodeGenerator& code, uintptr_t target) {
34template <typename T> 34template <typename T>
35inline void CallFarFunction(Xbyak::CodeGenerator& code, const T f) { 35inline void CallFarFunction(Xbyak::CodeGenerator& code, const T f) {
36 static_assert(std::is_pointer_v<T>, "Argument must be a (function) pointer."); 36 static_assert(std::is_pointer_v<T>, "Argument must be a (function) pointer.");
37 size_t addr = reinterpret_cast<size_t>(f); 37 std::size_t addr = reinterpret_cast<std::size_t>(f);
38 if (IsWithin2G(code, addr)) { 38 if (IsWithin2G(code, addr)) {
39 code.call(f); 39 code.call(f);
40 } else { 40 } else {