mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
wuffsfmt: double-indents hanging lines
This commit is contained in:
1 parent
d910658bce
commit
9c03b8c71d
40 files changed
+2579
-2571
No files matched your search
@@ -14,41 +14,41 @@
|
||||
|
||||
// CODE_ORDER is defined in the RFC section 3.2.7.
|
||||
pri const CODE_ORDER : array[19] base.u8[..= 18] = [
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
|
||||
]
|
||||
|
||||
// REVERSE8 reverses the bits in a byte.
|
||||
pri const REVERSE8 : array[256] base.u8 = [
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, // 0x00 - 0x07
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, // 0x08 - 0x0F
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, // 0x10 - 0x17
|
||||
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, // 0x18 - 0x1F
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, // 0x20 - 0x27
|
||||
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, // 0x28 - 0x2F
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, // 0x30 - 0x37
|
||||
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, // 0x38 - 0x3F
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, // 0x40 - 0x47
|
||||
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, // 0x48 - 0x4F
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, // 0x50 - 0x57
|
||||
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, // 0x58 - 0x5F
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, // 0x60 - 0x67
|
||||
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, // 0x68 - 0x6F
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, // 0x70 - 0x77
|
||||
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, // 0x78 - 0x7F
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, // 0x80 - 0x87
|
||||
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, // 0x88 - 0x8F
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, // 0x90 - 0x97
|
||||
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, // 0x98 - 0x9F
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, // 0xA0 - 0xA7
|
||||
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, // 0xA8 - 0xAF
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, // 0xB0 - 0xB7
|
||||
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, // 0xB8 - 0xBF
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, // 0xC0 - 0xC7
|
||||
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, // 0xC8 - 0xCF
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, // 0xD0 - 0xD7
|
||||
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, // 0xD8 - 0xDF
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, // 0xE0 - 0xE7
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, // 0xE8 - 0xEF
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, // 0xF0 - 0xF7
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, // 0xF8 - 0xFF
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, // 0x00 - 0x07
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, // 0x08 - 0x0F
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, // 0x10 - 0x17
|
||||
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, // 0x18 - 0x1F
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, // 0x20 - 0x27
|
||||
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, // 0x28 - 0x2F
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, // 0x30 - 0x37
|
||||
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, // 0x38 - 0x3F
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, // 0x40 - 0x47
|
||||
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, // 0x48 - 0x4F
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, // 0x50 - 0x57
|
||||
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, // 0x58 - 0x5F
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, // 0x60 - 0x67
|
||||
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, // 0x68 - 0x6F
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, // 0x70 - 0x77
|
||||
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, // 0x78 - 0x7F
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, // 0x80 - 0x87
|
||||
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, // 0x88 - 0x8F
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, // 0x90 - 0x97
|
||||
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, // 0x98 - 0x9F
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, // 0xA0 - 0xA7
|
||||
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, // 0xA8 - 0xAF
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, // 0xB0 - 0xB7
|
||||
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, // 0xB8 - 0xBF
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, // 0xC0 - 0xC7
|
||||
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, // 0xC8 - 0xCF
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, // 0xD0 - 0xD7
|
||||
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, // 0xD8 - 0xDF
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, // 0xE0 - 0xE7
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, // 0xE8 - 0xEF
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, // 0xF0 - 0xF7
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, // 0xF8 - 0xFF
|
||||
]
|
||||
+107
-107
@@ -45,17 +45,17 @@ pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
|
||||
// Some trailing elements are 0x08000000. Bit 27 indicates an invalid value.
|
||||
|
||||
pri const LCODE_MAGIC_NUMBERS : array[32] base.u32 = [
|
||||
0x4000_0000, 0x4000_0100, 0x4000_0200, 0x4000_0300, 0x4000_0400, 0x4000_0500, 0x4000_0600, 0x4000_0700,
|
||||
0x4000_0810, 0x4000_0A10, 0x4000_0C10, 0x4000_0E10, 0x4000_1020, 0x4000_1420, 0x4000_1820, 0x4000_1C20,
|
||||
0x4000_2030, 0x4000_2830, 0x4000_3030, 0x4000_3830, 0x4000_4040, 0x4000_5040, 0x4000_6040, 0x4000_7040,
|
||||
0x4000_8050, 0x4000_A050, 0x4000_C050, 0x4000_E050, 0x4000_FF00, 0x0800_0000, 0x0800_0000, 0x0800_0000,
|
||||
0x4000_0000, 0x4000_0100, 0x4000_0200, 0x4000_0300, 0x4000_0400, 0x4000_0500, 0x4000_0600, 0x4000_0700,
|
||||
0x4000_0810, 0x4000_0A10, 0x4000_0C10, 0x4000_0E10, 0x4000_1020, 0x4000_1420, 0x4000_1820, 0x4000_1C20,
|
||||
0x4000_2030, 0x4000_2830, 0x4000_3030, 0x4000_3830, 0x4000_4040, 0x4000_5040, 0x4000_6040, 0x4000_7040,
|
||||
0x4000_8050, 0x4000_A050, 0x4000_C050, 0x4000_E050, 0x4000_FF00, 0x0800_0000, 0x0800_0000, 0x0800_0000,
|
||||
]
|
||||
|
||||
pri const DCODE_MAGIC_NUMBERS : array[32] base.u32 = [
|
||||
0x4000_0000, 0x4000_0100, 0x4000_0200, 0x4000_0300, 0x4000_0410, 0x4000_0610, 0x4000_0820, 0x4000_0C20,
|
||||
0x4000_1030, 0x4000_1830, 0x4000_2040, 0x4000_3040, 0x4000_4050, 0x4000_6050, 0x4000_8060, 0x4000_C060,
|
||||
0x4001_0070, 0x4001_8070, 0x4002_0080, 0x4003_0080, 0x4004_0090, 0x4006_0090, 0x4008_00A0, 0x400C_00A0,
|
||||
0x4010_00B0, 0x4018_00B0, 0x4020_00C0, 0x4030_00C0, 0x4040_00D0, 0x4060_00D0, 0x0800_0000, 0x0800_0000,
|
||||
0x4000_0000, 0x4000_0100, 0x4000_0200, 0x4000_0300, 0x4000_0410, 0x4000_0610, 0x4000_0820, 0x4000_0C20,
|
||||
0x4000_1030, 0x4000_1830, 0x4000_2040, 0x4000_3040, 0x4000_4050, 0x4000_6050, 0x4000_8060, 0x4000_C060,
|
||||
0x4001_0070, 0x4001_8070, 0x4002_0080, 0x4003_0080, 0x4004_0090, 0x4006_0090, 0x4008_00A0, 0x400C_00A0,
|
||||
0x4010_00B0, 0x4018_00B0, 0x4020_00C0, 0x4030_00C0, 0x4040_00D0, 0x4060_00D0, 0x0800_0000, 0x0800_0000,
|
||||
]
|
||||
|
||||
// HUFFS_TABLE_SIZE is the smallest power of 2 that is greater than or equal to
|
||||
@@ -67,89 +67,89 @@ pri const HUFFS_TABLE_SIZE : base.u32 = 1024
|
||||
pri const HUFFS_TABLE_MASK : base.u32 = 1023
|
||||
|
||||
pub struct decoder? implements base.io_transformer(
|
||||
// These fields yield src's bits in Least Significant Bits order.
|
||||
bits : base.u32,
|
||||
n_bits : base.u32,
|
||||
// These fields yield src's bits in Least Significant Bits order.
|
||||
bits : base.u32,
|
||||
n_bits : base.u32,
|
||||
|
||||
// transformed_history_count is the number of bytes written to the history
|
||||
// ringbuffer due to calling transform_io. It excludes any pre-history
|
||||
// written by explicit calls to add_history. It also excludes any bytes
|
||||
// decoded from the final transform_io call (the one that doesn't suspend)
|
||||
// as there is no further need for tracking history (for resolving back-
|
||||
// references) once the decoding completes.
|
||||
transformed_history_count : base.u64,
|
||||
// transformed_history_count is the number of bytes written to the history
|
||||
// ringbuffer due to calling transform_io. It excludes any pre-history
|
||||
// written by explicit calls to add_history. It also excludes any bytes
|
||||
// decoded from the final transform_io call (the one that doesn't suspend)
|
||||
// as there is no further need for tracking history (for resolving back-
|
||||
// references) once the decoding completes.
|
||||
transformed_history_count : base.u64,
|
||||
|
||||
// history_index indexes the history array, defined below.
|
||||
history_index : base.u32,
|
||||
// history_index indexes the history array, defined below.
|
||||
history_index : base.u32,
|
||||
|
||||
// n_huffs_bits is discussed in the huffs field comment.
|
||||
n_huffs_bits : array[2] base.u32[..= 9],
|
||||
// n_huffs_bits is discussed in the huffs field comment.
|
||||
n_huffs_bits : array[2] base.u32[..= 9],
|
||||
|
||||
// end_of_block is whether decode_huffman_xxx saw an end-of-block code.
|
||||
//
|
||||
// TODO: can decode_huffman_xxx signal this in band instead of out of band?
|
||||
end_of_block : base.bool,
|
||||
// end_of_block is whether decode_huffman_xxx saw an end-of-block code.
|
||||
//
|
||||
// TODO: can decode_huffman_xxx signal this in band instead of out of band?
|
||||
end_of_block : base.bool,
|
||||
|
||||
util : base.utility,
|
||||
util : base.utility,
|
||||
)(
|
||||
// huffs and n_huffs_bits are the lookup tables for Huffman decodings.
|
||||
//
|
||||
// There are up to 2 Huffman decoders active at any one time. As per this
|
||||
// package's README.md:
|
||||
// - huffs[0] is used for clcode and lcode.
|
||||
// - huffs[1] is used for dcode.
|
||||
//
|
||||
// The initial table key is the low n_huffs_bits of the decoder.bits field.
|
||||
// Keys longer than 9 bits require a two step lookup, the first step
|
||||
// examines the low 9 bits, the second step examines the remaining bits.
|
||||
// Two steps are required at most, as keys are at most 15 bits long.
|
||||
//
|
||||
// Using decoder.bits's low n_huffs_bits as a table key is valid even if
|
||||
// decoder.n_bits is less than n_huffs_bits, because the immediate next
|
||||
// step after indexing the table by the key is to compare decoder.n_bits to
|
||||
// the table value's number of decoder.bits to consume. If it compares
|
||||
// less, then more source bytes are read and the table lookup re-tried.
|
||||
//
|
||||
// The table value's bits:
|
||||
// - bit 31 indicates a literal.
|
||||
// - bit 30 indicates a base number + extra bits.
|
||||
// - bit 29 indicates end-of-block.
|
||||
// - bit 28 indicates a redirect to another part of the table.
|
||||
// - bit 27 indicates an invalid value.
|
||||
// - bits 24 ..= 26 are zero.
|
||||
// - bits 8 ..= 23 are the redirect offset, literal (in bits [8 ..= 15])
|
||||
// or base number.
|
||||
// - bits 4 ..= 7 are the redirected table's size in bits or the number
|
||||
// of extra bits.
|
||||
// - bits 0 ..= 3 are the number of decoder.bits to consume.
|
||||
//
|
||||
// Exactly one of the eight bits [24 ..= 31] should be set.
|
||||
huffs : array[2] array[HUFFS_TABLE_SIZE] base.u32,
|
||||
// huffs and n_huffs_bits are the lookup tables for Huffman decodings.
|
||||
//
|
||||
// There are up to 2 Huffman decoders active at any one time. As per this
|
||||
// package's README.md:
|
||||
// - huffs[0] is used for clcode and lcode.
|
||||
// - huffs[1] is used for dcode.
|
||||
//
|
||||
// The initial table key is the low n_huffs_bits of the decoder.bits field.
|
||||
// Keys longer than 9 bits require a two step lookup, the first step
|
||||
// examines the low 9 bits, the second step examines the remaining bits.
|
||||
// Two steps are required at most, as keys are at most 15 bits long.
|
||||
//
|
||||
// Using decoder.bits's low n_huffs_bits as a table key is valid even if
|
||||
// decoder.n_bits is less than n_huffs_bits, because the immediate next
|
||||
// step after indexing the table by the key is to compare decoder.n_bits to
|
||||
// the table value's number of decoder.bits to consume. If it compares
|
||||
// less, then more source bytes are read and the table lookup re-tried.
|
||||
//
|
||||
// The table value's bits:
|
||||
// - bit 31 indicates a literal.
|
||||
// - bit 30 indicates a base number + extra bits.
|
||||
// - bit 29 indicates end-of-block.
|
||||
// - bit 28 indicates a redirect to another part of the table.
|
||||
// - bit 27 indicates an invalid value.
|
||||
// - bits 24 ..= 26 are zero.
|
||||
// - bits 8 ..= 23 are the redirect offset, literal (in bits [8 ..= 15])
|
||||
// or base number.
|
||||
// - bits 4 ..= 7 are the redirected table's size in bits or the number
|
||||
// of extra bits.
|
||||
// - bits 0 ..= 3 are the number of decoder.bits to consume.
|
||||
//
|
||||
// Exactly one of the eight bits [24 ..= 31] should be set.
|
||||
huffs : array[2] array[HUFFS_TABLE_SIZE] base.u32,
|
||||
|
||||
// history[.. 0x8000] holds up to the last 32KiB of decoded output, if the
|
||||
// decoding was incomplete (e.g. due to a short read or write). RFC 1951
|
||||
// (DEFLATE) gives the maximum distance in a length-distance back-reference
|
||||
// as 32768, or 0x8000. Similarly, the RFC gives the maximum length as 258.
|
||||
//
|
||||
// history[.. 0x8000] is a ringbuffer, so that the most distant byte in
|
||||
// the decoding isn't necessarily history[0]. The ringbuffer is full (i.e.
|
||||
// it holds 32KiB of history) if and only if history_index >= 0x8000.
|
||||
//
|
||||
// history[history_index & 0x7FFF] is where the next byte of decoded output
|
||||
// will be written.
|
||||
//
|
||||
// When suspended in decoder.transform_io, or after an add_history call,
|
||||
// history[0x8000 .. 0x8000 + (ML - 1)] duplicates history[.. (ML - 1)],
|
||||
// where ML is the maximum length (258 as stated above). This simplifies
|
||||
// copying up to ML bytes from the ringbuffer, as there is no need to split
|
||||
// the copy around the 0x8000 index.
|
||||
history : array[0x8000 + (258 - 1)] base.u8, // 32 KiB + (ML - 1) bytes.
|
||||
// history[.. 0x8000] holds up to the last 32KiB of decoded output, if the
|
||||
// decoding was incomplete (e.g. due to a short read or write). RFC 1951
|
||||
// (DEFLATE) gives the maximum distance in a length-distance back-reference
|
||||
// as 32768, or 0x8000. Similarly, the RFC gives the maximum length as 258.
|
||||
//
|
||||
// history[.. 0x8000] is a ringbuffer, so that the most distant byte in
|
||||
// the decoding isn't necessarily history[0]. The ringbuffer is full (i.e.
|
||||
// it holds 32KiB of history) if and only if history_index >= 0x8000.
|
||||
//
|
||||
// history[history_index & 0x7FFF] is where the next byte of decoded output
|
||||
// will be written.
|
||||
//
|
||||
// When suspended in decoder.transform_io, or after an add_history call,
|
||||
// history[0x8000 .. 0x8000 + (ML - 1)] duplicates history[.. (ML - 1)],
|
||||
// where ML is the maximum length (258 as stated above). This simplifies
|
||||
// copying up to ML bytes from the ringbuffer, as there is no need to split
|
||||
// the copy around the 0x8000 index.
|
||||
history : array[0x8000 + (258 - 1)] base.u8, // 32 KiB + (ML - 1) bytes.
|
||||
|
||||
// code_lengths is used to pass out-of-band data to init_huff.
|
||||
//
|
||||
// code_lengths[args.n_codes0 + i] holds the number of bits in the i'th
|
||||
// code.
|
||||
code_lengths : array[320] base.u8,
|
||||
// code_lengths is used to pass out-of-band data to init_huff.
|
||||
//
|
||||
// code_lengths[args.n_codes0 + i] holds the number of bits in the i'th
|
||||
// code.
|
||||
code_lengths : array[320] base.u8,
|
||||
)
|
||||
|
||||
pub func decoder.add_history!(hist: slice base.u8) {
|
||||
@@ -204,8 +204,8 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE,
|
||||
max_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE)
|
||||
min_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE,
|
||||
max_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE)
|
||||
}
|
||||
|
||||
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
||||
@@ -249,7 +249,7 @@ pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
|
||||
while.outer final == 0 {
|
||||
while this.n_bits < 3,
|
||||
post this.n_bits >= 3,
|
||||
post this.n_bits >= 3,
|
||||
{
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
this.bits |= b0 << (this.n_bits & 3)
|
||||
@@ -395,7 +395,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
bits = this.bits
|
||||
n_bits = this.n_bits
|
||||
while n_bits < 14,
|
||||
post n_bits >= 14,
|
||||
post n_bits >= 14,
|
||||
{
|
||||
b0 = args.src.read_u8_as_u32?()
|
||||
bits |= b0 << n_bits
|
||||
@@ -419,8 +419,8 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
i = 0
|
||||
while i < n_clen {
|
||||
while n_bits < 3,
|
||||
inv i < n_clen,
|
||||
post n_bits >= 3,
|
||||
inv i < n_clen,
|
||||
post n_bits >= 3,
|
||||
{
|
||||
b1 = args.src.read_u8_as_u32?()
|
||||
bits |= b1 << n_bits
|
||||
@@ -449,7 +449,7 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
|
||||
// Decode a clcode symbol from H-CL.
|
||||
while true,
|
||||
inv i < 320,
|
||||
inv i < 320,
|
||||
{
|
||||
table_entry = this.huffs[0][bits & mask]
|
||||
table_entry_n_bits = table_entry & 15
|
||||
@@ -503,9 +503,9 @@ pri func decoder.init_dynamic_huffman?(src: base.io_reader) {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
while n_bits < n_extra_bits,
|
||||
inv i < 320,
|
||||
inv rep_count <= 11,
|
||||
post n_bits >= n_extra_bits,
|
||||
inv i < 320,
|
||||
inv rep_count <= 11,
|
||||
post n_bits >= n_extra_bits,
|
||||
{
|
||||
assert n_bits < 7 via "a < b: a < c; c <= b"(c: n_extra_bits)
|
||||
b3 = args.src.read_u8_as_u32?()
|
||||
@@ -643,7 +643,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
// As a special case, allow a degenerate H-D Huffman table, with only
|
||||
// one 1-bit code.
|
||||
if (args.which == 1) and (counts[1] == 1) and
|
||||
(((counts[0] as base.u32) + args.n_codes0 + 1) == args.n_codes1) {
|
||||
(((counts[0] as base.u32) + args.n_codes0 + 1) == args.n_codes1) {
|
||||
|
||||
i = 0
|
||||
while i <= 29 {
|
||||
@@ -708,7 +708,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
// - offsets[5] = 10, formerly 8
|
||||
i = args.n_codes0
|
||||
while i < args.n_codes1,
|
||||
inv n_symbols <= 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c: args.n_codes1)
|
||||
// TODO: this if check should be unnecessary.
|
||||
@@ -732,7 +732,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
// - max_cl = 5
|
||||
min_cl = 1
|
||||
while true,
|
||||
inv n_symbols <= 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
if counts[min_cl] <> 0 {
|
||||
break
|
||||
@@ -744,7 +744,7 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
} endwhile
|
||||
max_cl = 15
|
||||
while true,
|
||||
inv n_symbols <= 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
if counts[max_cl] <> 0 {
|
||||
break
|
||||
@@ -793,9 +793,9 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
key = 0
|
||||
value = 0
|
||||
while true,
|
||||
pre code < (1 << 15),
|
||||
pre i < 288,
|
||||
inv n_symbols <= 288,
|
||||
pre code < (1 << 15),
|
||||
pre i < 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
@@ -827,10 +827,10 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
remaining = (1 as base.u32) << cl
|
||||
j = prev_cl
|
||||
while j <= 15,
|
||||
inv cl <= 9,
|
||||
inv code < (1 << 15),
|
||||
inv i < 288,
|
||||
inv n_symbols <= 288,
|
||||
inv cl <= 9,
|
||||
inv code < (1 << 15),
|
||||
inv i < 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
if remaining <= (counts[j] as base.u32) {
|
||||
break
|
||||
@@ -892,9 +892,9 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
high_bits = initial_high_bits
|
||||
delta = (1 as base.u32) << cl
|
||||
while high_bits >= delta,
|
||||
inv code < (1 << 15),
|
||||
inv i < 288,
|
||||
inv n_symbols <= 288,
|
||||
inv code < (1 << 15),
|
||||
inv i < 288,
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
high_bits -= delta
|
||||
if (top + ((high_bits | reversed_key) & 511)) >= HUFFS_TABLE_SIZE {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// the "choose cpu_arch >= x86_bmi2". Unsurprisingly, having Bit Manipulation
|
||||
// Instructions available to the compiler can help this function's performance.
|
||||
pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader) base.status,
|
||||
choose cpu_arch >= x86_bmi2,
|
||||
choose cpu_arch >= x86_bmi2,
|
||||
{
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
@@ -108,7 +108,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
table_entry = this.huffs[0][
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
@@ -162,7 +162,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
table_entry = this.huffs[1][
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
@@ -193,7 +193,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
// its presence minimizes the diff between decode_huffman_fastxx and
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
pre args.dst.length() >= 266,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
@@ -226,15 +226,15 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
return "#internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
@@ -255,15 +255,15 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
// what was previously in the writer buffer.
|
||||
if (dist_minus_1 + 1) >= 8 {
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else if (dist_minus_1 + 1) == 1 {
|
||||
// (distance == 1) is essentially RLE (Run Length Encoding). It
|
||||
// happens often enough that it's worth special-casing.
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else {
|
||||
args.dst.limited_copy_u32_from_history_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
@@ -283,7 +283,7 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
while n_bits >= 8,
|
||||
post n_bits < 8,
|
||||
post n_bits < 8,
|
||||
{
|
||||
n_bits -= 8
|
||||
if args.src.can_undo_byte() {
|
||||
|
||||
@@ -298,7 +298,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// its presence minimizes the diff between decode_huffman_fastxx and
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
pre args.dst.length() >= 266,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
@@ -331,15 +331,15 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
return "#internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
@@ -360,10 +360,10 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// what was previously in the writer buffer.
|
||||
if (dist_minus_1 + 1) >= 8 {
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else {
|
||||
args.dst.limited_copy_u32_from_history_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
@@ -380,7 +380,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
// even if conceptually, this function was responsible for reading the
|
||||
// bytes we want to rewind.
|
||||
while n_bits >= 8,
|
||||
post n_bits < 8,
|
||||
post n_bits < 8,
|
||||
{
|
||||
n_bits -= 8
|
||||
if args.src.can_undo_byte() {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// TODO: describe how the xxx_fastxx version differs from the xxx_slow one, the
|
||||
// assumptions that xxx_fastxx makes, and how that makes it fast.
|
||||
pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader) base.status,
|
||||
choosy,
|
||||
choosy,
|
||||
{
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
@@ -107,7 +107,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
table_entry = this.huffs[0][
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
@@ -161,7 +161,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
table_entry = this.huffs[1][
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
@@ -192,7 +192,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
// its presence minimizes the diff between decode_huffman_fastxx and
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
pre args.dst.length() >= 266,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
@@ -225,15 +225,15 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
return "#internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
@@ -254,15 +254,15 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
// what was previously in the writer buffer.
|
||||
if (dist_minus_1 + 1) >= 8 {
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else if (dist_minus_1 + 1) == 1 {
|
||||
// (distance == 1) is essentially RLE (Run Length Encoding). It
|
||||
// happens often enough that it's worth special-casing.
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else {
|
||||
args.dst.limited_copy_u32_from_history_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
@@ -282,7 +282,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
while n_bits >= 8,
|
||||
post n_bits < 8,
|
||||
post n_bits < 8,
|
||||
{
|
||||
n_bits -= 8
|
||||
if args.src.can_undo_byte() {
|
||||
|
||||
@@ -124,7 +124,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
if table_entry_n_bits > 0 {
|
||||
while n_bits < table_entry_n_bits,
|
||||
post n_bits >= table_entry_n_bits,
|
||||
post n_bits >= table_entry_n_bits,
|
||||
{
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
|
||||
b2 = args.src.read_u8_as_u32?()
|
||||
@@ -189,7 +189,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
if table_entry_n_bits > 0 {
|
||||
while n_bits < table_entry_n_bits,
|
||||
post n_bits >= table_entry_n_bits,
|
||||
post n_bits >= table_entry_n_bits,
|
||||
{
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
|
||||
b5 = args.src.read_u8_as_u32?()
|
||||
@@ -223,7 +223,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if n_copied < hlen {
|
||||
assert n_copied < length via "a < b: a < c; c <= b"(c: hlen)
|
||||
assert length > n_copied via "a > b: b < a"()
|
||||
@@ -241,7 +241,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
|
||||
// Copy from args.dst.
|
||||
n_copied = args.dst.limited_copy_u32_from_history!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
if length <= n_copied {
|
||||
continue.loop
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user