1/* 2 * Copyright (c) 2004 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 23 unchanged lines hidden (view full) --- 32 33//The purpose of this file is to provide endainness conversion utility 34//functions. Depending on the endianness of the guest system, either 35//the LittleEndianGuest or BigEndianGuest namespace is used. 36 37#ifndef __SIM_BYTE_SWAP_HH__ 38#define __SIM_BYTE_SWAP_HH__ 39 |
40#include "base/types.hh" 41 42// This lets us figure out what the byte order of the host system is 43#if defined(__linux__) 44#include <endian.h> 45// If this is a linux system, lets used the optimized definitions if they exist. 46// If one doesn't exist, we pretty much get what is listed below, so it all 47// works out --- 69 unchanged lines hidden (view full) --- 117 else if (sizeof(T) == 2) 118 return swap_byte16((uint16_t)x); 119 else if (sizeof(T) == 1) 120 return x; 121 else 122 panic("Can't byte-swap values larger than 64 bits"); 123} 124 |
125template <typename T, size_t N> 126inline std::array<T, N> 127swap_byte(std::array<T, N> a) 128{ 129 for (T &v: a) 130 v = swap_byte(v); 131 return a; 132} --- 58 unchanged lines hidden --- |