xref: /netbsd-src/external/gpl2/gettext/include/byteswap.h (revision 95b39c65ca575fb40c6bb7083e0eb7ec28eabef1)
1*95b39c65Schristos /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2*95b39c65Schristos /* byteswap.h - Byte swapping
3*95b39c65Schristos    Copyright (C) 2005 Free Software Foundation, Inc.
4*95b39c65Schristos    Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
5*95b39c65Schristos 
6*95b39c65Schristos    This program is free software; you can redistribute it and/or modify
7*95b39c65Schristos    it under the terms of the GNU General Public License as published by
8*95b39c65Schristos    the Free Software Foundation; either version 2, or (at your option)
9*95b39c65Schristos    any later version.
10*95b39c65Schristos 
11*95b39c65Schristos    This program is distributed in the hope that it will be useful,
12*95b39c65Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*95b39c65Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*95b39c65Schristos    GNU General Public License for more details.
15*95b39c65Schristos 
16*95b39c65Schristos    You should have received a copy of the GNU General Public License
17*95b39c65Schristos    along with this program; if not, write to the Free Software Foundation,
18*95b39c65Schristos    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19*95b39c65Schristos 
20*95b39c65Schristos #ifndef _BYTESWAP_H
21*95b39c65Schristos 
22*95b39c65Schristos #include <sys/endian.h>
23*95b39c65Schristos #if _BYTE_ORDER == _LITTLE_ENDIAN
24*95b39c65Schristos /* Given an unsigned 16-bit argument X, return the value corresponding to
25*95b39c65Schristos    X with reversed byte order.  */
26*95b39c65Schristos #define bswap_16(x) ((((x) & 0x00FF) << 8) | \
27*95b39c65Schristos 		     (((x) & 0xFF00) >> 8))
28*95b39c65Schristos 
29*95b39c65Schristos /* Given an unsigned 32-bit argument X, return the value corresponding to
30*95b39c65Schristos    X with reversed byte order.  */
31*95b39c65Schristos #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
32*95b39c65Schristos 		     (((x) & 0x0000FF00) << 8) | \
33*95b39c65Schristos 		     (((x) & 0x00FF0000) << 8) | \
34*95b39c65Schristos 		     (((x) & 0xFF000000) >> 24))
35*95b39c65Schristos 
36*95b39c65Schristos /* Given an unsigned 64-bit argument X, return the value corresponding to
37*95b39c65Schristos    X with reversed byte order.  */
38*95b39c65Schristos #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
39*95b39c65Schristos 		     (((x) & 0x000000000000FF00ULL) << 40) | \
40*95b39c65Schristos 		     (((x) & 0x0000000000FF0000ULL) << 24) | \
41*95b39c65Schristos 		     (((x) & 0x00000000FF000000ULL) << 8) | \
42*95b39c65Schristos 		     (((x) & 0x000000FF00000000ULL) >> 8) | \
43*95b39c65Schristos 		     (((x) & 0x0000FF0000000000ULL) >> 24) | \
44*95b39c65Schristos 		     (((x) & 0x00FF000000000000ULL) >> 40) | \
45*95b39c65Schristos 		     (((x) & 0xFF00000000000000ULL) >> 56))
46*95b39c65Schristos #else
47*95b39c65Schristos #define bswap_16(x) (x)
48*95b39c65Schristos #define bswap_32(x) (x)
49*95b39c65Schristos #define bswap_64(x) (x)
50*95b39c65Schristos #endif
51*95b39c65Schristos 
52*95b39c65Schristos #endif
53