annotate ezBAMQC/src/htslib/cram/os.h @ 17:161866cee2a2

wrapper rename
author youngkim
date Wed, 30 Mar 2016 13:28:47 -0400
parents dfa3745e5fd8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
1 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
2 Copyright (c) 1993, 1995-2002 MEDICAL RESEARCH COUNCIL
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
3 All rights reserved
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
4
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
6 modification, are permitted provided that the following conditions are met:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
7
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
8 1 Redistributions of source code must retain the above copyright notice,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
9 this list of conditions and the following disclaimer.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
10
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
11 2 Redistributions in binary form must reproduce the above copyright notice,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
12 this list of conditions and the following disclaimer in the documentation
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
13 and/or other materials provided with the distribution.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
14
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
15 3 Neither the name of the MEDICAL RESEARCH COUNCIL, THE LABORATORY OF
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
16 MOLECULAR BIOLOGY nor the names of its contributors may be used to endorse or
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
17 promote products derived from this software without specific prior written
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
18 permission.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
19
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
30 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
31
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
32 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
33 Copyright (c) 2004, 2006, 2009-2011, 2013 Genome Research Ltd.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
34 Author: James Bonfield <jkb@sanger.ac.uk>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
35
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
36 Redistribution and use in source and binary forms, with or without
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
37 modification, are permitted provided that the following conditions are met:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
38
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
39 1. Redistributions of source code must retain the above copyright notice,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
40 this list of conditions and the following disclaimer.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
41
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
42 2. Redistributions in binary form must reproduce the above copyright notice,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
43 this list of conditions and the following disclaimer in the documentation
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
44 and/or other materials provided with the distribution.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
45
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
46 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
47 Institute nor the names of its contributors may be used to endorse or promote
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
48 products derived from this software without specific prior written permission.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
49
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
50 THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS IS" AND
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
51 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
52 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
53 DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH LTD OR CONTRIBUTORS BE LIABLE
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
54 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
55 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
56 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
57 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
58 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
59 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
60 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
61
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
62 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
63 * File: os.h
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
64 *
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
65 * Author:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
66 * MRC Laboratory of Molecular Biology
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
67 * Hills Road
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
68 * Cambridge CB2 2QH
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
69 * United Kingdom
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
70 *
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
71 * Description: operating system specific type definitions
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
72 *
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
73 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
74
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
75 #ifndef _OS_H_
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
76 #define _OS_H_
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
77
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
78 #include <limits.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
79 #include <inttypes.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
80
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
81 #ifdef __cplusplus
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
82 extern "C" {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
83 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
84
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
85 /*-----------------------------------------------------------------------------
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
86 * Detection of endianness. The main part of this is done in autoconf, but
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
87 * for the case of MacOS FAT binaries we fall back on auto-sensing based on
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
88 * processor type too.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
89 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
90
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
91 /* Set by autoconf */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
92 #define SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
93
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
94 /* Mac FAT binaries or unknown. Auto detect based on CPU type */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
95 #if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
96
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
97 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
98 * x86 equivalents
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
99 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
100 #if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
101 # if defined(SP_BIG_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
102 # undef SP_BIG_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
103 # endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
104 # define SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
105 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
106
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
107 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
108 * DEC Alpha
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
109 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
110 #if defined(__alpha__) || defined(__alpha)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
111 # if defined(SP_LITTLE_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
112 # undef SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
113 # endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
114 # define SP_BIG_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
115 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
116
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
117 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
118 * SUN Sparc
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
119 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
120 #if defined(__sparc__) || defined(__sparc)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
121 # if defined(SP_LITTLE_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
122 # undef SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
123 # endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
124 # define SP_BIG_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
125 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
126
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
127 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
128 * PowerPC
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
129 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
130 #if defined(__ppc__) || defined(__ppc)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
131 # if defined(SP_LITTLE_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
132 # undef SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
133 # endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
134 # define SP_BIG_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
135 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
136
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
137 /* Some catch-alls */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
138 #if defined(__LITTLE_ENDIAN__) || defined(__LITTLEENDIAN__)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
139 # define SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
140 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
141
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
142 #if defined(__BIG_ENDIAN__) || defined(__BIGENDIAN__)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
143 # define SP_BIG_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
144 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
145
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
146 #if defined(SP_BIG_ENDIAN) && defined(SP_LITTLE_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
147 # error Both BIG and LITTLE endian defined. Fix os.h and/or Makefile
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
148 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
149
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
150 #if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
151 # error Neither BIG nor LITTLE endian defined. Fix os.h and/or Makefile
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
152 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
153
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
154 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
155
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
156 /*-----------------------------------------------------------------------------
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
157 * Allow for unaligned memory access. This is used in BAM code as the packed
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
158 * structure has 4-byte cigar ints after the variable length name.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
159 *
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
160 * Consider using AX_CHECK_ALIGNED_ACCESS_REQUIRED in autoconf.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
161 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
162 #if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
163 # define ALLOW_UAC
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
164 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
165
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
166 /*-----------------------------------------------------------------------------
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
167 * Byte swapping macros
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
168 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
169
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
170 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
171 * Our new swap runs at the same speed on Ultrix, but substantially faster
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
172 * (300% for swap_int4, ~50% for swap_int2) on an Alpha (due to the lack of
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
173 * decent 'char' support).
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
174 *
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
175 * They also have the ability to swap in situ (src == dst). Newer code now
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
176 * relies on this so don't change back!
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
177 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
178 #define iswap_int8(x) \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
179 (((x & 0x00000000000000ffLL) << 56) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
180 ((x & 0x000000000000ff00LL) << 40) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
181 ((x & 0x0000000000ff0000LL) << 24) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
182 ((x & 0x00000000ff000000LL) << 8) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
183 ((x & 0x000000ff00000000LL) >> 8) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
184 ((x & 0x0000ff0000000000LL) >> 24) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
185 ((x & 0x00ff000000000000LL) >> 40) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
186 ((x & 0xff00000000000000LL) >> 56))
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
187
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
188 #define iswap_int4(x) \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
189 (((x & 0x000000ff) << 24) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
190 ((x & 0x0000ff00) << 8) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
191 ((x & 0x00ff0000) >> 8) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
192 ((x & 0xff000000) >> 24))
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
193
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
194 #define iswap_int2(x) \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
195 (((x & 0x00ff) << 8) + \
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
196 ((x & 0xff00) >> 8))
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
197
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
198 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
199 * Linux systems may use byteswap.h to get assembly versions of byte-swap
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
200 * on intel systems. This can be as trivial as the bswap opcode, which works
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
201 * out at over 2-times faster than iswap_int4 above.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
202 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
203 #if 0
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
204 #if defined(__linux__)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
205 # include <byteswap.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
206 # undef iswap_int8
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
207 # undef iswap_int4
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
208 # undef iswap_int2
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
209 # define iswap_int8 bswap_64
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
210 # define iswap_int4 bswap_32
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
211 # define iswap_int2 bswap_16
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
212 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
213 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
214
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
215
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
216 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
217 * Macros to specify that data read in is of a particular endianness.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
218 * The macros here swap to the appropriate order for the particular machine
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
219 * running the macro and return the new answer. These may also be used when
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
220 * writing to a file to specify that we wish to write in (eg) big endian
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
221 * format.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
222 *
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
223 * This leads to efficient code as most of the time these macros are
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
224 * trivial.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
225 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
226 #ifdef SP_BIG_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
227 #define le_int4(x) iswap_int4((x))
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
228 #define le_int2(x) iswap_int2((x))
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
229 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
230
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
231 #ifdef SP_LITTLE_ENDIAN
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
232 #define le_int4(x) (x)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
233 #define le_int2(x) (x)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
234 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
235
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
236 /*-----------------------------------------------------------------------------
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
237 * <inttypes.h> definitions, incase they're not present
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
238 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
239
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
240 #ifndef PRId64
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
241 #define __PRI64__ "l"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
242 #define PRId64 __PRI64__ "d"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
243 #define PRId32 "d"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
244 #define PRId16 "d"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
245 #define PRId8 "d"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
246 #define PRIu64 __PRI64__ "u"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
247 #define PRIu32 "u"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
248 #define PRIu16 "u"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
249 #define PRIu8 "u"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
250 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
251
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
252 /*-----------------------------------------------------------------------------
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
253 * Operating system specifics.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
254 * These ought to be done by autoconf, but are legacy code.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
255 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
256 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
257 * SunOS 4.x
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
258 * Even though we use the ANSI gcc, we make use the the standard SunOS 4.x
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
259 * libraries and include files, which are non-ansi
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
260 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
261 #if defined(__sun__) && !defined(__svr4__)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
262 #define SEEK_SET 0
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
263 #define SEEK_CUR 1
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
264 #define SEEK_END 2
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
265 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
266
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
267 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
268 * Microsoft Visual C++
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
269 * Windows
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
270 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
271 #if defined(_MSC_VER)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
272 #define popen _popen
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
273 #define pclose _pclose
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
274 #define ftruncate(fd,len) _chsize(fd,len)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
275 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
276
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
277
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
278 /*
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
279 * Microsoft Windows running MinGW
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
280 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
281 #if defined(__MINGW32__)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
282 /* #define mkdir(filename,mode) mkdir((filename)) */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
283 #define sysconf(x) 512
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
284 #define ftruncate(fd,len) _chsize(fd,len)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
285 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
286
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
287 /* Generic WIN32 API issues */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
288 #ifdef _WIN32
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
289 # ifndef HAVE_FSEEKO
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
290 # if __MSVCRT_VERSION__ >= 0x800
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
291 /* if you have MSVCR80 installed then you can use these definitions: */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
292 # define off_t __int64
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
293 # define fseeko _fseeki64
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
294 # define ftello _ftelli64
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
295 # else
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
296 /* otherwise we're stuck with 32-bit file support */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
297 # define off_t long
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
298 # define fseeko fseek
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
299 # define ftello ftell
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
300 # endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
301 # endif /* !HAVE_FSEEKO */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
302 #endif /* _WIN32 */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
303
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
304 #ifdef __cplusplus
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
305 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
306 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
307
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
308 #endif /*_OS_H_*/