Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / ia64 / bits / byteswap.h
blobc00768eab02609e6d7dfc7f3482450830fa357d3
1 /* Macros to swap the order of bytes in integer values.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #if !defined _BYTESWAP_H && !defined _NETINET_IN_H && !defined _ENDIAN_H
20 # error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
21 #endif
23 #ifndef _BITS_BYTESWAP_H
24 #define _BITS_BYTESWAP_H 1
26 /* Swap bytes in 16 bit value. */
27 #define __bswap_constant_16(x) \
28 ((unsigned short int)((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
30 /* Get __bswap_16. */
31 #include <bits/byteswap-16.h>
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))
38 #if defined __GNUC__ && __GNUC__ >= 2
39 # define __bswap_32(x) \
40 (__extension__ \
41 ({ unsigned int __v, __x = (x); \
42 if (__builtin_constant_p (x)) \
43 __v = __bswap_constant_32 (__x); \
44 else \
45 __asm__ __volatile__ ("shl %0 = %1, 32 ;;" \
46 "mux1 %0 = %0, @rev ;;" \
47 : "=r" (__v) \
48 : "r" ((unsigned int) (__x))); \
49 __v; }))
50 #else
51 static __inline unsigned int
52 __bswap_32 (unsigned int __bsx)
54 return __bswap_constant_32 (__bsx);
56 #endif
59 /* Swap bytes in 64 bit value. */
60 #if defined __GNUC__ && __GNUC__ >= 2
61 # define __bswap_constant_64(x) \
62 (__extension__ ((((x) & 0xff00000000000000ul) >> 56) \
63 | (((x) & 0x00ff000000000000ul) >> 40) \
64 | (((x) & 0x0000ff0000000000ul) >> 24) \
65 | (((x) & 0x000000ff00000000ul) >> 8) \
66 | (((x) & 0x00000000ff000000ul) << 8) \
67 | (((x) & 0x0000000000ff0000ul) << 24) \
68 | (((x) & 0x000000000000ff00ul) << 40) \
69 | (((x) & 0x00000000000000fful) << 56)))
71 # define __bswap_64(x) \
72 (__extension__ \
73 ({ unsigned long int __v, __x = (x); \
74 if (__builtin_constant_p (x)) \
75 __v = __bswap_constant_64 (__x); \
76 else \
77 __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \
78 : "=r" (__v) \
79 : "r" ((unsigned long int) (__x))); \
80 __v; }))
82 #else
83 # define __bswap_constant_64(x) \
84 ((((x) & 0xff00000000000000ul) >> 56) \
85 | (((x) & 0x00ff000000000000ul) >> 40) \
86 | (((x) & 0x0000ff0000000000ul) >> 24) \
87 | (((x) & 0x000000ff00000000ul) >> 8) \
88 | (((x) & 0x00000000ff000000ul) << 8) \
89 | (((x) & 0x0000000000ff0000ul) << 24) \
90 | (((x) & 0x000000000000ff00ul) << 40) \
91 | (((x) & 0x00000000000000fful) << 56))
93 static __inline unsigned long int
94 __bswap_64 (unsigned long int __bsx)
96 return __bswap_constant_64 (__bsx);
98 #endif
100 #endif /* _BITS_BYTESWAP_H */