debuggers.hg

view extras/mini-os/include/ia64/endian.h @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 5c0bf00e371d
line source
1 /*
2 * Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
3 * Parts are taken from FreeBSD.
4 *
5 ****************************************************************************
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
26 #if !defined(_ENDIAN_H_)
27 #define _ENDIAN_H_
29 #include "types.h"
32 #if !defined(__ASSEMBLY__)
34 #if defined(BIG_ENDIAN)
36 static __inline uint64_t
37 __bswap64(uint64_t __x)
38 {
39 uint64_t __r;
40 asm __volatile("mux1 %0=%1,@rev" : "=r" (__r) : "r"(__x));
41 return __r;
42 }
44 static __inline uint32_t
45 __bswap32(uint32_t __x)
46 {
47 return (__bswap64(__x) >> 32);
48 }
50 static __inline uint16_t
51 __bswap16(uint16_t __x)
52 {
53 return (__bswap64(__x) >> 48);
54 }
56 #define doswap(x,sz) ( \
57 ((sz)==1)? (uint8_t)(x): \
58 ((sz)==2)? __bswap16(x): \
59 ((sz)==4)? __bswap32(x): \
60 ((sz)==8)? __bswap64(x): \
61 ~0l )
63 #define SWAP(x) doswap((x), sizeof((x)))
66 #else /* defined(BIG_ENDIAN) */
68 #define SWAP(x) (x)
70 #endif /* defined(BIG_ENDIAN) */
72 #endif /* !defined(__ASSEMBLY__) */
75 #endif /* !defined(_ENDIAN_H_) */