Leaked source code of windows server 2003
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.

206 lines
5.6 KiB

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