From 32462a072cb63fda5e84e9f372f7690a3eb691e4 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Tue, 23 Jun 2015 16:38:18 +0200 Subject: [PATCH] Speedup to HuffmanCostCombinedCount ~3% speedup for lossless encoding Improves compression ratio by ~0.03% Change-Id: Ic6d05fb0b1099b5ca56689b92b1c6515d54a5d6b --- src/dsp/lossless_enc.c | 16 +++++----------- src/dsp/lossless_enc_mips32.c | 23 ++++++++--------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/dsp/lossless_enc.c b/src/dsp/lossless_enc.c index d20ce1f8..54670fe5 100644 --- a/src/dsp/lossless_enc.c +++ b/src/dsp/lossless_enc.c @@ -1143,24 +1143,18 @@ static VP8LStreaks HuffmanCostCombinedCount(const uint32_t* X, const uint32_t* Y, int length) { int i; int streak = 0; + uint32_t xy_prev = 0xffffffff; VP8LStreaks stats; memset(&stats, 0, sizeof(stats)); - for (i = 0; i < length - 1; ++i) { - const int xy = X[i] + Y[i]; - const int xy_next = X[i + 1] + Y[i + 1]; + for (i = 0; i < length; ++i) { + const uint32_t xy = X[i] + Y[i]; ++streak; - if (xy == xy_next) { - continue; - } + if (xy != xy_prev) { stats.counts[xy != 0] += (streak > 3); stats.streaks[xy != 0][(streak > 3)] += streak; streak = 0; + xy_prev = xy; } - { - const int xy = X[i] + Y[i]; - ++streak; - stats.counts[xy != 0] += (streak > 3); - stats.streaks[xy != 0][(streak > 3)] += streak; } return stats; } diff --git a/src/dsp/lossless_enc_mips32.c b/src/dsp/lossless_enc_mips32.c index 922d88e7..c4cdd908 100644 --- a/src/dsp/lossless_enc_mips32.c +++ b/src/dsp/lossless_enc_mips32.c @@ -245,29 +245,22 @@ static VP8LStreaks HuffmanCostCombinedCount(const uint32_t* X, const uint32_t* Y, int length) { int i; int streak = 0; + uint32_t xy_prev = 0xffffffff; VP8LStreaks stats; int* const pstreaks = &stats.streaks[0][0]; int* const pcnts = &stats.counts[0]; int temp0, temp1, temp2, temp3; memset(&stats, 0, sizeof(stats)); - for (i = 0; i < length - 1; ++i) { - const uint32_t xy = X[i] + Y[i]; - const uint32_t xy_next = X[i + 1] + Y[i + 1]; - ++streak; - if (xy == xy_next) { - continue; - } - temp0 = (xy != 0); - HUFFMAN_COST_PASS - streak = 0; - } - { + for (i = 0; i < length; ++i) { const uint32_t xy = X[i] + Y[i]; ++streak; - temp0 = (xy != 0); - HUFFMAN_COST_PASS + if (xy != xy_prev) { + temp0 = (xy != 0); + HUFFMAN_COST_PASS + streak = 0; + xy_prev = xy; + } } - return stats; }