diff --git a/src/dev/virtio/base.hh b/src/dev/virtio/base.hh index 350e51024b..6eeb4a4a71 100644 --- a/src/dev/virtio/base.hh +++ b/src/dev/virtio/base.hh @@ -68,17 +68,18 @@ class VirtQueue; * of byte swapping. */ - -static inline vring_used_elem -swap_byte(vring_used_elem v) +template +inline std::enable_if_t::value, T> +swap_byte(T v) { v.id = swap_byte(v.id); v.len = swap_byte(v.len); return v; } -static inline vring_desc -swap_byte(vring_desc v) +template +inline std::enable_if_t::value, T> +swap_byte(T v) { v.addr = swap_byte(v.addr); v.len = swap_byte(v.len); diff --git a/src/sim/byteswap.hh b/src/sim/byteswap.hh index 30e63d1a54..82282ec76a 100644 --- a/src/sim/byteswap.hh +++ b/src/sim/byteswap.hh @@ -33,9 +33,6 @@ #ifndef __SIM_BYTE_SWAP_HH__ #define __SIM_BYTE_SWAP_HH__ -#include "base/types.hh" -#include "enums/ByteOrder.hh" - // This lets us figure out what the byte order of the host system is #if defined(__linux__) #include @@ -55,6 +52,12 @@ #include +#include "base/types.hh" +#include "enums/ByteOrder.hh" + +struct vring_used_elem; +struct vring_desc; + // These functions actually perform the swapping for parameters of various bit // lengths. inline uint64_t @@ -135,6 +138,15 @@ swap_byte(T x) return x; } +// Make the function visible in case we need to declare a version of it for +// other types +template +std::enable_if_t::value, T> +swap_byte(T v); +template +std::enable_if_t::value, T> +swap_byte(T v); + template inline std::array swap_byte(std::array a)