From dcef597345ee18060420a0b205c09782da20492f Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 12 May 2022 17:04:47 +0100 Subject: [PATCH] Introduce TrivialObject concept and use where appropriate Simplifies type checking and handles excluding container types that are trivially copyable but contain pointers --- app/src/main/cpp/skyline/common/address_space.h | 7 +++---- app/src/main/cpp/skyline/common/utils.h | 9 +++++++-- .../main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/skyline/common/address_space.h b/app/src/main/cpp/skyline/common/address_space.h index 3a64a44f..5d00787a 100644 --- a/app/src/main/cpp/skyline/common/address_space.h +++ b/app/src/main/cpp/skyline/common/address_space.h @@ -187,13 +187,12 @@ namespace skyline { void Write(VaType virt, u8 *source, VaType size); template - void Write(VaType virt, span source) { + void Write(VaType virt, span source) { Write(virt, reinterpret_cast(source.data()), source.size_bytes()); } - template - void Write(VaType virt, T source) { - Write(virt, reinterpret_cast(&source), sizeof(T)); + void Write(VaType virt, util::TrivialObject auto source) { + Write(virt, reinterpret_cast(&source), sizeof(source)); } void Copy(VaType dst, VaType src, VaType size); diff --git a/app/src/main/cpp/skyline/common/utils.h b/app/src/main/cpp/skyline/common/utils.h index 1ced47a3..bf7ab9af 100644 --- a/app/src/main/cpp/skyline/common/utils.h +++ b/app/src/main/cpp/skyline/common/utils.h @@ -13,6 +13,12 @@ #include "exception.h" namespace skyline::util { + /** + * @brief Concept for any trivial non-container type + */ + template + concept TrivialObject = std::is_trivially_copyable_v && !requires(T v) { v.data(); }; + /** * @brief Returns the current time in nanoseconds * @return The current time in nanoseconds @@ -241,8 +247,7 @@ namespace skyline::util { std::generate(in.begin(), in.end(), [&]() { return dist(detail::generator); }); } - template - requires (std::is_trivially_copyable_v && !requires (T v) { v.data(); }) + template void FillRandomBytes(T &object) { FillRandomBytes(std::span(reinterpret_cast::Type *>(&object), IntegerFor::Count)); } diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp index 98ee33d8..8cce3558 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp @@ -20,7 +20,7 @@ namespace skyline::soc::gm20b::engine { if (state.launchDma.layout == RegisterState::DmaDstMemoryLayout::Pitch && state.lineCount == 1) { // TODO: we can do this with the buffer manager to avoid some overhead in the future Logger::Debug("range: 0x{:X} -> 0x{:X}", u64{state.offsetOut}, u64{state.offsetOut} + buffer.size() * 0x4); - addressSpaceContext->gmmu.Write(state.offsetOut, buffer); + addressSpaceContext->gmmu.Write(state.offsetOut, span(buffer)); } else { Logger::Warn("Non-linear I2M uploads are not supported!"); }