mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-29 00:55:13 +02:00
[common] rework BitField and BitUtil, use concepts whenever possible
Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
30a42c5a6a
commit
aa3f19cc10
31 changed files with 527 additions and 756 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
||||
|
|
@ -8,12 +8,21 @@
|
|||
|
||||
#include <array>
|
||||
#include <iterator>
|
||||
|
||||
#if !defined(ARCHITECTURE_x86_64)
|
||||
#include <utility>
|
||||
#include <cstdlib> // for exit
|
||||
#endif
|
||||
#include "common/common_types.h"
|
||||
|
||||
#ifndef __cpp_lib_to_underlying
|
||||
namespace std {
|
||||
// https://en.cppreference.com/cpp/utility/to_underlying
|
||||
template<class T>
|
||||
requires std::is_enum_v<T>
|
||||
constexpr std::underlying_type_t<T> to_underlying(T e) noexcept {
|
||||
return std::underlying_type_t<T>(e);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
|
||||
#define CONCAT2(x, y) DO_CONCAT2(x, y)
|
||||
#define DO_CONCAT2(x, y) x##y
|
||||
|
|
@ -38,56 +47,43 @@
|
|||
|
||||
#define DECLARE_ENUM_FLAG_OPERATORS(type) \
|
||||
[[nodiscard]] constexpr type operator|(type a, type b) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \
|
||||
return type(std::to_underlying(a) | std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator&(type a, type b) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \
|
||||
return type(std::to_underlying(a) & std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator^(type a, type b) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \
|
||||
return type(std::to_underlying(a) ^ std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator<<(type a, type b) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<type>(static_cast<T>(a) << static_cast<T>(b)); \
|
||||
return type(std::to_underlying(a) << std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator>>(type a, type b) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<type>(static_cast<T>(a) >> static_cast<T>(b)); \
|
||||
return type(std::to_underlying(a) >> std::to_underlying(b)); \
|
||||
} \
|
||||
constexpr type& operator|=(type& a, type b) noexcept { \
|
||||
a = a | b; \
|
||||
return a; \
|
||||
constexpr type operator|=(type& a, type b) noexcept { \
|
||||
return a = a | b; \
|
||||
} \
|
||||
constexpr type& operator&=(type& a, type b) noexcept { \
|
||||
a = a & b; \
|
||||
return a; \
|
||||
constexpr type operator&=(type& a, type b) noexcept { \
|
||||
return a = a & b; \
|
||||
} \
|
||||
constexpr type& operator^=(type& a, type b) noexcept { \
|
||||
a = a ^ b; \
|
||||
return a; \
|
||||
constexpr type operator^=(type& a, type b) noexcept { \
|
||||
return a = a ^ b; \
|
||||
} \
|
||||
constexpr type& operator<<=(type& a, type b) noexcept { \
|
||||
a = a << b; \
|
||||
return a; \
|
||||
constexpr type operator<<=(type& a, type b) noexcept { \
|
||||
return a = a << b; \
|
||||
} \
|
||||
constexpr type& operator>>=(type& a, type b) noexcept { \
|
||||
a = a >> b; \
|
||||
return a; \
|
||||
constexpr type operator>>=(type& a, type b) noexcept { \
|
||||
return a = a >> b; \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator~(type key) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<type>(~static_cast<T>(key)); \
|
||||
return type(~std::to_underlying(key)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr bool True(type key) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<T>(key) != 0; \
|
||||
return std::to_underlying(key) != 0; \
|
||||
} \
|
||||
[[nodiscard]] constexpr bool False(type key) noexcept { \
|
||||
using T = std::underlying_type_t<type>; \
|
||||
return static_cast<T>(key) == 0; \
|
||||
return std::to_underlying(key) == 0; \
|
||||
}
|
||||
|
||||
#define YUZU_NON_COPYABLE(cls) \
|
||||
|
|
@ -104,10 +100,8 @@ namespace Common {
|
|||
return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr u64 MakeMagic(char a, char b, char c, char d, char e, char f, char g,
|
||||
char h) {
|
||||
return u64(a) << 0 | u64(b) << 8 | u64(c) << 16 | u64(d) << 24 | u64(e) << 32 | u64(f) << 40 |
|
||||
u64(g) << 48 | u64(h) << 56;
|
||||
[[nodiscard]] constexpr u64 MakeMagic(char a, char b, char c, char d, char e, char f, char g, char h) {
|
||||
return u64(a) << 0 | u64(b) << 8 | u64(c) << 16 | u64(d) << 24 | u64(e) << 32 | u64(f) << 40 | u64(g) << 48 | u64(h) << 56;
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue