Fix handling of OCAML_PKG_* macros for new OCaml autoconf.
[ocaml-bitstring.git] / byteswap.in.h
1 /* byteswap.h - Byte swapping
2    Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3    Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program 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
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /* NB:
20
21    This file is from Gnulib, and in accordance with the convention
22    there, the real license of this file comes from the module
23    definition.  It is really LGPLv2+.
24
25    - RWMJ. 2008/08/23
26 */
27
28 #ifndef _GL_BYTESWAP_H
29 #define _GL_BYTESWAP_H
30
31 /* Given an unsigned 16-bit argument X, return the value corresponding to
32    X with reversed byte order.  */
33 #define bswap_16(x) ((((x) & 0x00FF) << 8) | \
34                      (((x) & 0xFF00) >> 8))
35
36 /* Given an unsigned 32-bit argument X, return the value corresponding to
37    X with reversed byte order.  */
38 #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
39                      (((x) & 0x0000FF00) << 8) | \
40                      (((x) & 0x00FF0000) >> 8) | \
41                      (((x) & 0xFF000000) >> 24))
42
43 /* Given an unsigned 64-bit argument X, return the value corresponding to
44    X with reversed byte order.  */
45 #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
46                      (((x) & 0x000000000000FF00ULL) << 40) | \
47                      (((x) & 0x0000000000FF0000ULL) << 24) | \
48                      (((x) & 0x00000000FF000000ULL) << 8) | \
49                      (((x) & 0x000000FF00000000ULL) >> 8) | \
50                      (((x) & 0x0000FF0000000000ULL) >> 24) | \
51                      (((x) & 0x00FF000000000000ULL) >> 40) | \
52                      (((x) & 0xFF00000000000000ULL) >> 56))
53
54 #endif /* _GL_BYTESWAP_H */