1 /* ucl_conf.h -- main internal configuration file for the the UCL library
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
8 The UCL library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The UCL library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the UCL library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
28 /* WARNING: this file should *not* be used by applications. It is
29 part of the implementation of the library and is subject
37 #if !defined(__UCL_IN_MINIUCL)
39 # include <ucl/uclconf.h>
44 /***********************************************************************
46 ************************************************************************/
48 #if defined(__BOUNDS_CHECKING_ON)
49 # include <unchecked.h>
51 # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
52 # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
56 /***********************************************************************
58 ************************************************************************/
60 #if !defined(UCL_HAVE_CONFIG_H)
61 # include <stddef.h> /* ptrdiff_t, size_t */
62 # include <string.h> /* memcpy, memmove, memcmp, memset */
63 # if !defined(NO_STDLIB_H)
71 # include <sys/types.h>
72 # if defined(STDC_HEADERS)
76 # if defined(HAVE_STDDEF_H)
79 # if defined(HAVE_MEMORY_H)
84 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
85 # define HAVE_MALLOC_H
91 #if !defined(UCL_DEBUG)
94 #if 1 || defined(UCL_DEBUG) || !defined(NDEBUG)
95 # if !defined(NO_STDIO_H)
102 #if !defined(UCL_UNUSED)
103 # define UCL_UNUSED(parm) (parm = parm)
107 #if !defined(__inline__) && !defined(__GNUC__)
108 # if defined(__cplusplus)
109 # define __inline__ inline
111 # define __inline__ /* nothing */
116 /***********************************************************************
118 ************************************************************************/
121 # define UCL_BYTE(x) ((unsigned char) (x))
123 # define UCL_BYTE(x) ((unsigned char) ((x) & 0xff))
126 # define UCL_USHORT(x) ((unsigned short) (x))
128 # define UCL_USHORT(x) ((unsigned short) ((x) & 0xffff))
131 #define UCL_MAX(a,b) ((a) >= (b) ? (a) : (b))
132 #define UCL_MIN(a,b) ((a) <= (b) ? (a) : (b))
133 #define UCL_MAX3(a,b,c) ((a) >= (b) ? UCL_MAX(a,c) : UCL_MAX(b,c))
134 #define UCL_MIN3(a,b,c) ((a) <= (b) ? UCL_MIN(a,c) : UCL_MIN(b,c))
136 #define ucl_sizeof(type) ((ucl_uint) (sizeof(type)))
138 #define UCL_HIGH(array) ((ucl_uint) (sizeof(array)/sizeof(*(array))))
140 /* this always fits into 16 bits */
141 #define UCL_SIZE(bits) (1u << (bits))
142 #define UCL_MASK(bits) (UCL_SIZE(bits) - 1)
144 #define UCL_LSIZE(bits) (1ul << (bits))
145 #define UCL_LMASK(bits) (UCL_LSIZE(bits) - 1)
147 #define UCL_USIZE(bits) ((ucl_uint) 1 << (bits))
148 #define UCL_UMASK(bits) (UCL_USIZE(bits) - 1)
150 /* Maximum value of a signed/unsigned type.
151 Do not use casts, avoid overflows ! */
152 #define UCL_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2)))
153 #define UCL_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1)))
156 /***********************************************************************
158 ************************************************************************/
160 #if !defined(SIZEOF_UNSIGNED)
161 # if (UINT_MAX == 0xffff)
162 # define SIZEOF_UNSIGNED 2
163 # elif (UINT_MAX == UCL_0xffffffffL)
164 # define SIZEOF_UNSIGNED 4
165 # elif (UINT_MAX >= UCL_0xffffffffL)
166 # define SIZEOF_UNSIGNED 8
168 # error "SIZEOF_UNSIGNED"
172 #if !defined(SIZEOF_UNSIGNED_LONG)
173 # if (ULONG_MAX == UCL_0xffffffffL)
174 # define SIZEOF_UNSIGNED_LONG 4
175 # elif (ULONG_MAX >= UCL_0xffffffffL)
176 # define SIZEOF_UNSIGNED_LONG 8
178 # error "SIZEOF_UNSIGNED_LONG"
183 #if !defined(SIZEOF_SIZE_T)
184 # define SIZEOF_SIZE_T SIZEOF_UNSIGNED_LONG
186 #if !defined(SIZE_T_MAX)
187 # define SIZE_T_MAX UCL_UTYPE_MAX(SIZEOF_SIZE_T)
191 /***********************************************************************
192 // <string.h> section
193 ************************************************************************/
195 #if defined(NO_MEMCMP)
199 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCMP)
200 # define ucl_memcmp memcmp
202 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCPY)
203 # define ucl_memcpy memcpy
205 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMMOVE)
206 # define ucl_memmove memmove
208 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
209 # define ucl_memset memset
212 #if !defined(HAVE_MEMCMP)
214 # define memcmp ucl_memcmp
216 #if !defined(HAVE_MEMCPY)
218 # define memcpy ucl_memcpy
220 #if !defined(HAVE_MEMMOVE)
222 # define memmove ucl_memmove
224 #if !defined(HAVE_MEMSET)
226 # define memset ucl_memset
230 /***********************************************************************
231 // compiler and architecture specific stuff
232 ************************************************************************/
234 /* Some defines that indicate if memory can be accessed at unaligned
235 * memory addresses. You should also test that this is actually faster
236 * even if it is allowed by your system.
239 #if 1 && defined(__UCL_i386) && (UINT_MAX == UCL_0xffffffffL)
240 # if !defined(UCL_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff)
241 # define UCL_UNALIGNED_OK_2
243 # if !defined(UCL_UNALIGNED_OK_4) && (UCL_UINT32_MAX == UCL_0xffffffffL)
244 # define UCL_UNALIGNED_OK_4
248 #if defined(UCL_UNALIGNED_OK_2) || defined(UCL_UNALIGNED_OK_4)
249 # if !defined(UCL_UNALIGNED_OK)
250 # define UCL_UNALIGNED_OK
254 #if defined(__UCL_NO_UNALIGNED)
255 # undef UCL_UNALIGNED_OK
256 # undef UCL_UNALIGNED_OK_2
257 # undef UCL_UNALIGNED_OK_4
260 #if defined(UCL_UNALIGNED_OK_2) && (USHRT_MAX != 0xffff)
261 # error "UCL_UNALIGNED_OK_2 must not be defined on this system"
263 #if defined(UCL_UNALIGNED_OK_4) && (UCL_UINT32_MAX != UCL_0xffffffffL)
264 # error "UCL_UNALIGNED_OK_4 must not be defined on this system"
268 /* Many modern processors can transfer 32bit words much faster than
269 * bytes - this can significantly speed decompression.
272 #if defined(__UCL_NO_ALIGNED)
273 # undef UCL_ALIGNED_OK_4
276 #if defined(UCL_ALIGNED_OK_4) && (UCL_UINT32_MAX != UCL_0xffffffffL)
277 # error "UCL_ALIGNED_OK_4 must not be defined on this system"
281 /* Definitions for byte order, according to significance of bytes, from low
282 * addresses to high addresses. The value is what you get by putting '4'
283 * in the most significant byte, '3' in the second most significant byte,
284 * '2' in the second least significant byte, and '1' in the least
286 * The byte order is only needed if we use UCL_UNALIGNED_OK.
289 #define UCL_LITTLE_ENDIAN 1234
290 #define UCL_BIG_ENDIAN 4321
291 #define UCL_PDP_ENDIAN 3412
293 #if !defined(UCL_BYTE_ORDER)
294 # if defined(MFX_BYTE_ORDER)
295 # define UCL_BYTE_ORDER MFX_BYTE_ORDER
296 # elif defined(__UCL_i386)
297 # define UCL_BYTE_ORDER UCL_LITTLE_ENDIAN
298 # elif defined(BYTE_ORDER)
299 # define UCL_BYTE_ORDER BYTE_ORDER
300 # elif defined(__BYTE_ORDER)
301 # define UCL_BYTE_ORDER __BYTE_ORDER
305 #if defined(UCL_BYTE_ORDER)
306 # if (UCL_BYTE_ORDER != UCL_LITTLE_ENDIAN) && \
307 (UCL_BYTE_ORDER != UCL_BIG_ENDIAN)
308 # error "invalid UCL_BYTE_ORDER"
312 #if defined(UCL_UNALIGNED_OK) && !defined(UCL_BYTE_ORDER)
313 # error "UCL_BYTE_ORDER is not defined"
317 /***********************************************************************
319 ************************************************************************/
321 __UCL_EXTERN_C
int __ucl_init_done
;
322 __UCL_EXTERN_C
const ucl_byte __ucl_copyright
[];
323 UCL_EXTERN(const ucl_byte
*) ucl_copyright(void);
324 __UCL_EXTERN_C
const ucl_uint32 _ucl_crc32_table
[256];
327 /***********************************************************************
328 // ANSI C preprocessor macros
329 ************************************************************************/
331 #define _UCL_STRINGIZE(x) #x
332 #define _UCL_MEXPAND(x) _UCL_STRINGIZE(x)
335 #define _UCL_CONCAT2(a,b) a ## b
336 #define _UCL_CONCAT3(a,b,c) a ## b ## c
337 #define _UCL_CONCAT4(a,b,c,d) a ## b ## c ## d
338 #define _UCL_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
340 /* expand and concatenate (by using one level of indirection) */
341 #define _UCL_ECONCAT2(a,b) _UCL_CONCAT2(a,b)
342 #define _UCL_ECONCAT3(a,b,c) _UCL_CONCAT3(a,b,c)
343 #define _UCL_ECONCAT4(a,b,c,d) _UCL_CONCAT4(a,b,c,d)
344 #define _UCL_ECONCAT5(a,b,c,d,e) _UCL_CONCAT5(a,b,c,d,e)
347 /***********************************************************************
349 ************************************************************************/
354 #endif /* already included */