]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/x86_64/bits/byteswap.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / x86_64 / bits / byteswap.h
1 /* Macros to swap the order of bytes in integer values.
2    Copyright (C) 1997, 1998, 2000, 2002, 2003 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, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _ASM_BITS_BYTESWAP_H
20 #define _ASM_BITS_BYTESWAP_H 1
21
22 #include <bits/wordsize.h>
23
24 #define __bswap_non_constant_16(x) \
25      (__extension__                                                           \
26       ({ register unsigned short int __v;                                     \
27          __asm__ ("rorw $8, %w0"                                              \
28                   : "=r" (__v)                                                \
29                   : "0" (x)                                                   \
30                   : "cc");                                                    \
31          __v; }))
32
33 #if __WORDSIZE == 64 || (defined __i486__ || defined __pentium__              \
34                      || defined __pentiumpro__ || defined __pentium4__        \
35                      || defined __k8__ || defined __athlon__                  \
36                      || defined __k6__)
37 /* To swap the bytes in a word the i486 processors and up provide the
38    `bswap' opcode.  On i386 we have to use three instructions.  */
39 # define __bswap_non_constant_32(x) \
40      (__extension__                                                           \
41       ({ register unsigned int __v;                                           \
42          __asm__ ("bswap %0" : "=r" (__v) : "0" (x));                         \
43          __v; }))
44 #else
45 # define __bswap_non_constant_32(x) \
46      (__extension__                                                           \
47       ({ register unsigned int __v;                                           \
48          __asm__ ("rorw $8, %w0;"                                             \
49                   "rorl $16, %0;"                                             \
50                   "rorw $8, %w0"                                              \
51                   : "=r" (__v)                                                \
52                   : "0" (x)                                                   \
53                   : "cc");                                                    \
54          __v; }))
55 #endif
56
57 #if __WORDSIZE == 64
58 # define __bswap_non_constant_64(x) \
59      (__extension__                                                           \
60       ({ register unsigned long __v;                                          \
61          __asm__ ("bswap %q0" : "=r" (__v) : "0" (x));                        \
62          __v; }))
63 #endif
64
65 #endif
66
67 #include <bits/byteswap-common.h>