[Base] Add user-literals for several memory sizes

Rather than using `n * 1024 * 1024`, this adds a convenient `_MiB`/`_KiB` user-literal to the new `literals.h` header to concisely describe units of memory in a much more readable way. Any other useful literals can be added to this header. These literals exist in the `xe::literals` namespace so they are opt-in, similar to `std::chrono` literals, and require a `using namespace xe::literals` statement to utilize it within the current scope.

I've done a pass through the codebase to replace trivial instances of `1024 * 1024 * ...` expressions being used but avoided anything that added additional casting complexity from `size_t` to `uint32_t` and such to keep this commit concise.
This commit is contained in:
Wunkolo
2021-12-30 17:25:30 -08:00
committed by Rick Gibbed
parent b64b4c6761
commit 1a8068b151
19 changed files with 109 additions and 25 deletions

View File

@@ -20,6 +20,7 @@
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/assert.h"
#include "xenia/base/clock.h"
#include "xenia/base/literals.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -31,6 +32,8 @@ namespace cpu {
namespace backend {
namespace x64 {
using namespace xe::literals;
X64CodeCache::X64CodeCache() = default;
X64CodeCache::~X64CodeCache() {
@@ -227,7 +230,7 @@ void X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
old_commit_mark = generated_code_commit_mark_;
if (high_mark <= old_commit_mark) break;
new_commit_mark = old_commit_mark + 16 * 1024 * 1024;
new_commit_mark = old_commit_mark + 16_MiB;
if (generated_code_execute_base_ == generated_code_write_base_) {
xe::memory::AllocFixed(generated_code_execute_base_, new_commit_mark,
xe::memory::AllocationType::kCommit,
@@ -310,7 +313,7 @@ uint32_t X64CodeCache::PlaceData(const void* data, size_t length) {
old_commit_mark = generated_code_commit_mark_;
if (high_mark <= old_commit_mark) break;
new_commit_mark = old_commit_mark + 16 * 1024 * 1024;
new_commit_mark = old_commit_mark + 16_MiB;
if (generated_code_execute_base_ == generated_code_write_base_) {
xe::memory::AllocFixed(generated_code_execute_base_, new_commit_mark,
xe::memory::AllocationType::kCommit,

View File

@@ -18,6 +18,7 @@
#include "xenia/base/assert.h"
#include "xenia/base/atomic.h"
#include "xenia/base/debugging.h"
#include "xenia/base/literals.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -50,8 +51,9 @@ namespace x64 {
using xe::cpu::hir::HIRBuilder;
using xe::cpu::hir::Instr;
using namespace xe::literals;
static const size_t kMaxCodeSize = 1 * 1024 * 1024;
static const size_t kMaxCodeSize = 1_MiB;
static const size_t kStashOffset = 32;
// static const size_t kStashOffsetHigh = 32 + 32;

View File

@@ -10,6 +10,7 @@
#include "xenia/base/console_app_main.h"
#include "xenia/base/cvar.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/literals.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/platform.h"
@@ -36,6 +37,7 @@ namespace cpu {
namespace test {
using xe::cpu::ppc::PPCContext;
using namespace xe::literals;
typedef std::vector<std::pair<std::string, std::string>> AnnotationList;
@@ -177,7 +179,7 @@ class TestSuite {
class TestRunner {
public:
TestRunner() : memory_size_(64 * 1024 * 1024) {
TestRunner() : memory_size_(64_MiB) {
memory_.reset(new Memory());
memory_->Initialize();
}

View File

@@ -16,6 +16,7 @@
#include "xenia/base/cvar.h"
#include "xenia/base/debugging.h"
#include "xenia/base/exception_handler.h"
#include "xenia/base/literals.h"
#include "xenia/base/logging.h"
#include "xenia/base/memory.h"
#include "xenia/base/profiling.h"
@@ -57,6 +58,8 @@ namespace cpu {
using xe::cpu::ppc::PPCOpcode;
using xe::kernel::XThread;
using namespace xe::literals;
class BuiltinModule : public Module {
public:
explicit BuiltinModule(Processor* processor)
@@ -142,8 +145,8 @@ bool Processor::Setup(std::unique_ptr<backend::Backend> backend) {
// Open the trace data path, if requested.
functions_trace_path_ = cvars::trace_function_data_path;
if (!functions_trace_path_.empty()) {
functions_trace_file_ = ChunkedMappedMemoryWriter::Open(
functions_trace_path_, 32 * 1024 * 1024, true);
functions_trace_file_ =
ChunkedMappedMemoryWriter::Open(functions_trace_path_, 32_MiB, true);
}
return true;