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.

146 lines
4.9 KiB

  1. /*
  2. * decmacro.h
  3. *
  4. * Macros used by the decoder
  5. */
  6. /*
  7. * decode an element from the aligned offset tree, without checking
  8. * for the end of the input data
  9. */
  10. #define DECODE_ALIGNED_NOEOFCHECK(j) \
  11. (j) = context->dec_aligned_table[dec_bitbuf >> (32-ALIGNED_TABLE_BITS)]; \
  12. FILL_BUF_NOEOFCHECK(context->dec_aligned_len[(j)]);
  13. /*
  14. * Decode an element from the main tree
  15. * Check for EOF
  16. */
  17. #define DECODE_MAIN_TREE(j) \
  18. j = context->dec_main_tree_table[dec_bitbuf >> (32-MAIN_TREE_TABLE_BITS)]; \
  19. if (j < 0) \
  20. { \
  21. ulong mask = (1L << (32-1-MAIN_TREE_TABLE_BITS)); \
  22. do \
  23. { \
  24. j = -j; \
  25. if (dec_bitbuf & mask) \
  26. j = context->dec_main_tree_left_right[j*2+1]; \
  27. else \
  28. j = context->dec_main_tree_left_right[j*2]; \
  29. mask >>= 1; \
  30. } while (j < 0); \
  31. } \
  32. FILL_BUF_FULLCHECK(context->dec_main_tree_len[j]);
  33. /*
  34. * Decode an element from the secondary length tree
  35. * No checking for EOF
  36. */
  37. #define DECODE_LEN_TREE_NOEOFCHECK(matchlen) \
  38. matchlen = context->dec_secondary_length_tree_table[dec_bitbuf >> (32-SECONDARY_LEN_TREE_TABLE_BITS)]; \
  39. if (matchlen < 0) \
  40. { \
  41. ulong mask = (1L << (32-1-SECONDARY_LEN_TREE_TABLE_BITS)); \
  42. do \
  43. { \
  44. matchlen = -matchlen; \
  45. if (dec_bitbuf & mask) \
  46. matchlen = context->dec_secondary_length_tree_left_right[matchlen*2+1];\
  47. else \
  48. matchlen = context->dec_secondary_length_tree_left_right[matchlen*2]; \
  49. mask >>= 1; \
  50. } while (matchlen < 0); \
  51. } \
  52. FILL_BUF_NOEOFCHECK(context->dec_secondary_length_tree_len[matchlen]); \
  53. matchlen += NUM_PRIMARY_LENGTHS;
  54. /*
  55. * read n bits from input stream into dest_var, but don't
  56. * check for EOF
  57. */
  58. #define GET_BITS_NOEOFCHECK(N,DEST_VAR) \
  59. { \
  60. DEST_VAR = dec_bitbuf >> (32-(N)); \
  61. FILL_BUF_NOEOFCHECK((N)); \
  62. }
  63. /* same as above, but don't check for EOF */
  64. #define GET_BITS17_NOEOFCHECK(N,DEST_VAR) \
  65. { \
  66. DEST_VAR = dec_bitbuf >> (32-(N)); \
  67. FILL_BUF17_NOEOFCHECK((N)); \
  68. }
  69. /*
  70. * Remove n bits from the input stream
  71. * handles 1 <= n <= 17
  72. *
  73. * FORCE an EOF check ALWAYS, whether or not we read in more
  74. * bytes from memory.
  75. *
  76. * This is used to ensure that we always get an EOF check often enough
  77. * to not overrun the extra bytes in the buffer.
  78. *
  79. * This routine is used ONLY when decoding the main tree element,
  80. * where we know that the code we read in will be 16 bits or less
  81. * in length. Therefore we don't have to check for bitcount going
  82. * less than zero, twice.
  83. */
  84. #define FILL_BUF_FULLCHECK(N) \
  85. { \
  86. if (dec_input_curpos >= dec_end_input_pos) \
  87. return -1; \
  88. dec_bitbuf <<= (N); \
  89. dec_bitcount -= (N); \
  90. if (dec_bitcount <= 0) \
  91. { \
  92. dec_bitbuf |= ((((ulong) *dec_input_curpos | (((ulong) *(dec_input_curpos+1)) << 8))) << (-dec_bitcount)); \
  93. dec_input_curpos += 2; \
  94. dec_bitcount += 16; \
  95. } \
  96. }
  97. /*
  98. * Same as above, but no EOF check
  99. *
  100. * This is used when we know we will not run out of input
  101. */
  102. #define FILL_BUF_NOEOFCHECK(N) \
  103. { \
  104. dec_bitbuf <<= (N); \
  105. dec_bitcount -= (N); \
  106. if (dec_bitcount <= 0) \
  107. { \
  108. dec_bitbuf |= ((((ulong) *dec_input_curpos | (((ulong) *(dec_input_curpos+1)) << 8))) << (-dec_bitcount)); \
  109. dec_input_curpos += 2; \
  110. dec_bitcount += 16; \
  111. } \
  112. }
  113. /*
  114. * Same as above, but handles n=17 bits
  115. */
  116. #define FILL_BUF17_NOEOFCHECK(N) \
  117. { \
  118. dec_bitbuf <<= (N); \
  119. dec_bitcount -= (N); \
  120. if (dec_bitcount <= 0) \
  121. { \
  122. dec_bitbuf |= ((((ulong) *dec_input_curpos | (((ulong) *(dec_input_curpos+1)) << 8))) << (-dec_bitcount)); \
  123. dec_input_curpos += 2; \
  124. dec_bitcount += 16; \
  125. if (dec_bitcount <= 0) \
  126. { \
  127. dec_bitbuf |= ((((ulong) *dec_input_curpos | (((ulong) *(dec_input_curpos+1)) << 8))) << (-dec_bitcount)); \
  128. dec_input_curpos += 2; \
  129. dec_bitcount += 16; \
  130. } \
  131. } \
  132. }