Read bits up front in decode_huffman_fast.

name                           old speed      new speed       delta

puffs_adler32_10k/clang        2.36GB/s ± 4%   2.38GB/s ± 2%     ~     (p=1.000 n=5+5)
puffs_adler32_100k/clang       2.39GB/s ± 4%   2.39GB/s ± 1%     ~     (p=0.841 n=5+5)
puffs_flate_decode_1k/clang     121MB/s ± 1%    129MB/s ± 2%   +5.95%  (p=0.008 n=5+5)
puffs_flate_decode_10k/clang    138MB/s ± 3%    161MB/s ± 1%  +16.52%  (p=0.008 n=5+5)
puffs_flate_decode_100k/clang   163MB/s ± 4%    187MB/s ± 3%  +14.50%  (p=0.008 n=5+5)
puffs_zlib_decode_10k/clang     132MB/s ± 2%    150MB/s ± 1%  +13.92%  (p=0.008 n=5+5)
puffs_zlib_decode_100k/clang    152MB/s ± 6%    174MB/s ± 1%  +14.60%  (p=0.008 n=5+5)

puffs_adler32_10k/gcc          3.25GB/s ± 0%   3.12GB/s ± 3%   -4.06%  (p=0.008 n=5+5)
puffs_adler32_100k/gcc         3.25GB/s ± 0%   3.12GB/s ± 3%   -3.99%  (p=0.008 n=5+5)
puffs_flate_decode_1k/gcc      95.1MB/s ± 0%  127.7MB/s ± 3%  +34.25%  (p=0.008 n=5+5)
puffs_flate_decode_10k/gcc      110MB/s ± 0%    172MB/s ± 4%  +55.66%  (p=0.008 n=5+5)
puffs_flate_decode_100k/gcc     121MB/s ± 0%    196MB/s ± 2%  +61.45%  (p=0.008 n=5+5)
puffs_zlib_decode_10k/gcc       112MB/s ± 0%    164MB/s ± 1%  +46.14%  (p=0.008 n=5+5)
puffs_zlib_decode_100k/gcc      123MB/s ± 0%    186MB/s ± 0%  +51.22%  (p=0.016 n=5+4)
This commit is contained in:
Nigel Tao committed 2017-11-04 17:37:54 +11:00
1 parent 36a93fa6b7
commit f968950345
3 files changed
+206 -29

No files matched your search

+25 -1
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// TODO: describe how the xxx_fast version differs from the xxx_slow one, the
// assumptions that xxx_fast makes, and how that makes it fast.
pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// When editing this function, consider making the equivalent change to the
// decode_huffman_slow function. Keep the diff between the two
@@ -21,14 +23,34 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
var bits u32 = this.bits
var n_bits u32 = this.n_bits
// TODO: check that n_bits < 8?
var table_entry u32
var table_entry_n_bits u32[..15]
var lmask u32[..511] = ((1 as u32) << this.n_huffs_bits[0]) - 1
var dmask u32[..511] = ((1 as u32) << this.n_huffs_bits[1]) - 1
while:loop in.src.available() >= 6 {
// Ensure that we have at least 15 bits of input.
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= (in.src.read_u8?() as u32) << n_bits
n_bits += 8
bits |= (in.src.read_u8?() as u32) << n_bits
n_bits += 8
assert n_bits >= 15
} else {
assert in.src.available() >= 4
}
// These assertions are redundant, but are listed explicitly for
// clarity. They must hold regardless of which branch was taken for the
// if statement above.
assert in.src.available() >= 4
assert n_bits >= 15
// Decode an lcode symbol from H-L.
while true {
while true { // TODO: drop the while.
table_entry = this.huffs[0][bits & lmask]
table_entry_n_bits = table_entry & 0x0F
if n_bits >= table_entry_n_bits {
@@ -248,6 +270,8 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
}
}
// TODO: unread some in.src bytes if n_bits >= 8?
this.bits = bits
this.n_bits = n_bits
}