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.
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 #ifndef _ASM_BITS_BYTESWAP_H
20 #define _ASM_BITS_BYTESWAP_H 1
22 #include <bits/wordsize.h>
24 #define __bswap_non_constant_16(x) \
26 ({ register unsigned short int __v; \
27 __asm__ ("rorw $8, %w0" \
33 #if __WORDSIZE == 64 || (defined __i486__ || defined __pentium__ \
34 || defined __pentiumpro__ || defined __pentium4__ \
35 || defined __k8__ || defined __athlon__ \
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) \
41 ({ register unsigned int __v; \
42 __asm__ ("bswap %0" : "=r" (__v) : "0" (x)); \
45 # define __bswap_non_constant_32(x) \
47 ({ register unsigned int __v; \
48 __asm__ ("rorw $8, %w0;" \
58 # define __bswap_non_constant_64(x) \
60 ({ register unsigned long __v; \
61 __asm__ ("bswap %q0" : "=r" (__v) : "0" (x)); \
67 #include <bits/byteswap-common.h>