rust: Made the wrap helper inline and fixed an accidental copy error

This commit is contained in:
dragonmux 2024-01-03 15:07:53 +00:00 committed by myrtle
parent 3e46fbc655
commit cb269b46d6

View File

@ -24,17 +24,12 @@
namespace {
USING_NEXTPNR_NAMESPACE;
// `memcpy` is used here to avoid strict-aliasing problems, but GCC dislikes it.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
template<typename T>
uint64_t wrap(T thing) {
template<typename T> static inline uint64_t wrap(const T &thing) noexcept {
static_assert(sizeof(T) <= 8, "T is too big for FFI");
uint64_t b = 0;
memcpy(&b, &thing, sizeof(T));
return b;
}
#pragma GCC diagnostic pop
template<typename T> static inline T unwrap(const std::array<uint8_t, 8> &value) noexcept {
static_assert(sizeof(T) <= 8, "T is too big for FFI");