From 6be82cc3aeca52d56c4531a2e2d616a99257004f Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Tue, 1 Jun 2021 10:08:52 -0300 Subject: [PATCH] dev,sim: Fix compiler not finding specialized byte_swap The specialized version of byte_swap cannot be found by the compiler. As a temporary workaround to get the major patch going, move the specialization to the base header file. Change-Id: I7d2bfc1c29b70042860ae06cdc043c0490cd8916 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46322 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power --- src/dev/virtio/base.hh | 11 ++++++----- src/sim/byteswap.hh | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) 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)