home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 March / PCO3_97.ISO / filesbbs / os2 / lzo026.arj / LZO026.ZIP / lzo-0.26 / src / lzo_conf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-29  |  9.2 KB  |  323 lines

  1. /* lzo_conf.h -- main internal configuration file for the the LZO library
  2.  
  3.    This file is part of the LZO real-time data compression library.
  4.  
  5.    Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
  6.  
  7.    The LZO library is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU General Public License as
  9.    published by the Free Software Foundation; either version 2 of
  10.    the License, or (at your option) any later version.
  11.  
  12.    The LZO library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with the LZO library; see the file COPYING.
  19.    If not, write to the Free Software Foundation, Inc.,
  20.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  
  22.    Markus F.X.J. Oberhumer
  23.    markus.oberhumer@jk.uni-linz.ac.at
  24.  */
  25.  
  26.  
  27. /* WARNING: this file should *not* be used by applications. It is
  28.    part of the implementation of the library and is subject
  29.    to change.
  30.  */
  31.  
  32.  
  33. #ifndef __LZO_CONF_H
  34. #define __LZO_CONF_H
  35.  
  36. #ifndef __LZOCONF_H
  37. #  include <lzoconf.h>
  38. #endif
  39.  
  40.  
  41. /***********************************************************************
  42. // compiler and architecture specific defines
  43. ************************************************************************/
  44.  
  45. /* need Borland C 4.0 or above because of huge-pointer bugs */
  46. #if defined(__LZO_MSDOS16) && defined(__TURBOC__)
  47. #  if (__TURBOC__ < 0x452)
  48. #    error You need a newer compiler version
  49. #  endif
  50. #endif
  51.  
  52. #if defined(__LZO_MSDOS) || defined(__i386__) || defined(__386__)
  53. #  if !defined(__LZO_i386)
  54. #    define __LZO_i386
  55. #  endif
  56. #endif
  57.  
  58.  
  59. /***********************************************************************
  60. // autoconf section
  61. ************************************************************************/
  62.  
  63. #if !defined(LZO_HAVE_CONFIG_AC)
  64. #  include <stddef.h>            /* ptrdiff_t, size_t */
  65. #  include <string.h>            /* memcpy, memmove, memcmp, memset */
  66. #  include <stdlib.h>
  67. #else
  68. #  include <sys/types.h>
  69. #  if defined(STDC_HEADERS)
  70. #    include <string.h>
  71. #    include <stdlib.h>
  72. #  endif
  73. #  if defined(HAVE_STDDEF_H)
  74. #    include <stddef.h>
  75. #  endif
  76. #  if defined(HAVE_MEMORY_H)
  77. #    include <memory.h>
  78. #  endif
  79. #endif
  80.  
  81. #if defined(LZO_DEBUG)
  82. #  include <stdio.h>
  83. #endif
  84.  
  85. #if defined(__BOUNDS_CHECKING_ON)
  86. #  include <unchecked.h>
  87. #else
  88. #  define BOUNDS_CHECKING_OFF_DURING(stmt)        stmt
  89. #  define BOUNDS_CHECKING_OFF_IN_EXPR(expr)        (expr)
  90. #endif
  91.  
  92.  
  93. #ifdef __cplusplus
  94. #  define LZO_UNUSED(parm)
  95. #else
  96. #  define LZO_UNUSED(parm)    parm
  97. #endif
  98.  
  99.  
  100. #if !defined(__inline__) && !defined(__GNUC__)
  101. #  if defined(__cplusplus)
  102. #    define __inline__        inline
  103. #  else
  104. #    define __inline__        /* nothing */
  105. #  endif
  106. #endif
  107.  
  108.  
  109. /***********************************************************************
  110. //
  111. ************************************************************************/
  112.  
  113. /* ptrdiff_t */
  114. #if (UINT_MAX >= 0xffffffffL)
  115.    typedef ptrdiff_t        lzo_ptrdiff_t;
  116. #else
  117.    typedef long             lzo_ptrdiff_t;
  118. #endif
  119.  
  120.  
  121. /* Unsigned type that has *exactly* the same number of bits as a lzo_voidp */
  122. #if defined(LZO_HAVE_CONFIG_AC)
  123. #  if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
  124.      typedef unsigned long  lzo_void_ptr_t;
  125.      typedef long           lzo_void_sptr_t;
  126. #  elif (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
  127.      typedef unsigned int   lzo_void_ptr_t;
  128.      typedef int            lzo_void_sptr_t;
  129. #  elif (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
  130.      typedef unsigned short lzo_void_ptr_t;
  131.      typedef short          lzo_void_sptr_t;
  132. #  else
  133. #    error no suitable type for lzo_void_ptr_t
  134. #  endif
  135. #else
  136.    typedef lzo_ptr_t        lzo_void_ptr_t;
  137.    typedef lzo_sptr_t       lzo_void_sptr_t;
  138. #endif
  139.  
  140.  
  141. /* We always use the safe version for pointer-comparisions.
  142.  * The compiler should optimize away the additional casts anyway.
  143.  * Borland C doesn't like this, though.
  144.  */
  145. #if !defined(__LZO_MSDOS16)
  146. #  if !defined(LZO_SAFE_POINTERS)
  147. #    define LZO_SAFE_POINTERS
  148. #  endif
  149. #endif
  150.  
  151.  
  152. /***********************************************************************
  153. // compiler and architecture specific stuff
  154. ************************************************************************/
  155.  
  156. /* Some defines that indicate if memory can be accessed at unaligned
  157.  * memory addresses. You should also test that this is actually faster
  158.  * even if it is allowed by your system.
  159.  */
  160.  
  161. #if 1 && defined(__LZO_i386)
  162. #  if !defined(LZO_UNALIGNED_OK_2)
  163. #    define LZO_UNALIGNED_OK_2
  164. #  endif
  165. #  if !defined(LZO_UNALIGNED_OK_4)
  166. #    define LZO_UNALIGNED_OK_4
  167. #  endif
  168. #endif
  169.  
  170. #if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4)
  171. #  if !defined(LZO_UNALIGNED_OK)
  172. #    define LZO_UNALIGNED_OK
  173. #  endif
  174. #endif
  175.  
  176.  
  177. /* Definitions for byte order, according to significance of bytes, from low
  178.  * addresses to high addresses. The value is what you get by putting '4'
  179.  * in the most significant byte, '3' in the second most significant byte,
  180.  * '2' in the second least significant byte, and '1' in the least
  181.  * significant byte.
  182.  */
  183.  
  184. #define    LZO_LITTLE_ENDIAN        1234
  185. #define    LZO_BIG_ENDIAN            4321
  186. #define    LZO_PDP_ENDIAN            3412
  187.  
  188. /* The byte order is only needed if we use LZO_UNALIGNED_OK */
  189. #if !defined(LZO_BYTE_ORDER)
  190. #  if defined(MFX_BYTE_ORDER)
  191. #    define LZO_BYTE_ORDER        MFX_BYTE_ORDER
  192. #  elif defined(__LZO_i386)
  193. #    define LZO_BYTE_ORDER        LZO_LITTLE_ENDIAN
  194. #  elif defined(BYTE_ORDER)
  195. #    define LZO_BYTE_ORDER        BYTE_ORDER
  196. #  elif defined(__BYTE_ORDER)
  197. #    define LZO_BYTE_ORDER        __BYTE_ORDER
  198. #  endif
  199. #endif
  200.  
  201. #if defined(LZO_BYTE_ORDER)
  202. #  if (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \
  203.       (LZO_BYTE_ORDER != LZO_BIG_ENDIAN)
  204. #    error invalid LZO_BYTE_ORDER
  205. #  endif
  206. #endif
  207.  
  208. #if defined(LZO_UNALIGNED_OK) && !defined(LZO_BYTE_ORDER)
  209. #  error LZO_BYTE_ORDER is not defined
  210. #endif
  211.  
  212.  
  213. /***********************************************************************
  214. // optimization
  215. ************************************************************************/
  216.  
  217. /* gcc 2.6.3 and gcc 2.7.2 have a bug with 'register xxx __asm__("%yyy")' */
  218. #define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY
  219.  
  220. /* Help the gcc optimizer with register allocation. */
  221. #if defined(NDEBUG) && !defined(LZO_DEBUG) && !defined(__BOUNDS_CHECKING_ON)
  222. #  if defined(__GNUC__) && defined(__i386__)
  223. #    if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY)
  224. #      define LZO_OPTIMIZE_GNUC_i386
  225. #    endif
  226. #  endif
  227. #endif
  228.  
  229.  
  230. /***********************************************************************
  231. //
  232. ************************************************************************/
  233.  
  234. #define LZO_BYTE(x)            ((unsigned char) (x))
  235. #define LZO_USHORT(x)        ((unsigned short) (x))
  236.  
  237. #define LZO_MAX(a,b)        ((a) >= (b) ? (a) : (b))
  238. #define LZO_MIN(a,b)        ((a) <= (b) ? (a) : (b))
  239.  
  240. #define lzo_sizeof(x)        ((lzo_uint) (sizeof(x)))
  241.  
  242. #define LZO_HIGH(x)            ((lzo_uint) (sizeof(x)/sizeof(*(x))))
  243.  
  244. /* this always fits into 16 bits */
  245. #define LZO_SIZE(bits)        (1u << (bits))
  246. #define LZO_MASK(bits)        (LZO_SIZE(bits) - 1)
  247.  
  248. #define LZO_LSIZE(bits)        (1ul << (bits))
  249. #define LZO_LMASK(bits)        (LZO_LSIZE(bits) - 1)
  250.  
  251. #define LZO_USIZE(bits)        ((lzo_uint) 1 << (bits))
  252. #define LZO_UMASK(bits)        (LZO_USIZE(bits) - 1)
  253.  
  254.  
  255. /***********************************************************************
  256. // ANSI C preprocessor macros
  257. ************************************************************************/
  258.  
  259. #define _LZO_STRINGIZE(x)            #x
  260. #define _LZO_MEXPAND(x)                _LZO_STRINGIZE(x)
  261.  
  262. /* concatenate */
  263. #define _LZO_CONCAT2(a,b)            a ## b
  264. #define _LZO_CONCAT3(a,b,c)            a ## b ## c
  265. #define _LZO_CONCAT4(a,b,c,d)        a ## b ## c ## d
  266. #define _LZO_CONCAT5(a,b,c,d,e)        a ## b ## c ## d ## e
  267.  
  268. /* expand and concatenate (by using one level of indirection) */
  269. #define _LZO_ECONCAT2(a,b)            _LZO_CONCAT2(a,b)
  270. #define _LZO_ECONCAT3(a,b,c)        _LZO_CONCAT3(a,b,c)
  271. #define _LZO_ECONCAT4(a,b,c,d)        _LZO_CONCAT4(a,b,c,d)
  272. #define _LZO_ECONCAT5(a,b,c,d,e)    _LZO_CONCAT5(a,b,c,d,e)
  273.  
  274.  
  275. /***********************************************************************
  276. //
  277. ************************************************************************/
  278.  
  279. /* Generate compressed data in a deterministic way.
  280.  * This is fully portable, and compression can be faster as well.
  281.  * A reason NOT to be deterministic is when the block size is
  282.  * very small (e.g. 8kB) or the dictionary is big, because
  283.  * then the initialization of the dictionary becomes a relevant
  284.  * magnitude for compression speed.
  285.  */
  286. #define LZO_DETERMINISTIC
  287.  
  288.  
  289. /***********************************************************************
  290. //
  291. ************************************************************************/
  292.  
  293. #if defined(LZO_SAFE_POINTERS)
  294. #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
  295.         (m_pos == NULL || (m_off = ip - m_pos) > max_offset)
  296. #else
  297. #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
  298.     (BOUNDS_CHECKING_OFF_IN_EXPR( \
  299.         (m_off = ip - m_pos) > max_offset ))
  300. #endif
  301.  
  302. /* m_pos may point anywhere... */
  303. #if defined(LZO_SAFE_POINTERS)
  304. #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
  305.     (BOUNDS_CHECKING_OFF_IN_EXPR( \
  306.         ((lzo_void_ptr_t) m_pos < (lzo_void_ptr_t) in || \
  307.          (m_off = (lzo_void_ptr_t) ip - (lzo_void_ptr_t) m_pos) <= 0 || \
  308.           m_off > max_offset) ))
  309. #else
  310. #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
  311.     (BOUNDS_CHECKING_OFF_IN_EXPR( \
  312.         (m_pos < in || (m_off = ip - m_pos) <= 0 || m_off > max_offset) ))
  313. #endif
  314.  
  315.  
  316.  
  317. #endif /* already included */
  318.  
  319. /*
  320. vi:ts=4
  321. */
  322.  
  323.