LZO_CONF.H 8.4 KB

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