mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Rename deflate's "distance minus 1" variable
This commit is contained in:
1 parent
4675efdcc5
commit
26445adcdf
6 files changed
+42
-44
No files matched your search
+20
-20
@@ -318,7 +318,7 @@ typedef struct {
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
@@ -1997,7 +1997,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_fast(
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
@@ -2213,7 +2213,7 @@ label_0_continue:;
|
||||
WUFFS_DEFLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_distance = ((v_table_entry >> 8) & 32767);
|
||||
v_dist_minus_1 = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
if (v_table_entry_n_bits > 0) {
|
||||
if (v_n_bits < 15) {
|
||||
@@ -2228,15 +2228,15 @@ label_0_continue:;
|
||||
}
|
||||
v_n_bits += 8;
|
||||
}
|
||||
v_distance =
|
||||
((v_distance + ((v_bits) & ((1 << (v_table_entry_n_bits)) - 1))) &
|
||||
v_dist_minus_1 =
|
||||
((v_dist_minus_1 + ((v_bits) & ((1 << (v_table_entry_n_bits)) - 1))) &
|
||||
32767);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
v_n_copied = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_distance + 1))) >
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) >
|
||||
((uint64_t)(
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
@@ -2247,7 +2247,7 @@ label_0_continue:;
|
||||
.len))) {
|
||||
v_hlen = 0;
|
||||
v_hdist = ((uint32_t)((
|
||||
((uint64_t)((v_distance + 1))) -
|
||||
((uint64_t)((v_dist_minus_1 + 1))) -
|
||||
((uint64_t)(
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
@@ -2296,7 +2296,7 @@ label_0_continue:;
|
||||
if (v_length == 0) {
|
||||
goto label_0_continue;
|
||||
}
|
||||
if (((uint64_t)((v_distance + 1))) >
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) >
|
||||
((uint64_t)(
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
@@ -2310,7 +2310,7 @@ label_0_continue:;
|
||||
}
|
||||
}
|
||||
wuffs_base__writer1__copy_from_history32__bco(
|
||||
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_distance + 1,
|
||||
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_dist_minus_1 + 1,
|
||||
v_length);
|
||||
goto label_2_break;
|
||||
}
|
||||
@@ -2376,7 +2376,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
@@ -2428,7 +2428,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_redir_top = self->private_impl.c_decode_huffman_slow[0].v_redir_top;
|
||||
v_redir_mask = self->private_impl.c_decode_huffman_slow[0].v_redir_mask;
|
||||
v_length = self->private_impl.c_decode_huffman_slow[0].v_length;
|
||||
v_distance = self->private_impl.c_decode_huffman_slow[0].v_distance;
|
||||
v_dist_minus_1 = self->private_impl.c_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_n_copied = self->private_impl.c_decode_huffman_slow[0].v_n_copied;
|
||||
v_hlen = self->private_impl.c_decode_huffman_slow[0].v_hlen;
|
||||
v_hdist = self->private_impl.c_decode_huffman_slow[0].v_hdist;
|
||||
@@ -2620,7 +2620,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
WUFFS_DEFLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_distance = ((v_table_entry >> 8) & 32767);
|
||||
v_dist_minus_1 = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
if (v_table_entry_n_bits > 0) {
|
||||
while (v_n_bits < v_table_entry_n_bits) {
|
||||
@@ -2634,15 +2634,15 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
}
|
||||
v_n_bits += 8;
|
||||
}
|
||||
v_distance =
|
||||
((v_distance + ((v_bits) & ((1 << (v_table_entry_n_bits)) - 1))) &
|
||||
32767);
|
||||
v_dist_minus_1 = ((v_dist_minus_1 +
|
||||
((v_bits) & ((1 << (v_table_entry_n_bits)) - 1))) &
|
||||
32767);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
v_n_copied = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_distance + 1))) >
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) >
|
||||
((uint64_t)(
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
@@ -2653,7 +2653,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
.len))) {
|
||||
v_hlen = 0;
|
||||
v_hdist = ((uint32_t)(
|
||||
(((uint64_t)((v_distance + 1))) -
|
||||
(((uint64_t)((v_dist_minus_1 + 1))) -
|
||||
((uint64_t)(((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
@@ -2722,8 +2722,8 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow(
|
||||
}
|
||||
}
|
||||
v_n_copied = wuffs_base__writer1__copy_from_history32(
|
||||
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_distance + 1,
|
||||
v_length);
|
||||
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst,
|
||||
v_dist_minus_1 + 1, v_length);
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
goto label_7_break;
|
||||
@@ -2762,7 +2762,7 @@ suspend:
|
||||
self->private_impl.c_decode_huffman_slow[0].v_redir_top = v_redir_top;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_length = v_length;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_distance = v_distance;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_n_copied = v_n_copied;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_hlen = v_hlen;
|
||||
self->private_impl.c_decode_huffman_slow[0].v_hdist = v_hdist;
|
||||
|
||||
+1
-1
@@ -327,7 +327,7 @@ typedef struct {
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
|
||||
+1
-1
@@ -318,7 +318,7 @@ typedef struct {
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
|
||||
+1
-1
@@ -327,7 +327,7 @@ typedef struct {
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
|
||||
@@ -245,14 +245,13 @@ pri func decoder.decode_huffman_fast?(dst writer1, src reader1)() {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// distance = base_number_minus_1 + extra_bits.
|
||||
//
|
||||
// TODO: rename distance to dist_minus_1.
|
||||
// dist_minus_1 = base_number_minus_1 + extra_bits.
|
||||
// distance = dist_minus_1 + 1.
|
||||
//
|
||||
// The -1 is from the bias in script/print-deflate-magic-numbers.go.
|
||||
// That bias makes the "& 0x7FFF" 15-ish lines below correct and
|
||||
// undoing that bias makes proving (distance + 1) > 0 trivial.
|
||||
var distance u32[..0x7FFF] = (table_entry >> 8) & 0x7FFF
|
||||
// undoing that bias makes proving (dist_minus_1 + 1) > 0 trivial.
|
||||
var dist_minus_1 u32[..0x7FFF] = (table_entry >> 8) & 0x7FFF
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
if table_entry_n_bits > 0 {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
@@ -267,7 +266,7 @@ pri func decoder.decode_huffman_fast?(dst writer1, src reader1)() {
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert n_bits >= 15
|
||||
|
||||
distance = (distance + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
}
|
||||
@@ -282,13 +281,13 @@ pri func decoder.decode_huffman_fast?(dst writer1, src reader1)() {
|
||||
inv in.dst.is_marked(),
|
||||
{
|
||||
// Copy from this.history.
|
||||
if ((distance + 1) as u64) > in.dst.since_mark().length() {
|
||||
if ((dist_minus_1 + 1) as u64) > in.dst.since_mark().length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from in.dst.
|
||||
var hlen u32[..0x7FFF]
|
||||
var hdist u32 =
|
||||
(((distance + 1) as u64) - in.dst.since_mark().length()) as u32
|
||||
(((dist_minus_1 + 1) as u64) - in.dst.since_mark().length()) as u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
|
||||
@@ -343,23 +342,23 @@ pri func decoder.decode_huffman_fast?(dst writer1, src reader1)() {
|
||||
continue:loop
|
||||
}
|
||||
|
||||
if ((distance + 1) as u64) > in.dst.since_mark().length() {
|
||||
if ((dist_minus_1 + 1) as u64) > in.dst.since_mark().length() {
|
||||
return error "internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert length <= 258
|
||||
assert ((distance + 1) as u64) <= in.dst.since_mark().length()
|
||||
assert ((dist_minus_1 + 1) as u64) <= in.dst.since_mark().length()
|
||||
assert in.dst.available() >= 258
|
||||
assert in.dst.is_marked()
|
||||
|
||||
// We can therefore prove:
|
||||
assert (distance + 1) > 0
|
||||
assert (dist_minus_1 + 1) > 0
|
||||
assert (length as u64) <= 258
|
||||
assert (length as u64) <= in.dst.available() via "a <= b: a <= c; c <= b"(c:258)
|
||||
|
||||
// Copy from in.dst.
|
||||
in.dst.copy_from_history32(distance:(distance + 1), length:length)
|
||||
in.dst.copy_from_history32(distance:(dist_minus_1 + 1), length:length)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,14 +157,13 @@ pri func decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// distance = base_number_minus_1 + extra_bits.
|
||||
//
|
||||
// TODO: rename distance to dist_minus_1.
|
||||
// dist_minus_1 = base_number_minus_1 + extra_bits.
|
||||
// distance = dist_minus_1 + 1.
|
||||
//
|
||||
// The -1 is from the bias in script/print-deflate-magic-numbers.go.
|
||||
// That bias makes the "& 0x7FFF" 15-ish lines below correct and
|
||||
// undoing that bias makes proving (distance + 1) > 0 trivial.
|
||||
var distance u32[..0x7FFF] = (table_entry >> 8) & 0x7FFF
|
||||
// undoing that bias makes proving (dist_minus_1 + 1) > 0 trivial.
|
||||
var dist_minus_1 u32[..0x7FFF] = (table_entry >> 8) & 0x7FFF
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
if table_entry_n_bits > 0 {
|
||||
while n_bits < table_entry_n_bits,
|
||||
@@ -174,7 +173,7 @@ pri func decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
||||
bits |= (in.src.read_u8?() as u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
distance = (distance + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
}
|
||||
@@ -182,13 +181,13 @@ pri func decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
||||
var n_copied u32
|
||||
while true {
|
||||
// Copy from this.history.
|
||||
if ((distance + 1) as u64) > in.dst.since_mark().length() {
|
||||
if ((dist_minus_1 + 1) as u64) > in.dst.since_mark().length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from in.dst.
|
||||
var hlen u32[..0x7FFF]
|
||||
var hdist u32 =
|
||||
(((distance + 1) as u64) - in.dst.since_mark().length()) as u32
|
||||
(((dist_minus_1 + 1) as u64) - in.dst.since_mark().length()) as u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
|
||||
@@ -247,7 +246,7 @@ pri func decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
||||
}
|
||||
|
||||
// Copy from in.dst.
|
||||
n_copied = in.dst.copy_from_history32(distance:(distance + 1), length:length)
|
||||
n_copied = in.dst.copy_from_history32(distance:(dist_minus_1 + 1), length:length)
|
||||
if length <= n_copied {
|
||||
length = 0
|
||||
break
|
||||
|
||||
Reference in new issue
Block a user