Add a reader1.unread_u8 method.

Also re-enable a number of std/flate tests and benchmarks.

It's not an optimization per se, but as a data point, here are some
benchmark numbers between 36a93fa and this commit. 36a93fa is "36a93fa
Add a TODO about impure functions", which is one commit before "f968950
Read bits up front in decode_huffman_fast", and f968950 was the commit
that made decode_huffman_fast read more than one byte at a time.

name                             old speed      new speed       delta

puffs_adler32_10k/clang          2.45GB/s ± 0%   2.45GB/s ± 0%     ~     (p=0.684 n=10+10)
puffs_adler32_100k/clang         2.45GB/s ± 0%   2.46GB/s ± 0%   +0.07%  (p=0.019 n=10+10)
puffs_flate_decode_1k/clang       124MB/s ± 0%    132MB/s ± 0%   +6.06%  (p=0.000 n=10+10)
puffs_flate_decode_10k/clang      145MB/s ± 0%    174MB/s ± 0%  +20.19%  (p=0.000 n=9+10)
puffs_flate_decode_100k/clang     168MB/s ± 0%    208MB/s ± 0%  +23.31%  (p=0.000 n=10+10)
puffs_zlib_decode_10k/clang       136MB/s ± 0%    162MB/s ± 0%  +18.94%  (p=0.000 n=10+9)
puffs_zlib_decode_100k/clang      158MB/s ± 0%    192MB/s ± 0%  +21.58%  (p=0.000 n=10+9)

puffs_adler32_10k/gcc            3.26GB/s ± 0%   3.26GB/s ± 0%     ~     (p=0.631 n=10+10)
puffs_adler32_100k/gcc           3.27GB/s ± 0%   3.27GB/s ± 0%     ~     (p=0.237 n=10+8)
puffs_flate_decode_1k/gcc        95.3MB/s ± 0%  105.5MB/s ± 0%  +10.67%  (p=0.000 n=10+10)
puffs_flate_decode_10k/gcc        110MB/s ± 0%    140MB/s ± 0%  +27.32%  (p=0.000 n=9+9)
puffs_flate_decode_100k/gcc       121MB/s ± 0%    150MB/s ± 0%  +24.02%  (p=0.000 n=8+10)
puffs_zlib_decode_10k/gcc         112MB/s ± 0%    120MB/s ± 0%   +6.96%  (p=0.000 n=10+9)
puffs_zlib_decode_100k/gcc        123MB/s ± 0%    134MB/s ± 0%   +8.93%  (p=0.000 n=9+8)
This commit is contained in:
Nigel Tao committed 2017-11-05 15:59:02 +11:00
1 parent 6621526a2c
commit 13731f989f
7 files changed
+38 -16

No files matched your search

+9
View File
@@ -459,6 +459,15 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
}
b.printf(" = *%srptr_src++;\n", bPrefix)
} else if isInSrc(g.tm, n, t.KeyUnreadU8, 0) {
if !n.ProvenNotToSuspend() {
b.printf("if (%srptr_src == %srstart_src) { status = %sERROR_INVALID_I_O_OPERATION;",
bPrefix, bPrefix, g.PKGPREFIX)
b.writes("goto exit;")
b.writes("}\n")
}
b.printf("%srptr_src--;\n", bPrefix)
} else if isInSrc(g.tm, n, t.KeyReadU16BE, 0) {
return g.writeReadUXX(b, n, "src", 16, "be")
+6
View File
@@ -2349,6 +2349,12 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
label_0_break:;
while (v_n_bits >= 8) {
v_n_bits -= 8;
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
if (b_rptr_src == b_rstart_src) {
status = PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION;
goto exit;
}
b_rptr_src--;
}
self->private_impl.f_bits = v_bits;
self->private_impl.f_n_bits = v_n_bits;
+7 -3
View File
@@ -734,7 +734,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeyUnreadU8, 0) ||
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) ||
@@ -1170,7 +1170,8 @@ func (q *checker) bcheckIOMethods(n *a.Expr, depth uint32) error {
return nil
}
// Figure out the "receiver" in "receiver.read_u8?()".
// Figure out the "receiver" in "receiver.read_xxx?()", for some I/O method
// "read_xxx".
if n.ID0().Key() != t.KeyOpenParen {
return nil
}
@@ -1179,7 +1180,10 @@ func (q *checker) bcheckIOMethods(n *a.Expr, depth uint32) error {
return nil
}
advance := (*big.Int)(nil)
if key := receiver.ID1().Key(); key < t.Key(len(ioMethodAdvances)) {
if key := receiver.ID1().Key(); key == t.KeyUnreadU8 {
// TODO: call SetProvenNotToSuspend, since unread_u8 can never suspend,
// only succeed or fail.
} else if key < t.Key(len(ioMethodAdvances)) {
advance = ioMethodAdvances[key]
}
if advance == nil {
+1 -1
View File
@@ -407,7 +407,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
// require a TypeExpr being able to express function and method types.
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeyUnreadU8, 0) ||
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) ||
+5
View File
@@ -150,6 +150,8 @@ func (t Token) IsXAssociativeOp() bool { return t.ID.Key().isXOp() && t.ID.IsAss
//
// "Squiggly" means a sequence of non-alpha-numeric characters, such as "+" and
// "&=". Their Keys range in [0x01, 0x7F].
//
// TODO: re-pack the keys.
const nBuiltInKeys = Key(256)
const (
@@ -301,6 +303,7 @@ const (
KeyPrefix = Key(IDPrefix >> KeyShift)
KeySuffix = Key(IDSuffix >> KeyShift)
KeyLimit = Key(IDLimit >> KeyShift)
KeyUnreadU8 = Key(IDUnreadU8 >> KeyShift)
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
@@ -488,6 +491,7 @@ const (
IDPrefix = ID(0xCB<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDSuffix = ID(0xCC<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDLimit = ID(0xCD<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDUnreadU8 = ID(0xCE<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
)
// The IDXFoo IDs are not returned by the tokenizer. They are used by the
@@ -693,6 +697,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
KeyPrefix: {"prefix", IDPrefix},
KeySuffix: {"suffix", IDSuffix},
KeyLimit: {"limit", IDLimit},
KeyUnreadU8: {"unread_u8", IDUnreadU8},
}
var builtInsByName = map[string]ID{}
+1 -1
View File
@@ -306,7 +306,7 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// function is ProvenNotToSuspend?
while n_bits >= 8 {
n_bits -= 8
// TODO: in.src.unread_u8?()
in.src.unread_u8?()
}
this.bits = bits
+9 -11
View File
@@ -877,18 +877,17 @@ proc tests[] = {
test_puffs_flate_decode_flate_backref_crosses_blocks, //
test_puffs_flate_decode_midsummer, //
test_puffs_flate_decode_pi, //
// TODO: uncomment.
//test_puffs_flate_decode_pi_many_big_reads, //
//test_puffs_flate_decode_pi_many_medium_reads, //
//test_puffs_flate_decode_pi_many_small_writes_reads, //
//test_puffs_flate_decode_romeo, //
//test_puffs_flate_decode_romeo_fixed, //
test_puffs_flate_decode_pi_many_big_reads, //
test_puffs_flate_decode_pi_many_medium_reads, //
test_puffs_flate_decode_pi_many_small_writes_reads, //
test_puffs_flate_decode_romeo, //
test_puffs_flate_decode_romeo_fixed, //
test_puffs_flate_decode_split_src, //
test_puffs_flate_history_full, //
test_puffs_flate_history_partial, //
test_puffs_flate_table_redirect, //
//test_puffs_zlib_checksum_mismatch, //
//test_puffs_zlib_decode_midsummer, //
test_puffs_zlib_checksum_mismatch, //
test_puffs_zlib_decode_midsummer, //
test_puffs_zlib_decode_pi, //
#ifdef PUFFS_MIMIC
@@ -915,11 +914,10 @@ proc benches[] = {
// Flate Benches
bench_puffs_adler32_10k, //
bench_puffs_adler32_100k, //
// TODO: uncomment.
//bench_puffs_flate_decode_1k, //
bench_puffs_flate_decode_1k, //
bench_puffs_flate_decode_10k, //
bench_puffs_flate_decode_100k, //
//bench_puffs_zlib_decode_10k, //
bench_puffs_zlib_decode_10k, //
bench_puffs_zlib_decode_100k, //
#ifdef PUFFS_MIMIC