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.

292 lines
10 KiB

  1. /*
  2. * encvars.h
  3. *
  4. * Variables for the compressor
  5. */
  6. #ifdef ALLOC_VARS
  7. #undef EXT
  8. #define EXT
  9. #else
  10. #undef EXT
  11. #define EXT extern
  12. #endif
  13. /*
  14. * For the optimal parser
  15. *
  16. * Uses less memory if it's ushort, but then we're forcing the CPU
  17. * to do 16 bit operations.
  18. *
  19. * Change this to ulong if you don't mind a small memory hit.
  20. * Also, if you make LOOK too large, this number may cause the
  21. * cost estimation to overflow; e.g. 10000 uncompressed symbols
  22. * @ 8 bits each > 65535 bits.
  23. */
  24. typedef ulong numbits_t;
  25. /*
  26. * For the optimal parser
  27. */
  28. typedef struct
  29. {
  30. ulong link;
  31. ulong path;
  32. ulong repeated_offset[NUM_REPEATED_OFFSETS];
  33. numbits_t numbits;
  34. #ifdef TRACING
  35. ulong matchoff;
  36. #endif
  37. } decision_node;
  38. /*
  39. * 256 + 8 * max_position_slots
  40. */
  41. #define MAX_MAIN_TREE_ELEMENTS (256 + (8 * 291)) // 32MB
  42. typedef struct
  43. {
  44. /* "fake" window pointer, based on enc_RealMemWindow */
  45. byte *enc_MemWindow;
  46. ulong enc_window_size;
  47. #ifdef MULTIPLE_SEARCH_TREES
  48. /* root node pointers for our search trees */
  49. ulong *enc_tree_root;
  50. #else /* !MULTIPLE_SEARCH_TREES */
  51. ulong enc_single_tree_root;
  52. #endif /* MULTIPLE_SEARCH_TREES */
  53. /* "fake" start of left nodes */
  54. ulong *enc_Left;
  55. /* "fake" start of right nodes */
  56. ulong *enc_Right;
  57. /* bitwise outputting */
  58. ulong enc_bitbuf;
  59. signed char enc_bitcount;
  60. bool enc_output_overflow;
  61. char pad1[2];
  62. /* used to record literals and displacements */
  63. ulong enc_literals; /* current number of literals */
  64. ulong enc_distances; /* current number of displacements */
  65. ulong *enc_DistData; /* match displacement array */
  66. byte *enc_LitData; /* contains a character or a matchlength */
  67. #ifdef EXTRALONGMATCHES
  68. ushort *enc_ExtraLength; /* parallel to enc_LitData */
  69. #endif
  70. byte *enc_ItemType; /* bitmap for whether it's a character or matchlength */
  71. ulong enc_repeated_offset_at_literal_zero[NUM_REPEATED_OFFSETS];
  72. /*
  73. * the last three match offsets (displacements) encoded, the most recent
  74. * one being enc_last_matchpos_offset[0].
  75. */
  76. ulong enc_last_matchpos_offset[NUM_REPEATED_OFFSETS];
  77. /* used for optimal parsing */
  78. ulong enc_matchpos_table[MAX_MATCH+1];
  79. /* current encoding position in data */
  80. ulong enc_BufPos;
  81. /* lookup table for converting a match position into a slot */
  82. ushort enc_slot_table[1024];
  83. /* buffering the output data */
  84. byte *enc_output_buffer_start;
  85. byte *enc_output_buffer_curpos;
  86. byte *enc_output_buffer_end;
  87. ulong enc_input_running_total;
  88. ulong enc_bufpos_last_output_block;
  89. /* number of distinct position slots */
  90. ulong enc_num_position_slots;
  91. /* misc */
  92. ulong enc_file_size_for_translation;
  93. /* number of block splits for this 32K of uncompressed data */
  94. byte enc_num_block_splits;
  95. /* the number of 1 bits in any given integer */
  96. byte enc_ones[256];
  97. /* compression parameters */
  98. byte enc_first_block;
  99. bool enc_need_to_recalc_stats;
  100. bool enc_first_time_this_group;
  101. ulong enc_encoder_second_partition_size;
  102. ulong enc_earliest_window_data_remaining;
  103. ulong enc_bufpos_at_last_block;
  104. byte *enc_input_ptr;
  105. long enc_input_left;
  106. ulong enc_instr_pos;
  107. /* for tree.c */
  108. ushort *enc_tree_freq;
  109. ushort *enc_tree_sortptr;
  110. byte *enc_len;
  111. short enc_tree_heap[MAX_MAIN_TREE_ELEMENTS + 2];
  112. ushort enc_tree_leftright[2*(2*MAX_MAIN_TREE_ELEMENTS-1)];
  113. ushort enc_tree_len_cnt[17];
  114. int enc_tree_n;
  115. short enc_tree_heapsize;
  116. char enc_depth;
  117. ulong enc_next_tree_create;
  118. ulong enc_last_literals;
  119. ulong enc_last_distances;
  120. decision_node *enc_decision_node;
  121. /* trees */
  122. byte enc_main_tree_len[MAX_MAIN_TREE_ELEMENTS+1];
  123. byte enc_secondary_tree_len[NUM_SECONDARY_LENGTHS+1];
  124. ushort enc_main_tree_freq[MAX_MAIN_TREE_ELEMENTS*2];
  125. ushort enc_main_tree_code[MAX_MAIN_TREE_ELEMENTS];
  126. byte enc_main_tree_prev_len[MAX_MAIN_TREE_ELEMENTS+1];
  127. ushort enc_secondary_tree_freq[NUM_SECONDARY_LENGTHS*2];
  128. ushort enc_secondary_tree_code[NUM_SECONDARY_LENGTHS];
  129. byte enc_secondary_tree_prev_len[NUM_SECONDARY_LENGTHS+1];
  130. ushort enc_aligned_tree_freq[ALIGNED_NUM_ELEMENTS*2];
  131. ushort enc_aligned_tree_code[ALIGNED_NUM_ELEMENTS];
  132. byte enc_aligned_tree_len[ALIGNED_NUM_ELEMENTS];
  133. byte enc_aligned_tree_prev_len[ALIGNED_NUM_ELEMENTS];
  134. /* start of allocated window memory */
  135. byte *enc_RealMemWindow;
  136. /* start of allocated left nodes */
  137. ulong *enc_RealLeft;
  138. /* start of allocated right nodes */
  139. ulong *enc_RealRight;
  140. /* # cfdata frames this folder */
  141. ulong enc_num_cfdata_frames;
  142. /* misc */
  143. void *enc_fci_data;
  144. PFNALLOC enc_malloc;
  145. HANDLE enc_mallochandle;
  146. int (__stdcall *enc_output_callback_function)(
  147. void * pfol,
  148. unsigned char * compressed_data,
  149. long compressed_size,
  150. long uncompressed_size
  151. );
  152. } t_encoder_context;
  153. /*
  154. * Declare arrays?
  155. */
  156. #ifdef ALLOC_VARS
  157. /*
  158. * (1 << extra_bits[n])-1
  159. */
  160. const ulong enc_slot_mask[] =
  161. {
  162. 0, 0, 0, 0, 1, 1, 3, 3,
  163. 7, 7, 15, 15, 31, 31, 63, 63,
  164. 127, 127, 255, 255, 511, 511, 1023, 1023,
  165. 2047, 2047, 4095, 4095, 8191, 8191, 16383, 16383,
  166. 32767, 32767, 65535, 65535, 131071, 131071, 131071, 131071,
  167. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  168. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  169. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  170. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  171. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  172. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  173. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  174. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  175. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  176. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  177. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  178. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  179. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  180. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  181. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  182. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  183. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  184. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  185. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  186. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  187. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  188. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  189. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  190. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  191. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  192. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  193. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  194. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  195. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  196. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  197. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  198. 131071, 131071, 131071
  199. };
  200. const byte enc_extra_bits[] =
  201. {
  202. 0,0,0,0,1,1,2,2,
  203. 3,3,4,4,5,5,6,6,
  204. 7,7,8,8,9,9,10,10,
  205. 11,11,12,12,13,13,14,14,
  206. 15,15,16,16,17,17,17,17,
  207. 17,17,17,17,17,17,17,17,
  208. 17,17,17,17,17,17,17,17,
  209. 17,17,17,17,17,17,17,17,
  210. 17,17,17,17,17,17,17,17,
  211. 17,17,17,17,17,17,17,17,
  212. 17,17,17,17,17,17,17,17,
  213. 17,17,17,17,17,17,17,17,
  214. 17,17,17,17,17,17,17,17,
  215. 17,17,17,17,17,17,17,17,
  216. 17,17,17,17,17,17,17,17,
  217. 17,17,17,17,17,17,17,17,
  218. 17,17,17,17,17,17,17,17,
  219. 17,17,17,17,17,17,17,17,
  220. 17,17,17,17,17,17,17,17,
  221. 17,17,17,17,17,17,17,17,
  222. 17,17,17,17,17,17,17,17,
  223. 17,17,17,17,17,17,17,17,
  224. 17,17,17,17,17,17,17,17,
  225. 17,17,17,17,17,17,17,17,
  226. 17,17,17,17,17,17,17,17,
  227. 17,17,17,17,17,17,17,17,
  228. 17,17,17,17,17,17,17,17,
  229. 17,17,17,17,17,17,17,17,
  230. 17,17,17,17,17,17,17,17,
  231. 17,17,17,17,17,17,17,17,
  232. 17,17,17,17,17,17,17,17,
  233. 17,17,17,17,17,17,17,17,
  234. 17,17,17,17,17,17,17,17,
  235. 17,17,17,17,17,17,17,17,
  236. 17,17,17,17,17,17,17,17,
  237. 17,17,17,17,17,17,17,17,
  238. 17,17,17
  239. };
  240. #else
  241. extern const ulong enc_slot_mask[];
  242. extern const byte enc_extra_bits[];
  243. #endif