Files
wuffs/std/bzip2/decode_flush_fast.wuffs
T
Nigel Tao 66f194f7e0 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)
2022-05-24 11:50:48 +10:00

76 lines
2.3 KiB
Plaintext

// 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
}
}