LZO_CONF.H 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* lzo_conf.h -- main internal configuration file for the the LZO library
  15. This file is part of the LZO real-time data compression library.
  16. Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
  17. The LZO library is free software; you can redistribute it and/or
  18. modify it under the terms of the GNU Library General Public
  19. License as published by the Free Software Foundation; either
  20. version 2 of the License, or (at your option) any later version.
  21. The LZO library is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Library General Public License for more details.
  25. You should have received a copy of the GNU Library General Public
  26. License along with the LZO library; see the file COPYING.LIB.
  27. If not, write to the Free Software Foundation, Inc.,
  28. 675 Mass Ave, Cambridge, MA 02139, USA.
  29. Markus F.X.J. Oberhumer
  30. [email protected]
  31. */
  32. /* WARNING: this file should *not* be used by applications. It is
  33. part of the implementation of the library and is subject
  34. to change.
  35. */
  36. #ifndef __LZO_CONF_H
  37. #define __LZO_CONF_H
  38. #ifndef __LZOCONF_H
  39. # include <lzoconf.h>
  40. #endif
  41. /***********************************************************************
  42. // compiler specific defines
  43. ************************************************************************/
  44. /* need Borland C 4.0 or above because of huge-pointer bugs */
  45. #if defined(__LZO_MSDOS16) && defined(__TURBOC__)
  46. # if (__TURBOC__ < 0x452)
  47. # error You need a newer compiler version
  48. # endif
  49. #endif
  50. #if defined(__LZO_MSDOS) || defined(__i386__) || defined(__386__)
  51. # if !defined(__LZO_i386)
  52. # define __LZO_i386
  53. # endif
  54. #endif
  55. /***********************************************************************
  56. //
  57. ************************************************************************/
  58. #include <stddef.h> /* ptrdiff_t, size_t */
  59. #include <string.h> /* memcpy, memmove, memcmp, memset */
  60. #if 0 && !defined(assert)
  61. # error <assert.h> not included
  62. #endif
  63. #if defined(__BOUNDS_CHECKING_ON)
  64. # include <unchecked.h>
  65. #else
  66. # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
  67. # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
  68. #endif
  69. /* ptrdiff_t */
  70. #if (UINT_MAX >= 0xffffffffL)
  71. typedef ptrdiff_t lzo_ptrdiff_t;
  72. #else
  73. typedef long lzo_ptrdiff_t;
  74. #endif
  75. #ifdef __cplusplus
  76. # define LZO_UNUSED(parm)
  77. #else
  78. # define LZO_UNUSED(parm) parm
  79. #endif
  80. #if !defined(__inline__) && !defined(__GNUC__)
  81. # if defined(__cplusplus)
  82. # define __inline__ inline
  83. # else
  84. # define __inline__ /* nothing */
  85. # endif
  86. #endif
  87. /***********************************************************************
  88. // compiler and architecture specific stuff
  89. ************************************************************************/
  90. /* Some defines that indicate if memory can be accessed at unaligned
  91. * addresses. You should also test that this is actually faster if
  92. * it is allowed by your system.
  93. */
  94. #if 1 && defined(__LZO_i386)
  95. # if !defined(LZO_UNALIGNED_OK_2)
  96. # define LZO_UNALIGNED_OK_2
  97. # endif
  98. # if !defined(LZO_UNALIGNED_OK_4)
  99. # define LZO_UNALIGNED_OK_4
  100. # endif
  101. #endif
  102. #if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4)
  103. # if !defined(LZO_UNALIGNED_OK)
  104. # define LZO_UNALIGNED_OK
  105. # endif
  106. #endif
  107. /* Definitions for byte order, according to significance of bytes, from low
  108. * addresses to high addresses. The value is what you get by putting '4'
  109. * in the most significant byte, '3' in the second most significant byte,
  110. * '2' in the second least significant byte, and '1' in the least
  111. * significant byte.
  112. */
  113. #define LZO_LITTLE_ENDIAN 1234
  114. #define LZO_BIG_ENDIAN 4321
  115. #define LZO_PDP_ENDIAN 3412
  116. /* The byte order is only needed if we use LZO_UNALIGNED_OK */
  117. #if !defined(LZO_BYTE_ORDER)
  118. # if defined(__LZO_i386)
  119. # define LZO_BYTE_ORDER LZO_LITTLE_ENDIAN
  120. # elif defined(__mc68000__)
  121. # define LZO_BYTE_ORDER LZO_BIG_ENDIAN
  122. # elif defined(__BYTE_ORDER)
  123. # define LZO_BYTE_ORDER __BYTE_ORDER
  124. # endif
  125. #endif
  126. #if defined(LZO_UNALIGNED_OK)
  127. # if !defined(LZO_BYTE_ORDER)
  128. # error LZO_BYTE_ORDER is not defined
  129. # elif (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \
  130. (LZO_BYTE_ORDER != LZO_BIG_ENDIAN)
  131. # error invalid LZO_BYTE_ORDER
  132. # endif
  133. #endif
  134. /***********************************************************************
  135. // optimization
  136. ************************************************************************/
  137. /* gcc 2.6.3 and gcc 2.7.2 have a bug */
  138. #define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY
  139. /* Help the optimizer with register allocation.
  140. * Don't activate this macro for a fair comparision with other algorithms.
  141. */
  142. #if 1 && defined(NDEBUG) && !defined(__BOUNDS_CHECKING_ON)
  143. # if defined(__GNUC__) && defined(__i386__)
  144. # if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY)
  145. # define LZO_OPTIMIZE_GNUC_i386
  146. # endif
  147. # endif
  148. #endif
  149. /***********************************************************************
  150. //
  151. ************************************************************************/
  152. #define LZO_BYTE(x) ((unsigned char) (x))
  153. #define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
  154. #define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
  155. #define lzo_sizeof(x) ((lzo_uint) (sizeof(x)))
  156. #define LZO_HIGH(x) ((lzo_uint) (sizeof(x)/sizeof(*(x))))
  157. /* this always fits into 16 bits */
  158. #define LZO_SIZE(bits) (1u << (bits))
  159. #define LZO_MASK(bits) (LZO_SIZE(bits) - 1)
  160. #define LZO_LSIZE(bits) (1ul << (bits))
  161. #define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1)
  162. #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits))
  163. #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1)
  164. /***********************************************************************
  165. // ANSI C preprocessor macros
  166. ************************************************************************/
  167. #define _LZO_STRINGIZE(x) #x
  168. #define _LZO_MEXPAND(x) _LZO_STRINGIZE(x)
  169. /* concatenate */
  170. #define _LZO_CONCAT2(a,b) a ## b
  171. #define _LZO_CONCAT3(a,b,c) a ## b ## c
  172. #define _LZO_CONCAT4(a,b,c,d) a ## b ## c ## d
  173. #define _LZO_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
  174. /* expand and concatenate (by using one level of indirection) */
  175. #define _LZO_ECONCAT2(a,b) _LZO_CONCAT2(a,b)
  176. #define _LZO_ECONCAT3(a,b,c) _LZO_CONCAT3(a,b,c)
  177. #define _LZO_ECONCAT4(a,b,c,d) _LZO_CONCAT4(a,b,c,d)
  178. #define _LZO_ECONCAT5(a,b,c,d,e) _LZO_CONCAT5(a,b,c,d,e)
  179. /***********************************************************************
  180. //
  181. ************************************************************************/
  182. /* Generate compressed data in a deterministic way.
  183. * This is fully portable, and compression can be faster as well.
  184. * A reason NOT to be deterministic is when the block size is
  185. * very small (e.g. 8kB) or the dictionary is big, because
  186. * then the initialization of the dictionary becomes a relevant
  187. * magnitude for compression speed.
  188. */
  189. #define LZO_DETERMINISTIC
  190. /***********************************************************************
  191. //
  192. ************************************************************************/
  193. #if 0
  194. /* This line causes problems on some architectures */
  195. #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
  196. (BOUNDS_CHECKING_OFF_IN_EXPR( \
  197. (m_off = ip - m_pos) > max_offset ))
  198. #else
  199. /* This is the safe (but slower) version */
  200. #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
  201. (m_pos == NULL || (m_off = ip - m_pos) > max_offset)
  202. #endif
  203. /* m_pos may point anywhere...
  204. * This marco is probably a good candidate for architecture specific problems.
  205. * Try casting the pointers to lzo_ptr_t before comparing them.
  206. */
  207. #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
  208. (BOUNDS_CHECKING_OFF_IN_EXPR( \
  209. (m_pos < in || (m_off = ip - m_pos) <= 0 || m_off > max_offset) ))
  210. #endif /* already included */
  211. /*
  212. vi:ts=4
  213. */