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 <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46322
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
Daniel R. Carvalho
2021-06-01 10:08:52 -03:00
committed by Daniel Carvalho
parent 223b0b388e
commit 6be82cc3ae
2 changed files with 21 additions and 8 deletions

View File

@@ -68,17 +68,18 @@ class VirtQueue;
* of byte swapping.
*/
static inline vring_used_elem
swap_byte(vring_used_elem v)
template <typename T>
inline std::enable_if_t<std::is_same<T, vring_used_elem>::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 <typename T>
inline std::enable_if_t<std::is_same<T, vring_desc>::value, T>
swap_byte(T v)
{
v.addr = swap_byte(v.addr);
v.len = swap_byte(v.len);

View File

@@ -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 <endian.h>
@@ -55,6 +52,12 @@
#include <type_traits>
#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 <typename T>
std::enable_if_t<std::is_same<T, vring_used_elem>::value, T>
swap_byte(T v);
template <typename T>
std::enable_if_t<std::is_same<T, vring_desc>::value, T>
swap_byte(T v);
template <typename T, size_t N>
inline std::array<T, N>
swap_byte(std::array<T, N> a)