[common] revert "replace Common::BitSet with std::bitset"
Some checks failed
eden-license / license-header (pull_request) Failing after 25s
Some checks failed
eden-license / license-header (pull_request) Failing after 25s
this commit appears to cause some games to not boot on certain platforms (Linux is unaffected)--needs testing since this may be a linker issue
This commit is contained in:
parent
020ad29a8c
commit
1c97fe3340
3 changed files with 98 additions and 18 deletions
|
@ -32,6 +32,7 @@ add_library(
|
||||||
atomic_ops.h
|
atomic_ops.h
|
||||||
bit_cast.h
|
bit_cast.h
|
||||||
bit_field.h
|
bit_field.h
|
||||||
|
bit_set.h
|
||||||
bit_util.h
|
bit_util.h
|
||||||
bounded_threadsafe_queue.h
|
bounded_threadsafe_queue.h
|
||||||
cityhash.cpp
|
cityhash.cpp
|
||||||
|
|
86
src/common/bit_set.h
Normal file
86
src/common/bit_set.h
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <bit>
|
||||||
|
|
||||||
|
#include "common/alignment.h"
|
||||||
|
#include "common/bit_util.h"
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Common {
|
||||||
|
|
||||||
|
namespace impl {
|
||||||
|
|
||||||
|
template <typename Storage, size_t N>
|
||||||
|
class BitSet {
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr BitSet() = default;
|
||||||
|
|
||||||
|
constexpr void SetBit(size_t i) {
|
||||||
|
this->words[i / FlagsPerWord] |= GetBitMask(i % FlagsPerWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void ClearBit(size_t i) {
|
||||||
|
this->words[i / FlagsPerWord] &= ~GetBitMask(i % FlagsPerWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr size_t CountLeadingZero() const {
|
||||||
|
for (size_t i = 0; i < NumWords; i++) {
|
||||||
|
if (this->words[i]) {
|
||||||
|
return FlagsPerWord * i + CountLeadingZeroImpl(this->words[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FlagsPerWord * NumWords;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr size_t GetNextSet(size_t n) const {
|
||||||
|
for (size_t i = (n + 1) / FlagsPerWord; i < NumWords; i++) {
|
||||||
|
Storage word = this->words[i];
|
||||||
|
if (!IsAligned(n + 1, FlagsPerWord)) {
|
||||||
|
word &= GetBitMask(n % FlagsPerWord) - 1;
|
||||||
|
}
|
||||||
|
if (word) {
|
||||||
|
return FlagsPerWord * i + CountLeadingZeroImpl(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FlagsPerWord * NumWords;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static_assert(std::is_unsigned_v<Storage>);
|
||||||
|
static_assert(sizeof(Storage) <= sizeof(u64));
|
||||||
|
|
||||||
|
static constexpr size_t FlagsPerWord = BitSize<Storage>();
|
||||||
|
static constexpr size_t NumWords = AlignUp(N, FlagsPerWord) / FlagsPerWord;
|
||||||
|
|
||||||
|
static constexpr auto CountLeadingZeroImpl(Storage word) {
|
||||||
|
return std::countl_zero(static_cast<unsigned long long>(word)) -
|
||||||
|
(BitSize<unsigned long long>() - FlagsPerWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Storage GetBitMask(size_t bit) {
|
||||||
|
return Storage(1) << (FlagsPerWord - 1 - bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<Storage, NumWords> words{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace impl
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
using BitSet8 = impl::BitSet<u8, N>;
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
using BitSet16 = impl::BitSet<u16, N>;
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
using BitSet32 = impl::BitSet<u32, N>;
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
using BitSet64 = impl::BitSet<u64, N>;
|
||||||
|
|
||||||
|
} // namespace Common
|
|
@ -1,6 +1,3 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
@ -8,11 +5,10 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <bit>
|
#include <bit>
|
||||||
#include <bitset>
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
#include "common/bit_set.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/concepts.h"
|
#include "common/concepts.h"
|
||||||
|
|
||||||
|
@ -163,7 +159,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_queues[priority].PushBack(core, member)) {
|
if (m_queues[priority].PushBack(core, member)) {
|
||||||
m_available_priorities[core].set(std::size_t(priority));
|
m_available_priorities[core].SetBit(priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +172,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_queues[priority].PushFront(core, member)) {
|
if (m_queues[priority].PushFront(core, member)) {
|
||||||
m_available_priorities[core].set(std::size_t(priority));
|
m_available_priorities[core].SetBit(priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,14 +185,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_queues[priority].Remove(core, member)) {
|
if (m_queues[priority].Remove(core, member)) {
|
||||||
m_available_priorities[core].reset(std::size_t(priority));
|
m_available_priorities[core].ClearBit(priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Member* GetFront(s32 core) const {
|
constexpr Member* GetFront(s32 core) const {
|
||||||
ASSERT(IsValidCore(core));
|
ASSERT(IsValidCore(core));
|
||||||
|
|
||||||
const s32 priority = s32((~m_available_priorities[core]).count());
|
const s32 priority = static_cast<s32>(m_available_priorities[core].CountLeadingZero());
|
||||||
if (priority <= LowestPriority) {
|
if (priority <= LowestPriority) {
|
||||||
return m_queues[priority].GetFront(core);
|
return m_queues[priority].GetFront(core);
|
||||||
} else {
|
} else {
|
||||||
|
@ -220,14 +216,11 @@ public:
|
||||||
|
|
||||||
Member* next = member->GetPriorityQueueEntry(core).GetNext();
|
Member* next = member->GetPriorityQueueEntry(core).GetNext();
|
||||||
if (next == nullptr) {
|
if (next == nullptr) {
|
||||||
s32 priority = member->GetPriority() + 1;
|
const s32 priority = static_cast<s32>(
|
||||||
do {
|
m_available_priorities[core].GetNextSet(member->GetPriority()));
|
||||||
if (m_available_priorities[core][priority]) {
|
if (priority <= LowestPriority) {
|
||||||
next = m_queues[priority].GetFront(core);
|
next = m_queues[priority].GetFront(core);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
++priority;
|
|
||||||
} while (priority <= LowestPriority && priority < s32(m_available_priorities[core].size()));
|
|
||||||
}
|
}
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +250,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<KPerCoreQueue, NumPriority> m_queues{};
|
std::array<KPerCoreQueue, NumPriority> m_queues{};
|
||||||
std::array<std::bitset<NumPriority>, NumCores> m_available_priorities{};
|
std::array<Common::BitSet64<NumPriority>, NumCores> m_available_priorities{};
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue