byteswap.hh (12383:57de7e3b7ba0) byteswap.hh (12386:2bf5fb25a5f1)
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
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/bigint.hh"
41#include "base/types.hh"
42
43// This lets us figure out what the byte order of the host system is
44#if defined(__linux__)
45#include <endian.h>
46// If this is a linux system, lets used the optimized definitions if they exist.
47// If one doesn't exist, we pretty much get what is listed below, so it all
48// works out

--- 69 unchanged lines hidden (view full) ---

118 else if (sizeof(T) == 2)
119 return swap_byte16((uint16_t)x);
120 else if (sizeof(T) == 1)
121 return x;
122 else
123 panic("Can't byte-swap values larger than 64 bits");
124}
125
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
126template<>
127inline Twin64_t swap_byte<Twin64_t>(Twin64_t x)
128{
129 x.a = swap_byte(x.a);
130 x.b = swap_byte(x.b);
131 return x;
132}
133
134template<>
135inline Twin32_t swap_byte<Twin32_t>(Twin32_t x)
136{
137 x.a = swap_byte(x.a);
138 x.b = swap_byte(x.b);
139 return x;
140}
141
142template <typename T, size_t N>
143inline std::array<T, N>
144swap_byte(std::array<T, N> a)
145{
146 for (T &v: a)
147 v = swap_byte(v);
148 return a;
149}

--- 58 unchanged lines hidden ---
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 ---