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 #define __bswap_non_constant_16(x) \ 23 (__extension__ \ 24 ({ register unsigned short int __v; \ 25 __asm__ ("rorw $8, %w0" \ 26 : "=r" (__v) \ 27 : "0" (x) \ 28 : "cc"); \ 29 __v; })) 30 31 /* To swap the bytes in a word the i486 processors and up provide the 32 `bswap' opcode. On i386 we have to use three instructions. */ 33 #if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ \ 34 && !defined __pentium4__ 35 # define __bswap_non_constant_32(x) \ 36 (__extension__ \ 37 ({ register unsigned int __v; \ 38 __asm__ ("rorw $8, %w0;" \ 39 "rorl $16, %0;" \ 40 "rorw $8, %w0" \ 41 : "=r" (__v) \ 42 : "0" (x) \ 43 : "cc"); \ 44 __v; })) 45 #else 46 # define __bswap_non_constant_32(x) \ 47 (__extension__ \ 48 ({ register unsigned int __v; \ 49 __asm__ ("bswap %0" : "=r" (__v) : "0" (x)); \ 50 __v; })) 51 #endif 52 53 #endif 54 55 #include <bits/byteswap-common.h> 56