74 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
80 { 0x88, ( ( ( 143 - 0 ) + 1 ) / 2 ) },
81 { 0x99, ( ( ( 255 - 144 ) + 1 ) / 2 ) },
82 { 0x77, ( ( ( 279 - 256 ) + 1 ) / 2 ) },
83 { 0x88, ( ( ( 287 - 280 ) + 1 ) / 2 ) },
85 { 0x55, ( ( ( 31 - 0 ) + 1 ) / 2 ) },
98 static char buf[ ( 8 *
sizeof (
value ) ) + 1 ];
120 unsigned int bits ) {
133 unsigned int index ) {
152 return "distance/codelen";
176 for (
bits = 1 ;
bits <= (
sizeof ( alphabet->
huf ) /
177 sizeof ( alphabet->
huf[0] ) ) ;
bits++ ) {
178 huf_sym = &alphabet->
huf[
bits - 1 ];
179 if ( huf_sym->
freq == 0 )
182 DBGC2 ( alphabet,
"DEFLATE %p \"%s\" length %d start \"%s\" " 186 for ( i = 0 ; i < huf_sym->
freq ; i++ ) {
187 DBGC2 ( alphabet,
" %03x",
188 huf_sym->
raw[ huf + i ] );
190 DBGC2 ( alphabet,
"\n" );
194 DBGC2 ( alphabet,
"DEFLATE %p \"%s\" quick lookup:",
deflate,
196 for ( i = 0 ; i < (
sizeof ( alphabet->
lookup ) /
197 sizeof ( alphabet->
lookup[0] ) ) ; i++ ) {
198 DBGC2 ( alphabet,
" %d", ( alphabet->
lookup[i] + 1 ) );
200 DBGC2 ( alphabet,
"\n" );
217 unsigned int cum_freq;
220 unsigned int adjustment;
237 for (
bits = 1 ;
bits <= (
sizeof ( alphabet->
huf ) /
238 sizeof ( alphabet->
huf[0] ) ) ;
bits++ ) {
239 huf_sym = &alphabet->
huf[
bits - 1 ];
243 huf_sym->
raw = &alphabet->
raw[cum_freq];
244 huf += huf_sym->
freq;
245 if ( huf > ( 1U <<
bits ) ) {
246 DBGC ( alphabet,
"DEFLATE %p \"%s\" has too many " 247 "symbols with lengths <=%d\n",
deflate,
253 cum_freq += huf_sym->
freq;
255 complete = ( huf == ( 1U <<
bits ) );
261 huf_sym = &alphabet->
huf[
bits - 1 ];
269 for (
bits = 1 ;
bits <= (
sizeof ( alphabet->
huf ) /
270 sizeof ( alphabet->
huf[0] ) ) ;
bits++ ) {
271 huf_sym = &alphabet->
huf[
bits - 1 ];
275 adjustment = ( huf_sym->
start >> huf_sym->
shift );
276 huf_sym->
raw -= adjustment;
290 DBGC ( alphabet,
"DEFLATE %p \"%s\" is incomplete\n",
deflate,
306 unsigned int target ) {
393 unsigned int lookup_index;
409 huf_sym = &alphabet->
huf[ alphabet->
lookup[ lookup_index ] ];
410 while ( huf < huf_sym->
start )
454 if (
out->offset <
out->len ) {
455 copy_len = (
out->len -
out->offset );
456 if ( copy_len >
len )
459 *(out_byte++) = *(in_byte++);
516 "compression method %d\n",
deflate,
cm );
520 DBGC (
deflate,
"DEFLATE %p unsupported ZLIB preset " 545 DBGC (
deflate,
"DEFLATE %p found %sblock type %#x\n",
546 deflate, ( bfinal ?
"final " :
"" ), btype );
555 DBGC (
deflate,
"DEFLATE %p unsupported block type " 579 DBGC2 (
deflate,
"DEFLATE %p literal block length %#04zx\n",
610 if ( dlen > in_remaining )
636 pattern->
count ; pattern++ ) {
638 lengths += pattern->
count;
642 goto construct_alphabets;
671 DBGC2 (
deflate,
"DEFLATE %p dynamic block %d codelen, %d " 672 "litlen, %d distance\n",
deflate,
718 dynamic_litlen_distance: {
735 static const uint8_t dup_len[3] = { 3, 3, 11 };
736 static const uint8_t extra_bits[3] = { 2, 3, 7 };
737 index = ( clen - 16 );
745 dynamic_litlen_distance_extra: {
747 unsigned int dup_len;
768 goto dynamic_litlen_distance;
771 goto construct_alphabets;
774 construct_alphabets: {
813 distance_offset ) ) != 0 )
840 (
isprint (
byte ) ?
byte :
'.' ) );
863 goto lzhuf_litlen_extra;
868 lzhuf_litlen_extra: {
903 lzhuf_distance_extra: {
918 DBGCP (
deflate,
"DEFLATE %p duplicate length %zd distance " 919 "%zd\n",
deflate, dup_len, dup_distance );
922 if ( dup_distance >
out->offset ) {
923 DBGC (
deflate,
"DEFLATE %p bad distance %zd (max " 924 "%zd)\n",
deflate, dup_distance,
out->offset );
992 static int global_init_done;
1000 if ( ! global_init_done ) {
1003 for ( i = 255 ; i ; i-- ) {
1004 for (
bit = 1,
byte = 0 ;
bit ;
bit <<= 1 ) {
1014 for ( i = 0 ; i < 28 ; i++ ) {
1025 for ( i = 0 ; i < 30 ; i++ ) {
1035 global_init_done = 1;
#define EINVAL
Invalid argument.
static void deflate_set_length(struct deflate *deflate, unsigned int index, unsigned int bits)
Set Huffman symbol length.
struct arbelprm_rc_send_wqe rc
unsigned int length_index
Current length index within a set of code lengths.
#define DEFLATE_DYNAMIC_HLIT_LSB
Dynamic header HLIT field LSB.
static uint16_t deflate_distance_base[32]
Distance base values.
static void deflate_copy(struct deflate_chunk *out, const void *in, size_t len)
Copy data to output buffer (if available)
#define DEFLATE_CODELEN_BITS
Dynamic header code length length (in bits)
struct deflate_alphabet distance_codelen
Distance and code length Huffman alphabet.
static int deflate_decode(struct deflate *deflate, struct deflate_alphabet *alphabet)
Attempt to decode a Huffman-coded symbol from input stream.
unsigned int length_target
Target length index within a set of code lengths.
uint8_t extra
Signature extra byte.
#define DEFLATE_DYNAMIC_HCLEN_MASK
Dynamic header HCLEN field mask.
#define DEFLATE_HUFFMAN_QL_SHIFT
Quick lookup shift.
unsigned int extra_bits
Number of extra bits required.
#define DEFLATE_HUFFMAN_BITS
Maximum length of a Huffman symbol (in bits)
size_t dup_distance
Distance of a duplicated string.
#define DEFLATE_HEADER_BTYPE_STATIC
Block header type: static Huffman alphabet.
unsigned int header
Current block header.
uint16_t raw[0]
Raw symbols.
enum deflate_format format
Format.
unsigned int length
Current length within a set of code lengths.
A Huffman-coded set of symbols of a given length.
#define ZLIB_ADLER32_BITS
ZLIB ADLER32 length (in bits)
uint32_t start
First symbol of this length (normalised to 16 bits)
static unsigned int unsigned int bit
A Huffman-coded alphabet.
#define DEFLATE_LITLEN_END
Literal/length end of block code.
static unsigned int deflate_length(struct deflate *deflate, unsigned int index)
Get Huffman symbol length.
static int deflate_alphabet(struct deflate *deflate, struct deflate_alphabet *alphabet, unsigned int count, unsigned int offset)
Construct Huffman alphabet.
#define DEFLATE_DYNAMIC_HDIST_MASK
Dynamic header HDIST field mask.
uint8_t count
Repetition count.
static unsigned int code
Response code.
unsigned int bits
Number of bits within the accumulator.
static const char * deflate_bin(unsigned long value, unsigned int bits)
Transcribe binary value (for debugging)
#define ENOTSUP
Operation not supported.
static int isprint(int character)
Check if character is printable.
#define DEFLATE_DYNAMIC_HCLEN_LSB
Dynamic header HCLEN field LSB.
uint32_t start
Starting offset.
static void deflate_dump_alphabet(struct deflate *deflate, struct deflate_alphabet *alphabet)
Dump Huffman alphabet (for debugging)
static int deflate_accumulate(struct deflate *deflate, unsigned int target)
Attempt to accumulate bits from input stream.
#define DEFLATE_HEADER_BTYPE_LSB
Block header type LSB.
#define ZLIB_HEADER_BITS
ZLIB header length (in bits)
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
#define DEFLATE_LITERAL_LEN_BITS
Literal header LEN/NLEN field length (in bits)
uint32_t accumulator
Accumulator.
size_t dup_len
Length of a duplicated string.
#define ZLIB_HEADER_CM_DEFLATE
ZLIB header compression method: DEFLATE.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * resume
Resume point.
pseudo_bit_t value[0x00020]
#define DEFLATE_HUFFMAN_QL_BITS
Quick lookup length for a Huffman symbol (in bits)
uint8_t lookup[1<< DEFLATE_HUFFMAN_QL_BITS]
Quick lookup table.
static unsigned int count
Number of entries.
struct deflate_huf_symbols huf[DEFLATE_HUFFMAN_BITS]
Huffman-coded symbol set for each length.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static int deflate_extract(struct deflate *deflate, unsigned int target)
Attempt to extract a fixed number of bits from input stream.
uint16_t freq
Number of Huffman-coded symbols having this length.
#define DEFLATE_DYNAMIC_HLIT_MASK
Dynamic header HLIT field mask.
deflate_format
Compression formats.
#define DEFLATE_CODELEN_MAX_CODE
Maximum value of a code length code.
static const char * deflate_alphabet_name(struct deflate *deflate, struct deflate_alphabet *alphabet)
Determine Huffman alphabet name (for debugging)
uint32_t rotalumucca
Bit-reversed accumulator.
unsigned int distance_count
Number of symbols in the distance Huffman alphabet.
static uint8_t deflate_litlen_base[28]
Literal/length base values.
static int deflate_consume(struct deflate *deflate, unsigned int count)
Consume accumulated bits from the input stream.
int deflate_inflate(struct deflate *deflate, const void *data, size_t len, struct deflate_chunk *out)
Inflate compressed data.
struct deflate_alphabet litlen
Literal/length Huffman alphabet.
uint16_t * raw
Raw symbols having this length.
static uint8_t deflate_codelen_map[19]
Code length map.
const uint8_t * in
Current input data pointer.
#define DEFLATE_DYNAMIC_BITS
Dynamic header length (in bits)
Raw DEFLATE data (no header or footer)
static volatile void * bits
A static Huffman alphabet length pattern.
#define DEFLATE_HEADER_BTYPE_LITERAL
Block header type: literal data.
const uint8_t * end
End of input data pointer.
struct ena_llq_option header
Header locations.
#define DEFLATE_HEADER_BITS
Block header length (in bits)
uint8_t data[48]
Additional event data.
#define ZLIB_HEADER_CM_MASK
ZLIB header compression method mask.
static struct deflate_static_length_pattern deflate_static_length_patterns[]
Static Huffman alphabet length patterns.
unsigned int litlen_count
Number of symbols in the literal/length Huffman alphabet.
#define ZLIB_HEADER_CM_LSB
ZLIB header compression method LSB.
#define DEFLATE_HEADER_BFINAL_BIT
Block header final block flags bit.
uint8_t lengths[((DEFLATE_LITLEN_MAX_CODE+1)+(DEFLATE_DISTANCE_MAX_CODE+1)+1)/2]
Huffman code lengths.
static void deflate_discard_to_byte(struct deflate *deflate)
Discard bits up to the next byte boundary.
uint16_t offset
Offset to command line.
DEFLATE decompression algorithm.
uint8_t shift
Shift to normalise symbols of this length to 16 bits.
#define ZLIB_HEADER_FDICT_BIT
ZLIB header preset dictionary flag bit.
#define NULL
NULL pointer (VOID *)
#define DEFLATE_DYNAMIC_HDIST_LSB
Dynamic header HDIST field LSB.
uint8_t bits
Length of Huffman-coded symbols.
static uint8_t deflate_reverse[256]
Byte reversal table.
size_t remaining
Remaining length of data (e.g.
void * memset(void *dest, int character, size_t len) __nonnull
#define DEFLATE_HEADER_BTYPE_DYNAMIC
Block header type: dynamic Huffman alphabet.