ucl_conf.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /* ucl_conf.h -- main internal configuration file for the the UCL library
  2. This file is part of the UCL data compression library.
  3. Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The UCL library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The UCL library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with the UCL library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. */
  20. /* WARNING: this file should *not* be used by applications. It is
  21. part of the implementation of the library and is subject
  22. to change.
  23. */
  24. #ifndef __UCL_CONF_H
  25. #define __UCL_CONF_H
  26. #if !defined(__UCL_IN_MINIUCL)
  27. # ifndef __UCLCONF_H
  28. # include "uclconf.h"
  29. # endif
  30. #endif
  31. /***********************************************************************
  32. // memory checkers
  33. ************************************************************************/
  34. #if defined(__BOUNDS_CHECKING_ON)
  35. # include <unchecked.h>
  36. #else
  37. # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
  38. # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
  39. #endif
  40. /***********************************************************************
  41. // autoconf section
  42. ************************************************************************/
  43. #if !defined(UCL_HAVE_CONFIG_H)
  44. # include <stddef.h> /* ptrdiff_t, size_t */
  45. # include <string.h> /* memcpy, memmove, memcmp, memset */
  46. # if !defined(NO_STDLIB_H)
  47. # include <stdlib.h>
  48. # endif
  49. # define HAVE_MEMCMP
  50. # define HAVE_MEMCPY
  51. # define HAVE_MEMMOVE
  52. # define HAVE_MEMSET
  53. #else
  54. # include <sys/types.h>
  55. # if defined(STDC_HEADERS)
  56. # include <string.h>
  57. # include <stdlib.h>
  58. # endif
  59. # if defined(HAVE_STDDEF_H)
  60. # include <stddef.h>
  61. # endif
  62. # if defined(HAVE_MEMORY_H)
  63. # include <memory.h>
  64. # endif
  65. #endif
  66. #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
  67. # define HAVE_MALLOC_H
  68. # define HAVE_HALLOC
  69. #endif
  70. #undef NDEBUG
  71. #if !defined(UCL_DEBUG)
  72. # define NDEBUG
  73. #endif
  74. #if 1 || defined(UCL_DEBUG) || !defined(NDEBUG)
  75. # if !defined(NO_STDIO_H)
  76. # include <stdio.h>
  77. # endif
  78. #endif
  79. #include <assert.h>
  80. #if !defined(UCL_UNUSED)
  81. # define UCL_UNUSED(parm) (parm = parm)
  82. #endif
  83. #if !defined(__inline__) && !defined(__GNUC__)
  84. # if defined(__cplusplus)
  85. # define __inline__ inline
  86. # else
  87. # define __inline__ /* nothing */
  88. # endif
  89. #endif
  90. /***********************************************************************
  91. //
  92. ************************************************************************/
  93. #if 1
  94. # define UCL_BYTE(x) ((unsigned char) (x))
  95. #else
  96. # define UCL_BYTE(x) ((unsigned char) ((x) & 0xff))
  97. #endif
  98. #if 0
  99. # define UCL_USHORT(x) ((unsigned short) (x))
  100. #else
  101. # define UCL_USHORT(x) ((unsigned short) ((x) & 0xffff))
  102. #endif
  103. #define UCL_MAX(a,b) ((a) >= (b) ? (a) : (b))
  104. #define UCL_MIN(a,b) ((a) <= (b) ? (a) : (b))
  105. #define UCL_MAX3(a,b,c) ((a) >= (b) ? UCL_MAX(a,c) : UCL_MAX(b,c))
  106. #define UCL_MIN3(a,b,c) ((a) <= (b) ? UCL_MIN(a,c) : UCL_MIN(b,c))
  107. #define ucl_sizeof(type) ((ucl_uint) (sizeof(type)))
  108. #define UCL_HIGH(array) ((ucl_uint) (sizeof(array)/sizeof(*(array))))
  109. /* this always fits into 16 bits */
  110. #define UCL_SIZE(bits) (1u << (bits))
  111. #define UCL_MASK(bits) (UCL_SIZE(bits) - 1)
  112. #define UCL_LSIZE(bits) (1ul << (bits))
  113. #define UCL_LMASK(bits) (UCL_LSIZE(bits) - 1)
  114. #define UCL_USIZE(bits) ((ucl_uint) 1 << (bits))
  115. #define UCL_UMASK(bits) (UCL_USIZE(bits) - 1)
  116. /* Maximum value of a signed/unsigned type.
  117. Do not use casts, avoid overflows ! */
  118. #define UCL_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2)))
  119. #define UCL_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1)))
  120. /***********************************************************************
  121. //
  122. ************************************************************************/
  123. #if !defined(SIZEOF_UNSIGNED)
  124. # if (UINT_MAX == 0xffff)
  125. # define SIZEOF_UNSIGNED 2
  126. # elif (UINT_MAX == UCL_0xffffffffL)
  127. # define SIZEOF_UNSIGNED 4
  128. # elif (UINT_MAX >= UCL_0xffffffffL)
  129. # define SIZEOF_UNSIGNED 8
  130. # else
  131. # error "SIZEOF_UNSIGNED"
  132. # endif
  133. #endif
  134. #if !defined(SIZEOF_UNSIGNED_LONG)
  135. # if (ULONG_MAX == UCL_0xffffffffL)
  136. # define SIZEOF_UNSIGNED_LONG 4
  137. # elif (ULONG_MAX >= UCL_0xffffffffL)
  138. # define SIZEOF_UNSIGNED_LONG 8
  139. # else
  140. # error "SIZEOF_UNSIGNED_LONG"
  141. # endif
  142. #endif
  143. #if !defined(SIZEOF_SIZE_T)
  144. # define SIZEOF_SIZE_T SIZEOF_UNSIGNED
  145. #endif
  146. #if !defined(SIZE_T_MAX)
  147. # define SIZE_T_MAX UCL_UTYPE_MAX(SIZEOF_SIZE_T)
  148. #endif
  149. /***********************************************************************
  150. // <string.h> section
  151. ************************************************************************/
  152. #if defined(NO_MEMCMP)
  153. # undef HAVE_MEMCMP
  154. #endif
  155. #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCMP)
  156. # define ucl_memcmp memcmp
  157. #endif
  158. #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCPY)
  159. # define ucl_memcpy memcpy
  160. #endif
  161. #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMMOVE)
  162. # define ucl_memmove memmove
  163. #endif
  164. #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
  165. # define ucl_memset memset
  166. #endif
  167. #if !defined(HAVE_MEMCMP)
  168. # undef memcmp
  169. # define memcmp ucl_memcmp
  170. #endif
  171. #if !defined(HAVE_MEMCPY)
  172. # undef memcpy
  173. # define memcpy ucl_memcpy
  174. #endif
  175. #if !defined(HAVE_MEMMOVE)
  176. # undef memmove
  177. # define memmove ucl_memmove
  178. #endif
  179. #if !defined(HAVE_MEMSET)
  180. # undef memset
  181. # define memset ucl_memset
  182. #endif
  183. /***********************************************************************
  184. // compiler and architecture specific stuff
  185. ************************************************************************/
  186. /* Some defines that indicate if memory can be accessed at unaligned
  187. * memory addresses. You should also test that this is actually faster
  188. * even if it is allowed by your system.
  189. */
  190. #if 1 && defined(__UCL_i386) && (UINT_MAX == UCL_0xffffffffL)
  191. # if !defined(UCL_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff)
  192. # define UCL_UNALIGNED_OK_2
  193. # endif
  194. # if !defined(UCL_UNALIGNED_OK_4) && (UCL_UINT32_MAX == UCL_0xffffffffL)
  195. # define UCL_UNALIGNED_OK_4
  196. # endif
  197. #endif
  198. #if defined(UCL_UNALIGNED_OK_2) || defined(UCL_UNALIGNED_OK_4)
  199. # if !defined(UCL_UNALIGNED_OK)
  200. # define UCL_UNALIGNED_OK
  201. # endif
  202. #endif
  203. #if defined(__UCL_NO_UNALIGNED)
  204. # undef UCL_UNALIGNED_OK
  205. # undef UCL_UNALIGNED_OK_2
  206. # undef UCL_UNALIGNED_OK_4
  207. #endif
  208. #if defined(UCL_UNALIGNED_OK_2) && (USHRT_MAX != 0xffff)
  209. # error "UCL_UNALIGNED_OK_2 must not be defined on this system"
  210. #endif
  211. #if defined(UCL_UNALIGNED_OK_4) && (UCL_UINT32_MAX != UCL_0xffffffffL)
  212. # error "UCL_UNALIGNED_OK_4 must not be defined on this system"
  213. #endif
  214. /* Many modern processors can transfer 32bit words much faster than
  215. * bytes - this can significantly speed decompression.
  216. */
  217. #if defined(__UCL_NO_ALIGNED)
  218. # undef UCL_ALIGNED_OK_4
  219. #endif
  220. #if defined(UCL_ALIGNED_OK_4) && (UCL_UINT32_MAX != UCL_0xffffffffL)
  221. # error "UCL_ALIGNED_OK_4 must not be defined on this system"
  222. #endif
  223. /* Definitions for byte order, according to significance of bytes, from low
  224. * addresses to high addresses. The value is what you get by putting '4'
  225. * in the most significant byte, '3' in the second most significant byte,
  226. * '2' in the second least significant byte, and '1' in the least
  227. * significant byte.
  228. * The byte order is only needed if we use UCL_UNALIGNED_OK.
  229. */
  230. #define UCL_LITTLE_ENDIAN 1234
  231. #define UCL_BIG_ENDIAN 4321
  232. #define UCL_PDP_ENDIAN 3412
  233. #if !defined(UCL_BYTE_ORDER)
  234. # if defined(MFX_BYTE_ORDER)
  235. # define UCL_BYTE_ORDER MFX_BYTE_ORDER
  236. # elif defined(__UCL_i386)
  237. # define UCL_BYTE_ORDER UCL_LITTLE_ENDIAN
  238. # elif defined(BYTE_ORDER)
  239. # define UCL_BYTE_ORDER BYTE_ORDER
  240. # elif defined(__BYTE_ORDER)
  241. # define UCL_BYTE_ORDER __BYTE_ORDER
  242. # endif
  243. #endif
  244. #if defined(UCL_BYTE_ORDER)
  245. # if (UCL_BYTE_ORDER != UCL_LITTLE_ENDIAN) && \
  246. (UCL_BYTE_ORDER != UCL_BIG_ENDIAN)
  247. # error "invalid UCL_BYTE_ORDER"
  248. # endif
  249. #endif
  250. #if defined(UCL_UNALIGNED_OK) && !defined(UCL_BYTE_ORDER)
  251. # error "UCL_BYTE_ORDER is not defined"
  252. #endif
  253. /***********************************************************************
  254. // some globals
  255. ************************************************************************/
  256. __UCL_EXTERN_C int __ucl_init_done;
  257. __UCL_EXTERN_C const ucl_byte __ucl_copyright[];
  258. UCL_EXTERN(const ucl_byte *) ucl_copyright(void);
  259. __UCL_EXTERN_C const ucl_uint32 _ucl_crc32_table[256];
  260. /***********************************************************************
  261. // ANSI C preprocessor macros
  262. ************************************************************************/
  263. #define _UCL_STRINGIZE(x) #x
  264. #define _UCL_MEXPAND(x) _UCL_STRINGIZE(x)
  265. /* concatenate */
  266. #define _UCL_CONCAT2(a,b) a ## b
  267. #define _UCL_CONCAT3(a,b,c) a ## b ## c
  268. #define _UCL_CONCAT4(a,b,c,d) a ## b ## c ## d
  269. #define _UCL_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
  270. /* expand and concatenate (by using one level of indirection) */
  271. #define _UCL_ECONCAT2(a,b) _UCL_CONCAT2(a,b)
  272. #define _UCL_ECONCAT3(a,b,c) _UCL_CONCAT3(a,b,c)
  273. #define _UCL_ECONCAT4(a,b,c,d) _UCL_CONCAT4(a,b,c,d)
  274. #define _UCL_ECONCAT5(a,b,c,d,e) _UCL_CONCAT5(a,b,c,d,e)
  275. /***********************************************************************
  276. //
  277. ************************************************************************/
  278. #include "ucl_ptr.h"
  279. #endif /* already included */
  280. /*
  281. vi:ts=4:et
  282. */