1 |
1325 |
phoenix |
/* Macros to swap the order of bytes in integer values. m68k version.
|
2 |
|
|
Copyright (C) 1997, 2002 Free Software Foundation, Inc.
|
3 |
|
|
This file is part of the GNU C Library.
|
4 |
|
|
|
5 |
|
|
The GNU C Library is free software; you can redistribute it and/or
|
6 |
|
|
modify it under the terms of the GNU Lesser General Public
|
7 |
|
|
License as published by the Free Software Foundation; either
|
8 |
|
|
version 2.1 of the License, or (at your option) any later version.
|
9 |
|
|
|
10 |
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 |
|
|
Lesser General Public License for more details.
|
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU Lesser General Public
|
16 |
|
|
License along with the GNU C Library; if not, write to the Free
|
17 |
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
18 |
|
|
02111-1307 USA. */
|
19 |
|
|
|
20 |
|
|
#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
|
21 |
|
|
# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
|
22 |
|
|
#endif
|
23 |
|
|
|
24 |
|
|
#ifndef _BITS_BYTESWAP_H
|
25 |
|
|
#define _BITS_BYTESWAP_H 1
|
26 |
|
|
|
27 |
|
|
/* Swap bytes in 16 bit value. We don't provide an assembler version
|
28 |
|
|
because GCC is smart enough to generate optimal assembler output, and
|
29 |
|
|
this allows for better cse. */
|
30 |
|
|
#define __bswap_16(x) \
|
31 |
|
|
((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
|
32 |
|
|
|
33 |
|
|
/* Swap bytes in 32 bit value. */
|
34 |
|
|
#define __bswap_constant_32(x) \
|
35 |
|
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
36 |
|
|
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
|
37 |
|
|
|
38 |
|
|
#if defined __GNUC__ && __GNUC__ >= 2
|
39 |
|
|
# define __bswap_32(x) \
|
40 |
|
|
__extension__ \
|
41 |
|
|
({ unsigned int __bswap_32_v; \
|
42 |
|
|
if (__builtin_constant_p (x)) \
|
43 |
|
|
__bswap_32_v = __bswap_constant_32 (x); \
|
44 |
|
|
else \
|
45 |
|
|
__asm__ __volatile__ ("ror%.w %#8, %0;" \
|
46 |
|
|
"swap %0;" \
|
47 |
|
|
"ror%.w %#8, %0" \
|
48 |
|
|
: "=d" (__bswap_32_v) \
|
49 |
|
|
: "0" ((unsigned int) (x))); \
|
50 |
|
|
__bswap_32_v; })
|
51 |
|
|
#else
|
52 |
|
|
# define __bswap_32(x) __bswap_constant_32 (x)
|
53 |
|
|
#endif
|
54 |
|
|
|
55 |
|
|
#if defined __GNUC__ && __GNUC__ >= 2
|
56 |
|
|
/* Swap bytes in 64 bit value. */
|
57 |
|
|
# define __bswap_64(x) \
|
58 |
|
|
__extension__ \
|
59 |
|
|
({ union { unsigned long long int __ll; \
|
60 |
|
|
unsigned long int __l[2]; } __bswap_64_v, __bswap_64_r; \
|
61 |
|
|
__bswap_64_v.__ll = (x); \
|
62 |
|
|
__bswap_64_r.__l[0] = __bswap_32 (__bswap_64_v.__l[1]); \
|
63 |
|
|
__bswap_64_r.__l[1] = __bswap_32 (__bswap_64_v.__l[0]); \
|
64 |
|
|
__bswap_64_r.__ll; })
|
65 |
|
|
#endif
|
66 |
|
|
|
67 |
|
|
#endif /* _BITS_BYTESWAP_H */
|