mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-09 06:46:57 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51f2e2bfb9 |
+13
-12
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -146,16 +143,20 @@ public:
|
||||
return m_str;
|
||||
}
|
||||
|
||||
size_t GetLength() const {
|
||||
return std::strlen(this->GetString());
|
||||
constexpr size_t GetLength() const {
|
||||
if (std::is_constant_evaluated()) {
|
||||
return Strlen(this->GetString());
|
||||
} else {
|
||||
return std::strlen(this->GetString());
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool IsEmpty() const {
|
||||
return *m_str == '\x00';
|
||||
}
|
||||
|
||||
bool IsMatchHead(const char* p, size_t len) const {
|
||||
return std::strncmp(this->GetString(), p, len) == 0;
|
||||
constexpr bool IsMatchHead(const char* p, size_t len) const {
|
||||
return Strncmp(this->GetString(), p, len) == 0;
|
||||
}
|
||||
|
||||
Result Initialize(const Path& rhs) {
|
||||
@@ -168,7 +169,7 @@ public:
|
||||
R_TRY(this->Preallocate(len + 1));
|
||||
|
||||
// Copy the path
|
||||
const size_t copied = strlcpy(m_write_buffer.Get(), rhs.GetString(), len + 1);
|
||||
const size_t copied = Strlcpy<char>(m_write_buffer.Get(), rhs.GetString(), len + 1);
|
||||
R_UNLESS(copied == len, ResultUnexpectedInPathA);
|
||||
|
||||
// Set normalized
|
||||
@@ -330,14 +331,14 @@ public:
|
||||
// Get our write buffer
|
||||
auto* dst = m_write_buffer.Get();
|
||||
if (old_write_buffer.Get() != nullptr && cur_len > 0) {
|
||||
strlcpy(dst, old_write_buffer.Get(), cur_len + 1);
|
||||
Strlcpy<char>(dst, old_write_buffer.Get(), cur_len + 1);
|
||||
}
|
||||
|
||||
// Add separator
|
||||
dst[cur_len] = '/';
|
||||
|
||||
// Copy the child path
|
||||
const size_t copied = strlcpy(dst + cur_len + 1, c, child_len + 1);
|
||||
const size_t copied = Strlcpy<char>(dst + cur_len + 1, c, child_len + 1);
|
||||
R_UNLESS(copied == child_len, ResultUnexpectedInPathA);
|
||||
|
||||
R_SUCCEED();
|
||||
@@ -374,7 +375,7 @@ public:
|
||||
if (m_write_buffer.Get() == nullptr) {
|
||||
if (const auto len = std::strlen(m_str); len > 0) {
|
||||
R_TRY(this->Preallocate(len));
|
||||
strlcpy(m_write_buffer.Get(), m_str, len + 1);
|
||||
Strlcpy<char>(m_write_buffer.Get(), m_str, len + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,7 +497,7 @@ private:
|
||||
R_TRY(this->Preallocate(size + 1));
|
||||
|
||||
// Copy the path
|
||||
const size_t copied = strlcpy(m_write_buffer.Get(), path, size + 1);
|
||||
const size_t copied = Strlcpy<char>(m_write_buffer.Get(), path, size + 1);
|
||||
R_UNLESS(copied >= size, ResultUnexpectedInPathA);
|
||||
} else {
|
||||
// We can just clear the buffer
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
@@ -1217,7 +1217,7 @@ public:
|
||||
replaced_src = static_cast<char*>(Allocate(replaced_src_len));
|
||||
}
|
||||
|
||||
strlcpy(replaced_src, src, replaced_src_len);
|
||||
Strlcpy<char>(replaced_src, src, replaced_src_len);
|
||||
|
||||
Replace(replaced_src, replaced_src_len, AlternateDirectorySeparator,
|
||||
DirectorySeparator);
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -10,6 +7,85 @@
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
template <typename T>
|
||||
constexpr int Strlen(const T* str) {
|
||||
ASSERT(str != nullptr);
|
||||
|
||||
int length = 0;
|
||||
while (*str++) {
|
||||
++length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr int Strnlen(const T* str, std::size_t count) {
|
||||
return Strnlen(str, static_cast<int>(count));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr int Strnlen(const T* str, int count) {
|
||||
ASSERT(str != nullptr);
|
||||
ASSERT(count >= 0);
|
||||
|
||||
int length = 0;
|
||||
while (count-- && *str++) {
|
||||
++length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr int Strncmp(const T* lhs, const T* rhs, std::size_t count) {
|
||||
return Strncmp(lhs, rhs, static_cast<int>(count));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr int Strncmp(const T* lhs, const T* rhs, int count) {
|
||||
ASSERT(lhs != nullptr);
|
||||
ASSERT(rhs != nullptr);
|
||||
ASSERT(count >= 0);
|
||||
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
T l, r;
|
||||
do {
|
||||
l = *(lhs++);
|
||||
r = *(rhs++);
|
||||
} while (l && (l == r) && (--count));
|
||||
|
||||
return l - r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr int Strlcpy(T* dst, const T* src, std::size_t count) {
|
||||
return Strlcpy<T>(dst, src, static_cast<int>(count));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr int Strlcpy(T* dst, const T* src, int count) {
|
||||
ASSERT(dst != nullptr);
|
||||
ASSERT(src != nullptr);
|
||||
|
||||
const T* cur = src;
|
||||
if (count > 0) {
|
||||
while ((--count) && *cur) {
|
||||
*(dst++) = *(cur++);
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
|
||||
while (*cur) {
|
||||
cur++;
|
||||
}
|
||||
|
||||
return static_cast<int>(cur - src);
|
||||
}
|
||||
|
||||
enum CharacterEncodingResult {
|
||||
CharacterEncodingResult_Success = 0,
|
||||
CharacterEncodingResult_InsufficientLength = 1,
|
||||
|
||||
@@ -7,34 +7,27 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "common/assert.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "dynarmic/backend/x64/block_of_code.h"
|
||||
#include "dynarmic/backend/x64/constant_pool.h"
|
||||
|
||||
namespace Dynarmic::Backend::X64 {
|
||||
|
||||
ConstantPool::ConstantPool(BlockOfCode& code, size_t size)
|
||||
: insertion_point(0)
|
||||
{
|
||||
code.EnsureMemoryCommitted(align_size + size);
|
||||
code.int3();
|
||||
ConstantPool::ConstantPool(BlockOfCode& code, size_t size) noexcept {
|
||||
auto const align_size = 64; //always align to cacheline
|
||||
code.EnsureMemoryCommitted(2 * align_size + size);
|
||||
code.align(align_size);
|
||||
pool = std::span<ConstantT>(reinterpret_cast<ConstantT*>(code.AllocateFromCodeSpace(size)), size / align_size);
|
||||
pool = std::span<u128>(static_cast<u128*>(code.AllocateFromCodeSpace(size)), size / sizeof(u128));
|
||||
}
|
||||
|
||||
Xbyak::Address ConstantPool::GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lower, u64 upper) {
|
||||
const auto constant = ConstantT(lower, upper);
|
||||
auto it = constant_info.find(constant);
|
||||
if (it == constant_info.end()) {
|
||||
ASSERT(insertion_point < pool.size());
|
||||
ConstantT& target_constant = pool[insertion_point];
|
||||
target_constant = constant;
|
||||
it = constant_info.insert({constant, &target_constant}).first;
|
||||
++insertion_point;
|
||||
}
|
||||
return frame[code.rip + it->second];
|
||||
Xbyak::Address ConstantPool::GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lo, u64 hi) noexcept {
|
||||
// offset grows iff new constant is added
|
||||
auto const key = std::make_pair(lo, hi);
|
||||
auto const val = u32(constant_info.size());
|
||||
auto const [it, _] = constant_info.insert({key, val});
|
||||
// if it != constant_info.end(): assume(pool[it->second] == c);
|
||||
pool[it->second] = u128{lo, hi};
|
||||
return frame[code.rip + std::addressof(pool[it->second])];
|
||||
}
|
||||
|
||||
} // namespace Dynarmic::Backend::X64
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <utility>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/container/unordered_map.h"
|
||||
@@ -21,31 +22,17 @@ namespace Dynarmic::Backend::X64 {
|
||||
|
||||
class BlockOfCode;
|
||||
|
||||
/// ConstantPool allocates a block of memory from BlockOfCode.
|
||||
/// @brief ConstantPool allocates a block of memory from BlockOfCode.
|
||||
/// It places constants into this block of memory, returning the address
|
||||
/// of the memory location where the constant is placed. If the constant
|
||||
/// already exists, its memory location is reused.
|
||||
class ConstantPool final {
|
||||
public:
|
||||
ConstantPool(BlockOfCode& code, size_t size);
|
||||
|
||||
Xbyak::Address GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lower, u64 upper = 0);
|
||||
|
||||
private:
|
||||
static constexpr size_t align_size = 16; // bytes
|
||||
|
||||
using ConstantT = std::pair<u64, u64>;
|
||||
static_assert(sizeof(ConstantT) == align_size);
|
||||
|
||||
struct ConstantHash {
|
||||
std::size_t operator()(const ConstantT& constant) const noexcept {
|
||||
return constant.first ^ std::rotl<u64>(constant.second, 1);
|
||||
}
|
||||
};
|
||||
|
||||
::Common::unordered_map<ConstantT, void*, ConstantHash> constant_info;
|
||||
std::span<ConstantT> pool;
|
||||
std::size_t insertion_point;
|
||||
ConstantPool(BlockOfCode& code, size_t size) noexcept;
|
||||
Xbyak::Address GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lower, u64 upper = 0) noexcept;
|
||||
// key = identity hash, value = offset from pool.data()
|
||||
::Common::unordered_map<std::pair<u64, u64>, u32, boost::hash<std::pair<u64, u64>>> constant_info;
|
||||
std::span<u128> pool;
|
||||
};
|
||||
|
||||
} // namespace Dynarmic::Backend::X64
|
||||
|
||||
Reference in New Issue
Block a user