]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/igzip/igzip_stateless_base.c
4 #include "huff_codes.h"
7 static inline void update_state(struct isal_zstream
*stream
, struct isal_zstate
*state
,
8 uint8_t * end_in
, uint8_t * start_in
)
11 stream
->avail_in
= end_in
- stream
->next_in
;
12 stream
->total_in
+= stream
->next_in
- start_in
;
13 count
= buffer_used(&state
->bitbuf
);
14 stream
->next_out
= buffer_ptr(&state
->bitbuf
);
15 stream
->avail_out
-= count
;
16 stream
->total_out
+= count
;
20 void isal_deflate_body_stateless_base(struct isal_zstream
*stream
)
22 uint32_t literal
= 0, hash
;
23 uint8_t *start_in
, *end_in
, *end
, *next_hash
;
24 uint16_t match_length
;
26 uint64_t code
, code_len
, code2
, code_len2
, i
;
27 struct isal_zstate
*state
= &stream
->internal_state
;
28 uint16_t *last_seen
= state
->head
;
30 if (stream
->avail_in
== 0)
33 set_buf(&state
->bitbuf
, stream
->next_out
, stream
->avail_out
);
34 start_in
= stream
->next_in
;
35 end_in
= stream
->next_in
+ stream
->avail_in
;
37 while (stream
->next_in
< end_in
- 3) {
38 if (is_full(&state
->bitbuf
)) {
39 update_state(stream
, state
, end_in
, start_in
);
43 literal
= *(uint32_t *) stream
->next_in
;
44 hash
= compute_hash(literal
) & HASH_MASK
;
45 dist
= (uint64_t) (stream
->next_in
- last_seen
[hash
]) & 0xFFFF;
46 last_seen
[hash
] = (uint64_t) stream
->next_in
;
48 if (dist
- 1 < IGZIP_D
- 1 && stream
->next_in
- dist
>= start_in
) { /* The -1 are to handle the case when dist = 0 */
50 compare258(stream
->next_in
- dist
, stream
->next_in
,
51 end_in
- stream
->next_in
);
53 if (match_length
>= SHORTEST_MATCH
) {
54 next_hash
= stream
->next_in
;
55 #ifdef LIMIT_HASH_UPDATE
58 end
= next_hash
+ match_length
;
63 for (; next_hash
< end
; next_hash
++) {
64 literal
= *(uint32_t *) next_hash
;
65 hash
= compute_hash(literal
) & HASH_MASK
;
66 last_seen
[hash
] = (uint64_t) next_hash
;
69 get_len_code(stream
->hufftables
, match_length
, &code
,
71 get_dist_code(stream
->hufftables
, dist
, &code2
, &code_len2
);
73 code
|= code2
<< code_len
;
74 code_len
+= code_len2
;
76 write_bits(&state
->bitbuf
, code
, code_len
);
78 stream
->next_in
+= match_length
;
84 get_lit_code(stream
->hufftables
, literal
& 0xFF, &code
, &code_len
);
85 write_bits(&state
->bitbuf
, code
, code_len
);
89 if (is_full(&state
->bitbuf
)) {
90 update_state(stream
, state
, end_in
, start_in
);
94 literal
= *(uint32_t *) (end_in
- 4);
96 for (i
= 4; i
> end_in
- stream
->next_in
; i
--)
97 literal
= literal
>> 8;
99 hash
= compute_hash(literal
) & HASH_MASK
;
100 dist
= (uint64_t) (stream
->next_in
- last_seen
[hash
]) & 0xFFFF;
102 if (dist
- 1 < IGZIP_D
- 1 && stream
->next_in
- dist
>= start_in
) {
104 compare258(stream
->next_in
- dist
, stream
->next_in
,
105 end_in
- stream
->next_in
);
106 if (match_length
>= SHORTEST_MATCH
) {
107 get_len_code(stream
->hufftables
, match_length
, &code
, &code_len
);
108 get_dist_code(stream
->hufftables
, dist
, &code2
, &code_len2
);
109 code
|= code2
<< code_len
;
110 code_len
+= code_len2
;
111 write_bits(&state
->bitbuf
, code
, code_len
);
112 stream
->next_in
+= 3;
114 if (is_full(&state
->bitbuf
)) {
115 update_state(stream
, state
, end_in
, start_in
);
119 get_lit_code(stream
->hufftables
, 256, &code
, &code_len
);
120 write_bits(&state
->bitbuf
, code
, code_len
);
122 if (is_full(&state
->bitbuf
)) {
123 update_state(stream
, state
, end_in
, start_in
);
128 update_state(stream
, state
, end_in
, start_in
);
133 while (stream
->next_in
< end_in
) {
134 get_lit_code(stream
->hufftables
, literal
& 0xFF, &code
, &code_len
);
135 write_bits(&state
->bitbuf
, code
, code_len
);
138 if (is_full(&state
->bitbuf
)) {
139 update_state(stream
, state
, end_in
, start_in
);
145 get_lit_code(stream
->hufftables
, 256, &code
, &code_len
);
146 write_bits(&state
->bitbuf
, code
, code_len
);
149 update_state(stream
, state
, end_in
, start_in
);