From 8b25a3035a39a424b119ef9e5f50a425f9bee042 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 28 Apr 2018 10:25:58 +1000 Subject: [PATCH] Remove another obsolete bounds[0] check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Benchmarks are a little noisy, but they certainly don't look worse. I can't remember why that "if true" performance optimization hack was added in the first place, although my compiler versions have probably upgraded since that hack was added. name old speed new speed delta wuffs_deflate_decode_1k/clang 141MB/s ± 0% 141MB/s ± 2% ~ (p=0.151 n=5+5) wuffs_deflate_decode_10k/clang 210MB/s ± 0% 226MB/s ± 3% +7.68% (p=0.008 n=5+5) wuffs_deflate_decode_100k/clang 230MB/s ± 0% 251MB/s ± 4% +9.28% (p=0.008 n=5+5) wuffs_deflate_decode_1k/gcc 152MB/s ± 1% 151MB/s ± 2% ~ (p=0.841 n=5+5) wuffs_deflate_decode_10k/gcc 251MB/s ± 3% 263MB/s ± 3% +4.75% (p=0.008 n=5+5) wuffs_deflate_decode_100k/gcc 293MB/s ± 3% 302MB/s ± 0% +2.90% (p=0.008 n=5+5) wuffs_lzw_decode_20k/clang 126MB/s ± 0% 127MB/s ± 0% +0.48% (p=0.032 n=5+5) wuffs_lzw_decode_100k/clang 161MB/s ± 4% 163MB/s ± 0% ~ (p=0.151 n=5+5) wuffs_gif_decode_1k/clang 350MB/s ± 1% 354MB/s ± 1% ~ (p=0.056 n=5+5) wuffs_gif_decode_10k/clang 140MB/s ± 0% 140MB/s ± 2% ~ (p=0.841 n=5+5) wuffs_gif_decode_100k/clang 120MB/s ± 1% 121MB/s ± 0% +0.87% (p=0.016 n=5+5) wuffs_gif_decode_1000k/clang 122MB/s ± 2% 124MB/s ± 0% +1.47% (p=0.016 n=5+4) wuffs_lzw_decode_20k/gcc 146MB/s ± 1% 148MB/s ± 3% ~ (p=0.151 n=5+5) wuffs_lzw_decode_100k/gcc 201MB/s ± 3% 207MB/s ± 3% ~ (p=0.095 n=5+5) wuffs_gif_decode_1k/gcc 346MB/s ± 0% 346MB/s ± 1% ~ (p=0.548 n=5+5) wuffs_gif_decode_10k/gcc 125MB/s ± 0% 127MB/s ± 2% ~ (p=0.151 n=5+5) wuffs_gif_decode_100k/gcc 115MB/s ± 1% 117MB/s ± 1% +2.13% (p=0.008 n=5+5) wuffs_gif_decode_1000k/gcc 117MB/s ± 1% 119MB/s ± 0% +2.23% (p=0.016 n=5+4) --- cmd/wuffs-c/internal/cgen/expr.go | 13 ++------ gen/c/std/deflate.c | 54 +++++++++++-------------------- gen/c/std/gzip.c | 21 +++++------- gen/c/std/zlib.c | 4 +-- 4 files changed, 29 insertions(+), 63 deletions(-) diff --git a/cmd/wuffs-c/internal/cgen/expr.go b/cmd/wuffs-c/internal/cgen/expr.go index c114ed27..bf6e6cea 100644 --- a/cmd/wuffs-c/internal/cgen/expr.go +++ b/cmd/wuffs-c/internal/cgen/expr.go @@ -184,19 +184,10 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare return nil } if isInDst(g.tm, n, t.IDSinceMark, 0) { - // Write .len as either "foo ? bar : baz" or "bar". - // - // TODO: drop the "true" in the "if true", provided that the - // benchmark numbers improve. - len0, len1 := "", "" - if true { - len0 = aPrefix + "dst.private_impl.bounds[0] ?" - len1 = ": 0" - } b.printf("((wuffs_base__slice_u8){ "+ ".ptr = %sdst.private_impl.bounds[0], "+ - ".len = %s (size_t)(%swptr_dst - %sdst.private_impl.bounds[0]) %s, })", - aPrefix, len0, bPrefix, aPrefix, len1) + ".len = %swptr_dst - %sdst.private_impl.bounds[0], })", + aPrefix, bPrefix, aPrefix) return nil } if isInDst(g.tm, n, t.IDCopyFromReader32, 2) { diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 8acefa24..11d35d58 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -1836,9 +1836,7 @@ wuffs_deflate__status wuffs_deflate__decoder__decode( } v_written = ((wuffs_base__slice_u8){ .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - a_dst.private_impl.bounds[0]) - : 0, + .len = b_wptr_dst - a_dst.private_impl.bounds[0], }); if (((uint64_t)(v_written.len)) >= 32768) { v_written = wuffs_base__slice_u8_suffix(v_written, 32768); @@ -3138,23 +3136,17 @@ label_0_continue:; if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(((wuffs_base__slice_u8){ .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - - a_dst.private_impl.bounds[0]) - : 0, + .len = b_wptr_dst - a_dst.private_impl.bounds[0], }) .len))) { v_hlen = 0; - v_hdist = ((uint32_t)(( - ((uint64_t)((v_dist_minus_1 + 1))) - - ((uint64_t)(((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - - a_dst.private_impl.bounds[0]) - : 0, - }) - .len))))); + v_hdist = ((uint32_t)( + (((uint64_t)((v_dist_minus_1 + 1))) - + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = b_wptr_dst - a_dst.private_impl.bounds[0], + }) + .len))))); if (v_length > v_hdist) { v_length -= v_hdist; v_hlen = v_hdist; @@ -3198,10 +3190,7 @@ label_0_continue:; if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(((wuffs_base__slice_u8){ .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - - a_dst.private_impl.bounds[0]) - : 0, + .len = b_wptr_dst - a_dst.private_impl.bounds[0], }) .len))) { status = WUFFS_DEFLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE; @@ -3547,24 +3536,17 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow( if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(((wuffs_base__slice_u8){ .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - - a_dst.private_impl.bounds[0]) - : 0, + .len = b_wptr_dst - a_dst.private_impl.bounds[0], }) .len))) { v_hlen = 0; - v_hdist = ((uint32_t)( - (((uint64_t)((v_dist_minus_1 + 1))) - - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - - a_dst.private_impl.bounds[0]) - : 0, - }) - .len))))); + v_hdist = ((uint32_t)(( + ((uint64_t)((v_dist_minus_1 + 1))) - + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = b_wptr_dst - a_dst.private_impl.bounds[0], + }) + .len))))); if (v_length > v_hdist) { v_length -= v_hdist; v_hlen = v_hdist; diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index 0be2b035..30ade335 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -2140,20 +2140,15 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, &self->private_impl.f_checksum, ((wuffs_base__slice_u8){ .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - a_dst.private_impl.bounds[0]) - : 0, + .len = b_wptr_dst - a_dst.private_impl.bounds[0], })); - v_decoded_length_got += ((uint32_t)(( - ((uint64_t)(((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - - a_dst.private_impl.bounds[0]) - : 0, - }) - .len)) & - 4294967295))); + v_decoded_length_got += ((uint32_t)( + (((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = b_wptr_dst - a_dst.private_impl.bounds[0], + }) + .len)) & + 4294967295))); } if (v_z == 0) { goto label_2_break; diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index 0eb1d221..22419dcc 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -2043,9 +2043,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self, &self->private_impl.f_checksum, ((wuffs_base__slice_u8){ .ptr = a_dst.private_impl.bounds[0], - .len = a_dst.private_impl.bounds[0] - ? (size_t)(b_wptr_dst - a_dst.private_impl.bounds[0]) - : 0, + .len = b_wptr_dst - a_dst.private_impl.bounds[0], })); } if (v_z == 0) {