summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/alignment.h37
-rw-r--r--src/common/lz4_compression.cpp6
-rw-r--r--src/common/lz4_compression.h2
-rw-r--r--src/common/settings.cpp10
-rw-r--r--src/common/settings.h1
5 files changed, 49 insertions, 7 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h
index fa715d497..fc5c26898 100644
--- a/src/common/alignment.h
+++ b/src/common/alignment.h
@@ -3,6 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <bit>
6#include <cstddef> 7#include <cstddef>
7#include <new> 8#include <new>
8#include <type_traits> 9#include <type_traits>
@@ -10,8 +11,10 @@
10namespace Common { 11namespace Common {
11 12
12template <typename T> 13template <typename T>
13 requires std::is_unsigned_v<T> 14 requires std::is_integral_v<T>
14[[nodiscard]] constexpr T AlignUp(T value, size_t size) { 15[[nodiscard]] constexpr T AlignUp(T value_, size_t size) {
16 using U = typename std::make_unsigned_t<T>;
17 auto value{static_cast<U>(value_)};
15 auto mod{static_cast<T>(value % size)}; 18 auto mod{static_cast<T>(value % size)};
16 value -= mod; 19 value -= mod;
17 return static_cast<T>(mod == T{0} ? value : value + size); 20 return static_cast<T>(mod == T{0} ? value : value + size);
@@ -24,8 +27,10 @@ template <typename T>
24} 27}
25 28
26template <typename T> 29template <typename T>
27 requires std::is_unsigned_v<T> 30 requires std::is_integral_v<T>
28[[nodiscard]] constexpr T AlignDown(T value, size_t size) { 31[[nodiscard]] constexpr T AlignDown(T value_, size_t size) {
32 using U = typename std::make_unsigned_t<T>;
33 const auto value{static_cast<U>(value_)};
29 return static_cast<T>(value - value % size); 34 return static_cast<T>(value - value % size);
30} 35}
31 36
@@ -55,6 +60,30 @@ template <typename T, typename U>
55 return (x + (y - 1)) / y; 60 return (x + (y - 1)) / y;
56} 61}
57 62
63template <typename T>
64 requires std::is_integral_v<T>
65[[nodiscard]] constexpr T LeastSignificantOneBit(T x) {
66 return x & ~(x - 1);
67}
68
69template <typename T>
70 requires std::is_integral_v<T>
71[[nodiscard]] constexpr T ResetLeastSignificantOneBit(T x) {
72 return x & (x - 1);
73}
74
75template <typename T>
76 requires std::is_integral_v<T>
77[[nodiscard]] constexpr bool IsPowerOfTwo(T x) {
78 return x > 0 && ResetLeastSignificantOneBit(x) == 0;
79}
80
81template <typename T>
82 requires std::is_integral_v<T>
83[[nodiscard]] constexpr T FloorPowerOfTwo(T x) {
84 return T{1} << (sizeof(T) * 8 - std::countl_zero(x) - 1);
85}
86
58template <typename T, size_t Align = 16> 87template <typename T, size_t Align = 16>
59class AlignmentAllocator { 88class AlignmentAllocator {
60public: 89public:
diff --git a/src/common/lz4_compression.cpp b/src/common/lz4_compression.cpp
index ffb32fecf..d85ab1742 100644
--- a/src/common/lz4_compression.cpp
+++ b/src/common/lz4_compression.cpp
@@ -71,4 +71,10 @@ std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed, std::size_t un
71 return uncompressed; 71 return uncompressed;
72} 72}
73 73
74int DecompressDataLZ4(void* dst, size_t dst_size, const void* src, size_t src_size) {
75 // This is just a thin wrapper around LZ4.
76 return LZ4_decompress_safe(reinterpret_cast<const char*>(src), reinterpret_cast<char*>(dst),
77 static_cast<int>(src_size), static_cast<int>(dst_size));
78}
79
74} // namespace Common::Compression 80} // namespace Common::Compression
diff --git a/src/common/lz4_compression.h b/src/common/lz4_compression.h
index 7fd53a960..3ae17c2bb 100644
--- a/src/common/lz4_compression.h
+++ b/src/common/lz4_compression.h
@@ -56,4 +56,6 @@ namespace Common::Compression {
56[[nodiscard]] std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed, 56[[nodiscard]] std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed,
57 std::size_t uncompressed_size); 57 std::size_t uncompressed_size);
58 58
59[[nodiscard]] int DecompressDataLZ4(void* dst, size_t dst_size, const void* src, size_t src_size);
60
59} // namespace Common::Compression 61} // namespace Common::Compression
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 15fd2e222..16a58a750 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -207,9 +207,7 @@ const char* TranslateCategory(Category category) {
207 return "Miscellaneous"; 207 return "Miscellaneous";
208} 208}
209 209
210void UpdateRescalingInfo() { 210void TranslateResolutionInfo(ResolutionSetup setup, ResolutionScalingInfo& info) {
211 const auto setup = values.resolution_setup.GetValue();
212 auto& info = values.resolution_info;
213 info.downscale = false; 211 info.downscale = false;
214 switch (setup) { 212 switch (setup) {
215 case ResolutionSetup::Res1_2X: 213 case ResolutionSetup::Res1_2X:
@@ -269,6 +267,12 @@ void UpdateRescalingInfo() {
269 info.active = info.up_scale != 1 || info.down_shift != 0; 267 info.active = info.up_scale != 1 || info.down_shift != 0;
270} 268}
271 269
270void UpdateRescalingInfo() {
271 const auto setup = values.resolution_setup.GetValue();
272 auto& info = values.resolution_info;
273 TranslateResolutionInfo(setup, info);
274}
275
272void RestoreGlobalState(bool is_powered_on) { 276void RestoreGlobalState(bool is_powered_on) {
273 // If a game is running, DO NOT restore the global settings state 277 // If a game is running, DO NOT restore the global settings state
274 if (is_powered_on) { 278 if (is_powered_on) {
diff --git a/src/common/settings.h b/src/common/settings.h
index b0bc6519a..4407c1e6d 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -525,6 +525,7 @@ std::string GetTimeZoneString(TimeZone time_zone);
525 525
526void LogSettings(); 526void LogSettings();
527 527
528void TranslateResolutionInfo(ResolutionSetup setup, ResolutionScalingInfo& info);
528void UpdateRescalingInfo(); 529void UpdateRescalingInfo();
529 530
530// Restore the global state of all applicable settings in the Values struct 531// Restore the global state of all applicable settings in the Values struct