summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/CMakeLists.txt8
-rw-r--r--src/common/alignment.h66
-rw-r--r--src/common/binary_find.h21
-rw-r--r--src/common/bit_util.h44
-rw-r--r--src/common/common_funcs.h1
-rw-r--r--src/common/hex_util.cpp7
-rw-r--r--src/common/hex_util.h16
-rw-r--r--src/common/logging/backend.cpp1
-rw-r--r--src/common/logging/log.h1
9 files changed, 154 insertions, 11 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 198b3fe07..dfed8b51d 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -10,6 +10,9 @@ if (DEFINED ENV{CI})
elseif(DEFINED ENV{APPVEYOR})
set(BUILD_REPOSITORY $ENV{APPVEYOR_REPO_NAME})
set(BUILD_TAG $ENV{APPVEYOR_REPO_TAG_NAME})
+ elseif(DEFINED ENV{AZURE})
+ set(BUILD_REPOSITORY $ENV{AZURE_REPO_NAME})
+ set(BUILD_TAG $ENV{AZURE_REPO_TAG})
endif()
endif()
add_custom_command(OUTPUT scm_rev.cpp
@@ -44,6 +47,7 @@ add_custom_command(OUTPUT scm_rev.cpp
"${VIDEO_CORE}/shader/decode/half_set.cpp"
"${VIDEO_CORE}/shader/decode/half_set_predicate.cpp"
"${VIDEO_CORE}/shader/decode/hfma2.cpp"
+ "${VIDEO_CORE}/shader/decode/image.cpp"
"${VIDEO_CORE}/shader/decode/integer_set.cpp"
"${VIDEO_CORE}/shader/decode/integer_set_predicate.cpp"
"${VIDEO_CORE}/shader/decode/memory.cpp"
@@ -54,7 +58,10 @@ add_custom_command(OUTPUT scm_rev.cpp
"${VIDEO_CORE}/shader/decode/register_set_predicate.cpp"
"${VIDEO_CORE}/shader/decode/shift.cpp"
"${VIDEO_CORE}/shader/decode/video.cpp"
+ "${VIDEO_CORE}/shader/decode/warp.cpp"
"${VIDEO_CORE}/shader/decode/xmad.cpp"
+ "${VIDEO_CORE}/shader/control_flow.cpp"
+ "${VIDEO_CORE}/shader/control_flow.h"
"${VIDEO_CORE}/shader/decode.cpp"
"${VIDEO_CORE}/shader/node.h"
"${VIDEO_CORE}/shader/node_helper.cpp"
@@ -74,6 +81,7 @@ add_library(common STATIC
assert.h
detached_tasks.cpp
detached_tasks.h
+ binary_find.h
bit_field.h
bit_util.h
cityhash.cpp
diff --git a/src/common/alignment.h b/src/common/alignment.h
index d94a2291f..88d5d3a65 100644
--- a/src/common/alignment.h
+++ b/src/common/alignment.h
@@ -3,6 +3,7 @@
#pragma once
#include <cstddef>
+#include <memory>
#include <type_traits>
namespace Common {
@@ -20,6 +21,12 @@ constexpr T AlignDown(T value, std::size_t size) {
}
template <typename T>
+constexpr T AlignBits(T value, std::size_t align) {
+ static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
+ return static_cast<T>((value + ((1ULL << align) - 1)) >> align << align);
+}
+
+template <typename T>
constexpr bool Is4KBAligned(T value) {
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
return (value & 0xFFF) == 0;
@@ -31,4 +38,63 @@ constexpr bool IsWordAligned(T value) {
return (value & 0b11) == 0;
}
+template <typename T, std::size_t Align = 16>
+class AlignmentAllocator {
+public:
+ using value_type = T;
+ using size_type = std::size_t;
+ using difference_type = std::ptrdiff_t;
+
+ using pointer = T*;
+ using const_pointer = const T*;
+
+ using reference = T&;
+ using const_reference = const T&;
+
+public:
+ pointer address(reference r) noexcept {
+ return std::addressof(r);
+ }
+
+ const_pointer address(const_reference r) const noexcept {
+ return std::addressof(r);
+ }
+
+ pointer allocate(size_type n) {
+ return static_cast<pointer>(::operator new (n, std::align_val_t{Align}));
+ }
+
+ void deallocate(pointer p, size_type) {
+ ::operator delete (p, std::align_val_t{Align});
+ }
+
+ void construct(pointer p, const value_type& wert) {
+ new (p) value_type(wert);
+ }
+
+ void destroy(pointer p) {
+ p->~value_type();
+ }
+
+ size_type max_size() const noexcept {
+ return size_type(-1) / sizeof(value_type);
+ }
+
+ template <typename T2>
+ struct rebind {
+ using other = AlignmentAllocator<T2, Align>;
+ };
+
+ bool operator!=(const AlignmentAllocator<T, Align>& other) const noexcept {
+ return !(*this == other);
+ }
+
+ // Returns true if and only if storage allocated from *this
+ // can be deallocated from other, and vice versa.
+ // Always returns true for stateless allocators.
+ bool operator==(const AlignmentAllocator<T, Align>& other) const noexcept {
+ return true;
+ }
+};
+
} // namespace Common
diff --git a/src/common/binary_find.h b/src/common/binary_find.h
new file mode 100644
index 000000000..5cc523bf9
--- /dev/null
+++ b/src/common/binary_find.h
@@ -0,0 +1,21 @@
+// Copyright 2019 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <algorithm>
+
+namespace Common {
+
+template <class ForwardIt, class T, class Compare = std::less<>>
+ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) {
+ // Note: BOTH type T and the type after ForwardIt is dereferenced
+ // must be implicitly convertible to BOTH Type1 and Type2, used in Compare.
+ // This is stricter than lower_bound requirement (see above)
+
+ first = std::lower_bound(first, last, value, comp);
+ return first != last && !comp(value, *first) ? first : last;
+}
+
+} // namespace Common
diff --git a/src/common/bit_util.h b/src/common/bit_util.h
index d032df413..6f7d5a947 100644
--- a/src/common/bit_util.h
+++ b/src/common/bit_util.h
@@ -97,4 +97,48 @@ inline u32 CountTrailingZeroes64(u64 value) {
}
#endif
+#ifdef _MSC_VER
+
+inline u32 MostSignificantBit32(const u32 value) {
+ unsigned long result;
+ _BitScanReverse(&result, value);
+ return static_cast<u32>(result);
+}
+
+inline u32 MostSignificantBit64(const u64 value) {
+ unsigned long result;
+ _BitScanReverse64(&result, value);
+ return static_cast<u32>(result);
+}
+
+#else
+
+inline u32 MostSignificantBit32(const u32 value) {
+ return 31U - static_cast<u32>(__builtin_clz(value));
+}
+
+inline u32 MostSignificantBit64(const u64 value) {
+ return 63U - static_cast<u32>(__builtin_clzll(value));
+}
+
+#endif
+
+inline u32 Log2Floor32(const u32 value) {
+ return MostSignificantBit32(value);
+}
+
+inline u32 Log2Ceil32(const u32 value) {
+ const u32 log2_f = Log2Floor32(value);
+ return log2_f + ((value ^ (1U << log2_f)) != 0U);
+}
+
+inline u32 Log2Floor64(const u64 value) {
+ return MostSignificantBit64(value);
+}
+
+inline u32 Log2Ceil64(const u64 value) {
+ const u64 log2_f = static_cast<u64>(Log2Floor64(value));
+ return static_cast<u32>(log2_f + ((value ^ (1ULL << log2_f)) != 0ULL));
+}
+
} // namespace Common
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 8b0d34da6..04ecac959 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -4,6 +4,7 @@
#pragma once
+#include <algorithm>
#include <string>
#if !defined(ARCHITECTURE_x86_64)
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp
index 5b63f9e81..c2f6cf0f6 100644
--- a/src/common/hex_util.cpp
+++ b/src/common/hex_util.cpp
@@ -30,13 +30,6 @@ std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) {
return out;
}
-std::string HexVectorToString(const std::vector<u8>& vector, bool upper) {
- std::string out;
- for (u8 c : vector)
- out += fmt::format(upper ? "{:02X}" : "{:02x}", c);
- return out;
-}
-
std::array<u8, 16> operator""_array16(const char* str, std::size_t len) {
if (len != 32) {
LOG_ERROR(Common,
diff --git a/src/common/hex_util.h b/src/common/hex_util.h
index 68f003cb6..bb4736f96 100644
--- a/src/common/hex_util.h
+++ b/src/common/hex_util.h
@@ -7,6 +7,7 @@
#include <array>
#include <cstddef>
#include <string>
+#include <type_traits>
#include <vector>
#include <fmt/format.h>
#include "common/common_types.h"
@@ -30,13 +31,20 @@ std::array<u8, Size> HexStringToArray(std::string_view str) {
return out;
}
-std::string HexVectorToString(const std::vector<u8>& vector, bool upper = true);
+template <typename ContiguousContainer>
+std::string HexToString(const ContiguousContainer& data, bool upper = true) {
+ static_assert(std::is_same_v<typename ContiguousContainer::value_type, u8>,
+ "Underlying type within the contiguous container must be u8.");
+
+ constexpr std::size_t pad_width = 2;
-template <std::size_t Size>
-std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
std::string out;
- for (u8 c : array)
+ out.reserve(std::size(data) * pad_width);
+
+ for (const u8 c : data) {
out += fmt::format(upper ? "{:02X}" : "{:02x}", c);
+ }
+
return out;
}
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index a03179520..1111cfbad 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -255,6 +255,7 @@ void DebuggerBackend::Write(const Entry& entry) {
CLS(Input) \
CLS(Network) \
CLS(Loader) \
+ CLS(CheatEngine) \
CLS(Crypto) \
CLS(WebService)
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 8ed6d5050..259708116 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -117,6 +117,7 @@ enum class Class : ClassType {
Audio_DSP, ///< The HLE implementation of the DSP
Audio_Sink, ///< Emulator audio output backend
Loader, ///< ROM loader
+ CheatEngine, ///< Memory manipulation and engine VM functions
Crypto, ///< Cryptographic engine/functions
Input, ///< Input emulation
Network, ///< Network emulation