byteswap.hh (2956:790b4f39c21c) byteswap.hh (3483:edede8473667)
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;

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

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
49#include <byteswap.h>
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;

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

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
49#include <byteswap.h>
50#elif defined (__sun__)
51#include <sys/isa_defs.h>
50#else
51#include <machine/endian.h>
52#endif
53
54#if defined(__APPLE__)
55#include <libkern/OSByteOrder.h>
56#endif
57

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

123
124//The conversion functions with fixed endianness on both ends don't need to
125//be in a namespace
126template <typename T> static inline T betole(T value) {return swap_byte(value);}
127template <typename T> static inline T letobe(T value) {return swap_byte(value);}
128
129//For conversions not involving the guest system, we can define the functions
130//conditionally based on the BYTE_ORDER macro and outside of the namespaces
52#else
53#include <machine/endian.h>
54#endif
55
56#if defined(__APPLE__)
57#include <libkern/OSByteOrder.h>
58#endif
59

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

125
126//The conversion functions with fixed endianness on both ends don't need to
127//be in a namespace
128template <typename T> static inline T betole(T value) {return swap_byte(value);}
129template <typename T> static inline T letobe(T value) {return swap_byte(value);}
130
131//For conversions not involving the guest system, we can define the functions
132//conditionally based on the BYTE_ORDER macro and outside of the namespaces
131#if BYTE_ORDER == BIG_ENDIAN
133#if defined(_BIG_ENDIAN) || BYTE_ORDER == BIG_ENDIAN
132template <typename T> static inline T htole(T value) {return swap_byte(value);}
133template <typename T> static inline T letoh(T value) {return swap_byte(value);}
134template <typename T> static inline T htobe(T value) {return value;}
135template <typename T> static inline T betoh(T value) {return value;}
134template <typename T> static inline T htole(T value) {return swap_byte(value);}
135template <typename T> static inline T letoh(T value) {return swap_byte(value);}
136template <typename T> static inline T htobe(T value) {return value;}
137template <typename T> static inline T betoh(T value) {return value;}
136#elif BYTE_ORDER == LITTLE_ENDIAN
138#elif defined(_LITTLE_ENDIAN) || BYTE_ORDER == LITTLE_ENDIAN
137template <typename T> static inline T htole(T value) {return value;}
138template <typename T> static inline T letoh(T value) {return value;}
139template <typename T> static inline T htobe(T value) {return swap_byte(value);}
140template <typename T> static inline T betoh(T value) {return swap_byte(value);}
141#else
142 #error Invalid Endianess
143#endif
144

--- 32 unchanged lines hidden ---
139template <typename T> static inline T htole(T value) {return value;}
140template <typename T> static inline T letoh(T value) {return value;}
141template <typename T> static inline T htobe(T value) {return swap_byte(value);}
142template <typename T> static inline T betoh(T value) {return swap_byte(value);}
143#else
144 #error Invalid Endianess
145#endif
146

--- 32 unchanged lines hidden ---