Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.2 KiB

  1. #ifndef _XPRS_H_
  2. #define _XPRS_H_
  3. /* ------------------------------------------------------------------------ */
  4. /* */
  5. /* Copyright (c) Microsoft Corporation, 2000-2001. All rights reserved. */
  6. /* Copyright (c) Andrew Kadatch, 1991-2001. All rights reserved. */
  7. /* */
  8. /* Microsoft Confidential -- do not redistribute. */
  9. /* */
  10. /* ------------------------------------------------------------------------ */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <assert.h>
  15. #include "xpress.h"
  16. #ifdef _MSC_VER
  17. #pragma code_seg ("PAGELK")
  18. #ifdef _M_IX86
  19. #pragma optimize ("tgaw", on)
  20. #else
  21. #pragma optimize ("tgw", on)
  22. #endif /* _M_IX86 */
  23. #endif
  24. /* ------------------------ Configuration ----------------------------- */
  25. /* ------------- */
  26. #ifndef CODING_ALG
  27. #define CODING_ALG 1
  28. #endif
  29. #define CODING_DIRECT2 (1 << 1)
  30. #define CODING_DIRECT (1 << 2)
  31. #define CODING_BY_BIT (1 << 3)
  32. #define CODING_HUFF_LEN (1 << 4)
  33. #define CODING_HUFF_PTR (1 << 5)
  34. #define CODING_HUFF_ALL (1 << 6)
  35. #define CODING (1 << CODING_ALG)
  36. #define SUPPORT_CRC 0
  37. #define BUFF_SIZE_LOG XPRESS_MAX_BLOCK_LOG
  38. #define BUFF_SIZE (1<<BUFF_SIZE_LOG)
  39. #if 1
  40. #define MAX_OFFSET (BUFF_SIZE_LOG > 16 ? 16 : BUFF_SIZE_LOG)
  41. #else
  42. #define MAX_OFFSET 13
  43. #endif
  44. #if CODING == CODING_DIRECT2 && MAX_OFFSET > 13
  45. #undef MAX_OFFSET
  46. #define MAX_OFFSET 13
  47. #define DIRECT2_LEN_LOG (16 - MAX_OFFSET)
  48. #define DIRECT2_MAX_LEN ((1 << DIRECT2_LEN_LOG) - 1)
  49. #endif
  50. #if BUFF_SIZE < XPRESS_MAX_BLOCK
  51. #error BUFF_SIZE should not be less than XPRESS_MAX_BLOCK
  52. #endif
  53. #if CODING == CODING_HUFF_LEN
  54. #define MAX_LENGTH 32
  55. #define HUFF_SIZE (MAX_LENGTH * 2)
  56. #elif CODING & (CODING_HUFF_PTR | CODING_HUFF_ALL)
  57. #if (256 / MAX_OFFSET) >= 32
  58. #define MAX_LENGTH_LOG 5
  59. #else
  60. #define MAX_LENGTH_LOG 4
  61. #endif
  62. #define MAX_LENGTH (1 << MAX_LENGTH_LOG)
  63. #if CODING == CODING_HUFF_PTR
  64. #define HUFF_SIZE ((MAX_LENGTH * MAX_OFFSET + 1) & ~1)
  65. #elif CODING == CODING_HUFF_ALL
  66. #define HUFF_SIZE (256 + ((MAX_LENGTH * MAX_OFFSET + 1) & ~1))
  67. #endif
  68. #endif
  69. #define MIN_MATCH 3 /* min acceptable match length */
  70. #if CODING == CODING_HUFF_LEN
  71. #define DECODE_BITS 8
  72. #elif CODING & (CODING_HUFF_PTR | CODING_HUFF_ALL)
  73. #define DECODE_BITS 10
  74. #endif
  75. /* ---------------------- Useful types ------------------------ */
  76. /* ------------ */
  77. #if defined (_M_IX86) && !defined (i386)
  78. #define i386 1 /* ifdef i386 asm code will be used for some encodings */
  79. #endif
  80. #define uchar unsigned char /* useful types */
  81. #define schar signed char
  82. #ifdef _M_IX86
  83. #define __unaligned /* x86 does not have __unaligned keyword */
  84. #endif
  85. #define int4 int /* any long enough integral type */
  86. #define int2 short /* assert (2*sizeof(int2) == sizeof (int4)) */
  87. #define xint int /* any int type >= 32 bits && >= sizeof (bitmask4) */
  88. #define int32 int /* 32 bit type */
  89. #define int16 short /* 16 bit type */
  90. #define tag_t int32
  91. #ifdef i386
  92. #define bitmask4 int32 /* must be 32 bit for i386 */
  93. #define bitmask2 int16
  94. #else
  95. #define bitmask4 int4 /* not important otherwise; shall not exceed xint */
  96. #define bitmask2 int2
  97. #endif
  98. #define uint4 unsigned int4
  99. #define uint2 unsigned int2
  100. #define uxint unsigned xint
  101. #define uint32 unsigned int32
  102. #define uint16 unsigned int16
  103. #define utag_t unsigned tag_t
  104. #define ubitmask4 unsigned bitmask4
  105. #define ubitmask2 unsigned bitmask2
  106. #ifdef _MSC_VER
  107. #if _MSC_VER >= 1200
  108. #define INLINE __forceinline
  109. #else
  110. #define INLINE __inline
  111. #endif
  112. #pragma warning(disable:4127) /* conditional expression is constant */
  113. #pragma warning(disable:4711) /* function XXX selected for automatic inline expansion */
  114. #pragma warning(disable:4710) /* function XXX not expanded */
  115. #pragma warning(disable:4100) /* unreferenced formal paramter */
  116. #pragma warning(disable:4068) /* bogus "unknown pragma" */
  117. #endif
  118. #ifndef DEBUG
  119. #define DEBUG 0
  120. #endif
  121. #if !defined (INLINE) || DEBUG
  122. #undef INLINE
  123. #define INLINE static
  124. #endif
  125. #if !DEBUG
  126. #undef assert
  127. #define assert(x)
  128. #endif
  129. #if CODING & (CODING_DIRECT | CODING_DIRECT2)
  130. #define MIN_SIZE0 8
  131. #elif CODING == CODING_BY_BIT
  132. #define MIN_SIZE0 7
  133. #elif CODING == CODING_HUFF_LEN
  134. #define MIN_SIZE0 44
  135. #elif CODING == CODING_HUFF_PTR
  136. #define MIN_SIZE0 139
  137. #elif CODING == CODING_HUFF_ALL
  138. #define MIN_SIZE0 261
  139. #else
  140. #error wrong CODING
  141. #endif
  142. #define MIN_SIZE (MIN_SIZE0 + CRC_STAMP_SIZE)
  143. #define CRC32_FIRST 0
  144. #if SUPPORT_CRC
  145. #define CRC_STAMP_SIZE sizeof (uint32)
  146. #else
  147. #define CRC_STAMP_SIZE 0
  148. #endif
  149. #if DEBUG
  150. extern long xxx[];
  151. #endif
  152. #ifdef _MSC_VER
  153. #pragma warning (disable: 4731) /* frame pointer register 'ebp' modified by inline assembly code */
  154. #endif
  155. #if CODING_ALG != 1 && CODING_ALG != 6
  156. #error CODING_ALGs different from 1 and 6 are not supported anymore
  157. #endif
  158. #endif /* _XPRS_H_ */