mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Introduce std/bzip2 decoder.flush_fast method
Compared to the recent commit 623290ef "Cache std/bzip2 Huffman tree
lookup":
name old speed new speed delta
wuffs_bzip2_decode_10k/clang11 60.5MB/s ± 0% 60.5MB/s ± 0% ~ (p=1.000 n=5+5)
wuffs_bzip2_decode_100k/clang11 46.7MB/s ± 1% 45.7MB/s ± 1% -2.05% (p=0.008 n=5+5)
wuffs_bzip2_decode_10k/gcc10 58.7MB/s ± 0% 58.5MB/s ± 0% ~ (p=0.222 n=5+5)
wuffs_bzip2_decode_100k/gcc10 46.9MB/s ± 0% 46.3MB/s ± 0% -1.46% (p=0.008 n=5+5)
This commit is contained in:
1 parent
29eec43287
commit
66f194f7e0
4 files changed
+309
-106
No files matched your search
@@ -43,7 +43,12 @@ pub struct decoder? implements base.io_transformer(
|
||||
decode_huffman_section : base.u32,
|
||||
decode_huffman_run_shift : base.u32[..= 23],
|
||||
|
||||
flush_pointer : base.u32[..= 1_048575],
|
||||
flush_repeat_count : base.u32[..= 255],
|
||||
flush_prev : base.u8,
|
||||
|
||||
final_checksum_have : base.u32,
|
||||
block_checksum_have : base.u32,
|
||||
block_checksum_want : base.u32,
|
||||
original_pointer : base.u32,
|
||||
num_symbols : base.u32[..= 258],
|
||||
@@ -174,7 +179,31 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
} endwhile
|
||||
|
||||
this.invert_bwt!()
|
||||
this.flush_block?(dst: args.dst)
|
||||
|
||||
this.block_checksum_have = 0xFFFF_FFFF
|
||||
if this.original_pointer >= this.block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert this.original_pointer < 900000 via "a < b: a < c; c <= b"(c: this.block_size)
|
||||
this.flush_pointer = this.bwt[this.original_pointer] >> 12
|
||||
this.flush_repeat_count = 0
|
||||
this.flush_prev = 0
|
||||
|
||||
while this.block_size > 0 {
|
||||
this.flush_fast!(dst: args.dst)
|
||||
if this.block_size <= 0 {
|
||||
break
|
||||
}
|
||||
this.flush_slow?(dst: args.dst)
|
||||
} endwhile
|
||||
|
||||
this.block_checksum_have ^= 0xFFFF_FFFF
|
||||
if this.block_checksum_have <> this.block_checksum_want {
|
||||
return "#bad checksum"
|
||||
}
|
||||
this.final_checksum_have = this.block_checksum_have ^ (
|
||||
(this.final_checksum_have >> 31) |
|
||||
(this.final_checksum_have ~mod<< 1))
|
||||
} endwhile
|
||||
|
||||
// Read the 32-bit final checksum.
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.flush_fast!(dst: base.io_writer) {
|
||||
var flush_pointer : base.u32[..= 1_048575]
|
||||
var flush_repeat_count : base.u32[..= 255]
|
||||
var flush_prev : base.u8
|
||||
var block_checksum_have : base.u32
|
||||
var block_size : base.u32
|
||||
|
||||
var entry : base.u32
|
||||
var curr : base.u8
|
||||
|
||||
flush_pointer = this.flush_pointer
|
||||
flush_repeat_count = this.flush_repeat_count
|
||||
flush_prev = this.flush_prev
|
||||
block_checksum_have = this.block_checksum_have
|
||||
block_size = this.block_size
|
||||
|
||||
while (block_size > 0) and (args.dst.length() > 255) {
|
||||
entry = this.bwt[flush_pointer]
|
||||
curr = (entry & 0xFF) as base.u8
|
||||
flush_pointer = entry >> 12
|
||||
|
||||
if flush_repeat_count >= 4 {
|
||||
flush_repeat_count = curr as base.u32
|
||||
while flush_repeat_count > 0,
|
||||
inv block_size > 0,
|
||||
{
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ flush_prev] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
if args.dst.length() > 0 {
|
||||
args.dst.write_u8_fast!(a: flush_prev)
|
||||
}
|
||||
flush_repeat_count -= 1
|
||||
} endwhile
|
||||
flush_repeat_count = 0
|
||||
} else if curr <> flush_prev {
|
||||
flush_repeat_count = 1
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8_fast!(a: curr)
|
||||
} else {
|
||||
flush_repeat_count += 1
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8_fast!(a: curr)
|
||||
}
|
||||
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
} endwhile
|
||||
|
||||
this.flush_pointer = flush_pointer
|
||||
this.flush_repeat_count = flush_repeat_count
|
||||
this.flush_prev = flush_prev
|
||||
this.block_checksum_have = block_checksum_have
|
||||
if block_size <= 900000 {
|
||||
this.block_size = block_size
|
||||
}
|
||||
}
|
||||
@@ -12,65 +12,62 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.flush_block?(dst: base.io_writer) {
|
||||
var i : base.u32[..= 1_048575]
|
||||
var n : base.u32
|
||||
var entry : base.u32
|
||||
var repeat_count : base.u32[..= 255]
|
||||
pri func decoder.flush_slow?(dst: base.io_writer) {
|
||||
var flush_pointer : base.u32[..= 1_048575]
|
||||
var flush_repeat_count : base.u32[..= 255]
|
||||
var flush_prev : base.u8
|
||||
var block_checksum_have : base.u32
|
||||
var prev : base.u8
|
||||
var curr : base.u8
|
||||
var block_size : base.u32
|
||||
|
||||
if this.original_pointer >= this.block_size {
|
||||
return "#bad block length"
|
||||
}
|
||||
assert this.original_pointer < 900000 via "a < b: a < c; c <= b"(c: this.block_size)
|
||||
i = this.bwt[this.original_pointer] >> 12
|
||||
var entry : base.u32
|
||||
var curr : base.u8
|
||||
|
||||
block_checksum_have = 0xFFFF_FFFF
|
||||
flush_pointer = this.flush_pointer
|
||||
flush_repeat_count = this.flush_repeat_count
|
||||
flush_prev = this.flush_prev
|
||||
block_checksum_have = this.block_checksum_have
|
||||
block_size = this.block_size
|
||||
|
||||
n = 0
|
||||
while n < this.block_size {
|
||||
assert n < 900000 via "a < b: a < c; c <= b"(c: this.block_size)
|
||||
entry = this.bwt[i]
|
||||
while (block_size > 0) and (not coroutine_resumed) {
|
||||
entry = this.bwt[flush_pointer]
|
||||
curr = (entry & 0xFF) as base.u8
|
||||
i = entry >> 12
|
||||
flush_pointer = entry >> 12
|
||||
|
||||
if repeat_count >= 4 {
|
||||
repeat_count = curr as base.u32
|
||||
while repeat_count > 0,
|
||||
inv n < 900000,
|
||||
if flush_repeat_count >= 4 {
|
||||
flush_repeat_count = curr as base.u32
|
||||
while flush_repeat_count > 0,
|
||||
inv block_size > 0,
|
||||
{
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ prev] ^
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ flush_prev] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8?(a: prev)
|
||||
repeat_count -= 1
|
||||
args.dst.write_u8?(a: flush_prev)
|
||||
flush_repeat_count -= 1
|
||||
} endwhile
|
||||
repeat_count = 0
|
||||
} else if curr <> prev {
|
||||
repeat_count = 1
|
||||
flush_repeat_count = 0
|
||||
} else if curr <> flush_prev {
|
||||
flush_repeat_count = 1
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8?(a: curr)
|
||||
} else {
|
||||
repeat_count += 1
|
||||
flush_repeat_count += 1
|
||||
block_checksum_have =
|
||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||
(block_checksum_have ~mod<< 8)
|
||||
args.dst.write_u8?(a: curr)
|
||||
}
|
||||
|
||||
prev = curr
|
||||
n += 1
|
||||
flush_prev = curr
|
||||
block_size -= 1
|
||||
} endwhile
|
||||
|
||||
block_checksum_have ^= 0xFFFF_FFFF
|
||||
if block_checksum_have <> this.block_checksum_want {
|
||||
return "#bad checksum"
|
||||
this.flush_pointer = flush_pointer
|
||||
this.flush_repeat_count = flush_repeat_count
|
||||
this.flush_prev = flush_prev
|
||||
this.block_checksum_have = block_checksum_have
|
||||
if block_size <= 900000 {
|
||||
this.block_size = block_size
|
||||
}
|
||||
this.final_checksum_have = block_checksum_have ^ (
|
||||
(this.final_checksum_have >> 31) |
|
||||
(this.final_checksum_have ~mod<< 1))
|
||||
}
|
||||
Reference in new issue
Block a user