Dash:
[t2.git] / package / base / dietlibc / byteswap_prot_h.patch
blobedbb70a9fddd56c2b8c493f9e58476f0758a49f8
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../dietlibc/byteswap_prot_h.patch
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 # Copyright (C) 1998 - 2004 ROCK Linux Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This patch file is dual-licensed. It is available under the license the
11 # patched project is licensed under, as long as it is an OpenSource license
12 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
13 # of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 e2fsprogs >_<
20 --- /dev/null Thu Jan 1 00:00:00 1970
21 +++ ./include/byteswap_prot.h Sat Jan 11 01:23:36 2003
22 @@ -0,0 +1,117 @@
23 +/* Macros to swap the order of bytes in integer values.
24 + Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
25 + This file is part of the GNU C Library.
27 + The GNU C Library is free software; you can redistribute it and/or
28 + modify it under the terms of the GNU Lesser General Public
29 + License as published by the Free Software Foundation; either
30 + version 2.1 of the License, or (at your option) any later version.
32 + The GNU C Library is distributed in the hope that it will be useful,
33 + but WITHOUT ANY WARRANTY; without even the implied warranty of
34 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 + Lesser General Public License for more details.
37 + You should have received a copy of the GNU Lesser General Public
38 + License along with the GNU C Library; if not, write to the Free
39 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
40 + 02111-1307 USA. */
42 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
43 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
44 +#endif
46 +#ifndef _BITS_BYTESWAP_H
47 +#define _BITS_BYTESWAP_H 1
49 +/* Swap bytes in 16 bit value. */
50 +#define __bswap_constant_16(x) \
51 + ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
53 +#if defined __GNUC__ && __GNUC__ >= 2
54 +# define __bswap_16(x) \
55 + (__extension__ \
56 + ({ register unsigned short int __v, __x = (x); \
57 + if (__builtin_constant_p (__x)) \
58 + __v = __bswap_constant_16 (__x); \
59 + else \
60 + __asm__ ("rorw $8, %w0" \
61 + : "=r" (__v) \
62 + : "0" (__x) \
63 + : "cc"); \
64 + __v; }))
65 +#else
66 +/* This is better than nothing. */
67 +# define __bswap_16(x) \
68 + (__extension__ \
69 + ({ register unsigned short int __x = (x); __bswap_constant_16 (__x); }))
70 +#endif
73 +/* Swap bytes in 32 bit value. */
74 +#define __bswap_constant_32(x) \
75 + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
76 + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
78 +#if defined __GNUC__ && __GNUC__ >= 2
79 +/* To swap the bytes in a word the i486 processors and up provide the
80 + `bswap' opcode. On i386 we have to use three instructions. */
81 +# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
82 +# define __bswap_32(x) \
83 + (__extension__ \
84 + ({ register unsigned int __v, __x = (x); \
85 + if (__builtin_constant_p (__x)) \
86 + __v = __bswap_constant_32 (__x); \
87 + else \
88 + __asm__ ("rorw $8, %w0;" \
89 + "rorl $16, %0;" \
90 + "rorw $8, %w0" \
91 + : "=r" (__v) \
92 + : "0" (__x) \
93 + : "cc"); \
94 + __v; }))
95 +# else
96 +# define __bswap_32(x) \
97 + (__extension__ \
98 + ({ register unsigned int __v, __x = (x); \
99 + if (__builtin_constant_p (__x)) \
100 + __v = __bswap_constant_32 (__x); \
101 + else \
102 + __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); \
103 + __v; }))
104 +# endif
105 +#else
106 +# define __bswap_16(x) \
107 + (__extension__ \
108 + ({ register unsigned int __x = (x); __bswap_constant_32 (__x); }))
109 +#endif
112 +#if defined __GNUC__ && __GNUC__ >= 2
113 +/* Swap bytes in 64 bit value. */
114 +#define __bswap_constant_64(x) \
115 + ((((x) & 0xff00000000000000ull) >> 56) \
116 + | (((x) & 0x00ff000000000000ull) >> 40) \
117 + | (((x) & 0x0000ff0000000000ull) >> 24) \
118 + | (((x) & 0x000000ff00000000ull) >> 8) \
119 + | (((x) & 0x00000000ff000000ull) << 8) \
120 + | (((x) & 0x0000000000ff0000ull) << 24) \
121 + | (((x) & 0x000000000000ff00ull) << 40) \
122 + | (((x) & 0x00000000000000ffull) << 56))
124 +# define __bswap_64(x) \
125 + (__extension__ \
126 + ({ union { __extension__ unsigned long long int __ll; \
127 + unsigned long int __l[2]; } __w, __r; \
128 + __w.__ll = (x); \
129 + if (__builtin_constant_p (__w.__ll)) \
130 + __r.__ll = __bswap_constant_64 (__w.__ll); \
131 + else \
132 + { \
133 + __r.__l[0] = __bswap_32 (__w.__l[1]); \
134 + __r.__l[1] = __bswap_32 (__w.__l[0]); \
135 + } \
136 + __r.__ll; }))
137 +#endif
139 +#endif /* _BITS_BYTESWAP_H */