limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / c_cpp / etc / calc / byteswap.h
blob2809f51548ff42cf5bb2deb541e11a8bd30d9acf
1 /*
2 * byteswap - byte swapping macros
4 * Copyright (C) 1999 Landon Curt Noll
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.1 $
21 * @(#) $Id: byteswap.h,v 30.1 2007/03/16 11:09:46 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/byteswap.h,v $
24 * Under source code control: 1995/10/11 04:44:01
25 * File existed as early as: 1995
27 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
28 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
32 #if !defined(__BYTESWAP_H__)
33 #define __BYTESWAP_H__
36 #if defined(CALC_SRC) /* if we are building from the calc source tree */
37 # include "longbits.h"
38 #else
39 # include <calc/longbits.h>
40 #endif
44 * SWAP_B8_IN_B16 - swap 8 bits in 16 bits
46 * dest - pointer to where the swapped src wil be put
47 * src - pointer to a 16 bit value to swap
49 * This macro will either switch to the opposite byte sex (Big Endian vs.
50 * Little Endian) a 16 bit value.
52 #define SWAP_B8_IN_B16(dest, src) ( \
53 *((USB16*)(dest)) = \
54 (((*((USB16*)(src))) << 8) | ((*((USB16*)(src))) >> 8)) \
58 * SWAP_B16_IN_B32 - swap 16 bits in 32 bits
60 * dest - pointer to where the swapped src wil be put
61 * src - pointer to a 32 bit value to swap
63 #define SWAP_B16_IN_B32(dest, src) ( \
64 *((USB32*)(dest)) = \
65 (((*((USB32*)(src))) << 16) | ((*((USB32*)(src))) >> 16)) \
69 * SWAP_B8_IN_B32 - swap 8 & 16 bits in 32 bits
71 * dest - pointer to where the swapped src wil be put
72 * src - pointer to a 32 bit value to swap
74 * This macro will either switch to the opposite byte sex (Big Endian vs.
75 * Little Endian) a 32 bit value.
77 #define SWAP_B8_IN_B32(dest, src) ( \
78 SWAP_B16_IN_B32(dest, src), \
79 (*((USB32*)(dest)) = \
80 ((((*((USB32*)(dest))) & (USB32)0xff00ff00) >> 8) | \
81 (((*((USB32*)(dest))) & (USB32)0x00ff00ff) << 8))) \
84 #if defined(HAVE_B64)
87 * SWAP_B32_IN_B64 - swap 32 bits in 64 bits
89 * dest - pointer to where the swapped src wil be put
90 * src - pointer to a 64 bit value to swap
92 #define SWAP_B32_IN_B64(dest, src) ( \
93 *((USB64*)(dest)) = \
94 (((*((USB64*)(src))) << 32) | ((*((USB64*)(src))) >> 32)) \
98 * SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits
100 * dest - pointer to where the swapped src wil be put
101 * src - pointer to a 64 bit value to swap
103 #define SWAP_B16_IN_B64(dest, src) ( \
104 SWAP_B32_IN_B64(dest, src), \
105 (*((USB64*)(dest)) = \
106 ((((*((USB64*)(dest))) & (USB64)0xffff0000ffff0000) >> 16) | \
107 (((*((USB64*)(dest))) & (USB64)0x0000ffff0000ffff) << 16))) \
111 * SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits
113 * dest - pointer to where the swapped src wil be put
114 * src - pointer to a 64 bit value to swap
116 * This macro will either switch to the opposite byte sex (Big Endian vs.
117 * Little Endian) a 64 bit value.
119 #define SWAP_B8_IN_B64(dest, src) ( \
120 SWAP_B16_IN_B64(dest, src), \
121 (*((USB64*)(dest)) = \
122 ((((*((USB64*)(dest))) & (USB64)0xff00ff00ff00ff00) >> 8) | \
123 (((*((USB64*)(dest))) & (USB64)0x00ff00ff00ff00ff) << 8))) \
126 #else /* HAVE_B64 */
129 * SWAP_B32_IN_B64 - swap 32 bits in 64 bits (simulated by 2 32 bit values)
131 * dest - pointer to where the swapped src wil be put
132 * src - pointer to a 64 bit value to swap
134 #define SWAP_B32_IN_B64(dest, src) ( \
135 ((USB32*)(dest))[1] = ((USB32*)(dest))[0], \
136 ((USB32*)(dest))[0] = ((USB32*)(dest))[1] \
140 * SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
142 * dest - pointer to where the swapped src wil be put
143 * src - pointer to a 64 bit value to swap
145 #define SWAP_B16_IN_B64(dest, src) ( \
146 SWAP_B16_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \
147 SWAP_B16_IN_B32(((USB32*)dest), ((USB32*)src)+1) \
151 * SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
153 * dest - pointer to where the swapped src wil be put
154 * src - pointer to a 64 bit value to swap
156 * This macro will either switch to the opposite byte sex (Big Endian vs.
157 * Little Endian) a 64 bit value.
159 #define SWAP_B8_IN_B64(dest, src) ( \
160 SWAP_B8_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \
161 SWAP_B8_IN_B32(((USB32*)dest), ((USB32*)src)+1) \
164 #endif /* HAVE_B64 */
166 #if LONG_BITS == 64
168 #define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B64(dest, src)
169 #define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B64(dest, src)
170 #define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B64(dest, src)
172 #else /* LONG_BITS == 64 */
174 #define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B32(dest, src)
175 #define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B32(dest, src)
176 #define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B32(dest, src)
178 #endif /* LONG_BITS == 64 */
181 #endif /* !__BYTESWAP_H__ */