summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt5
-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
5 files changed, 137 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 198b3fe076..01abdb3bb5 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -44,6 +44,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 +55,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 +78,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 d94a2291f7..88d5d3a65f 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 0000000000..5cc523bf9c
--- /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 d032df4131..6f7d5a9479 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 8b0d34da6e..04ecac959b 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)