4 * Constants for the LZMS compression format.
7 #ifndef _LZMS_CONSTANTS_H
8 #define _LZMS_CONSTANTS_H
10 /* Limits on match lengths and offsets (in bytes) */
11 #define LZMS_MIN_MATCH_LENGTH 1
12 #define LZMS_MAX_MATCH_LENGTH 1073809578
13 #define LZMS_MIN_MATCH_OFFSET 1
14 #define LZMS_MAX_MATCH_OFFSET 1180427428
16 /* The value to which buffer sizes should be limited. Microsoft's
17 * implementation seems to use 67108864 (2^26) bytes. However, since the format
18 * itself supports higher match lengths and offsets, we'll use 2^30 bytes. */
19 #define LZMS_MAX_BUFFER_SIZE 1073741824
21 /* The length of each LRU queue for match sources:
23 * 1. offsets of LZ matches
24 * 2. (power, raw offset) pairs of delta matches */
25 #define LZMS_NUM_LZ_REPS 3
26 #define LZMS_NUM_DELTA_REPS 3
28 /* The numbers of binary decision classes needed for encoding queue indices */
29 #define LZMS_NUM_LZ_REP_DECISIONS (LZMS_NUM_LZ_REPS - 1)
30 #define LZMS_NUM_DELTA_REP_DECISIONS (LZMS_NUM_DELTA_REPS - 1)
32 /* These are the numbers of probability entries for each binary decision class.
33 * The logarithm base 2 of each of these values is the number of recently
34 * encoded bits that are remembered for each decision class and are used to
35 * select the appropriate probability entry when decoding/encoding the next
36 * binary decision (bit). */
37 #define LZMS_NUM_MAIN_PROBS 16
38 #define LZMS_NUM_MATCH_PROBS 32
39 #define LZMS_NUM_LZ_PROBS 64
40 #define LZMS_NUM_LZ_REP_PROBS 64
41 #define LZMS_NUM_DELTA_PROBS 64
42 #define LZMS_NUM_DELTA_REP_PROBS 64
44 /* These values define the precision for probabilities in LZMS, which are always
45 * given as a numerator; the denominator is implied. */
46 #define LZMS_PROBABILITY_BITS 6
47 #define LZMS_PROBABILITY_DENOMINATOR (1 << LZMS_PROBABILITY_BITS)
49 /* These values define the initial state of each probability entry. */
50 #define LZMS_INITIAL_PROBABILITY 48
51 #define LZMS_INITIAL_RECENT_BITS 0x0000000055555555
53 /* The number of symbols in each Huffman-coded alphabet */
54 #define LZMS_NUM_LITERAL_SYMS 256
55 #define LZMS_NUM_LENGTH_SYMS 54
56 #define LZMS_NUM_DELTA_POWER_SYMS 8
57 #define LZMS_MAX_NUM_OFFSET_SYMS 799
58 #define LZMS_MAX_NUM_SYMS 799
60 /* The rebuild frequencies, in symbols, for each Huffman code */
61 #define LZMS_LITERAL_CODE_REBUILD_FREQ 1024
62 #define LZMS_LZ_OFFSET_CODE_REBUILD_FREQ 1024
63 #define LZMS_LENGTH_CODE_REBUILD_FREQ 512
64 #define LZMS_DELTA_OFFSET_CODE_REBUILD_FREQ 1024
65 #define LZMS_DELTA_POWER_CODE_REBUILD_FREQ 512
67 /* The maximum length, in bits, of any Huffman codeword. This is guaranteed by
68 * the way frequencies are updated. */
69 #define LZMS_MAX_CODEWORD_LENGTH 15
71 /* The maximum number of verbatim bits, in addition to the Huffman-encoded
72 * length slot symbol, that may be required to encode a match length */
73 #define LZMS_MAX_EXTRA_LENGTH_BITS 30
75 /* The maximum number of verbatim bits, in addition to the Huffman-encoded
76 * offset slot symbol, that may be required to encode a match offset */
77 #define LZMS_MAX_EXTRA_OFFSET_BITS 30
79 /* Parameters for x86 machine code pre/post-processing */
80 #define LZMS_X86_ID_WINDOW_SIZE 65535
81 #define LZMS_X86_MAX_TRANSLATION_OFFSET 1023
83 #endif /* _LZMS_CONSTANTS_H */