Introduce TrivialObject concept and use where appropriate

Simplifies type checking and handles excluding container types that are trivially copyable but contain pointers
This commit is contained in:
Billy Laws 2022-05-12 17:04:47 +01:00
parent f2cc25ee9f
commit dcef597345
3 changed files with 11 additions and 7 deletions

View File

@ -191,9 +191,8 @@ namespace skyline {
Write(virt, reinterpret_cast<u8 *>(source.data()), source.size_bytes()); Write(virt, reinterpret_cast<u8 *>(source.data()), source.size_bytes());
} }
template<typename T> void Write(VaType virt, util::TrivialObject auto source) {
void Write(VaType virt, T source) { Write(virt, reinterpret_cast<u8 *>(&source), sizeof(source));
Write(virt, reinterpret_cast<u8 *>(&source), sizeof(T));
} }
void Copy(VaType dst, VaType src, VaType size); void Copy(VaType dst, VaType src, VaType size);

View File

@ -13,6 +13,12 @@
#include "exception.h" #include "exception.h"
namespace skyline::util { namespace skyline::util {
/**
* @brief Concept for any trivial non-container type
*/
template<typename T>
concept TrivialObject = std::is_trivially_copyable_v<T> && !requires(T v) { v.data(); };
/** /**
* @brief Returns the current time in nanoseconds * @brief Returns the current time in nanoseconds
* @return 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); }); std::generate(in.begin(), in.end(), [&]() { return dist(detail::generator); });
} }
template<class T> template<TrivialObject T>
requires (std::is_trivially_copyable_v<T> && !requires (T v) { v.data(); })
void FillRandomBytes(T &object) { void FillRandomBytes(T &object) {
FillRandomBytes(std::span(reinterpret_cast<typename IntegerFor<T>::Type *>(&object), IntegerFor<T>::Count)); FillRandomBytes(std::span(reinterpret_cast<typename IntegerFor<T>::Type *>(&object), IntegerFor<T>::Count));
} }

View File

@ -20,7 +20,7 @@ namespace skyline::soc::gm20b::engine {
if (state.launchDma.layout == RegisterState::DmaDstMemoryLayout::Pitch && state.lineCount == 1) { 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 // 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); 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 { } else {
Logger::Warn("Non-linear I2M uploads are not supported!"); Logger::Warn("Non-linear I2M uploads are not supported!");
} }