From 3761c0108cbfc6f88c4bf43fc13a38a2f7db0d6f Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Mon, 24 Nov 2008 18:40:49 +0000 Subject: Branch optimisation in both C (giving hints to gcc - verified using -fprofile-arcs and gcov) and asm files. Biggest effect on coldfire (-c1000: +8%, -c2000: +5%), but ARM also profits a bit (less than 1% on ARM7TDMI, around 1% on ARM1136). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19199 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/demac/libdemac/entropy.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'apps/codecs/demac/libdemac/entropy.c') diff --git a/apps/codecs/demac/libdemac/entropy.c b/apps/codecs/demac/libdemac/entropy.c index 54ff226bce..e8561122a7 100644 --- a/apps/codecs/demac/libdemac/entropy.c +++ b/apps/codecs/demac/libdemac/entropy.c @@ -283,13 +283,13 @@ static inline void update_rice(struct rice_t* rice, int x) { rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5); - if (rice->k == 0) { + if (UNLIKELY(rice->k == 0)) { rice->k = 1; } else { uint32_t lim = 1 << (rice->k + 4); - if (rice->ksum < lim) { + if (UNLIKELY(rice->ksum < lim)) { rice->k--; - } else if (rice->ksum >= 2 * lim) { + } else if (UNLIKELY(rice->ksum >= 2 * lim)) { rice->k++; } } @@ -300,11 +300,12 @@ static inline int entropy_decode3980(struct rice_t* rice) int base, x, pivot, overflow; pivot = rice->ksum >> 5; - if (pivot == 0) pivot=1; + if (UNLIKELY(pivot == 0)) + pivot=1; overflow = range_get_symbol_3980(); - if (overflow == (MODEL_ELEMENTS-1)) { + if (UNLIKELY(overflow == (MODEL_ELEMENTS-1))) { overflow = range_decode_short() << 16; overflow |= range_decode_short(); } @@ -352,7 +353,7 @@ static inline int entropy_decode3970(struct rice_t* rice) int overflow = range_get_symbol_3970(); - if (overflow == (MODEL_ELEMENTS - 1)) { + if (UNLIKELY(overflow == (MODEL_ELEMENTS - 1))) { tmpk = range_decode_bits(5); overflow = 0; } else { @@ -435,13 +436,13 @@ int ICODE_ATTR_DEMAC entropy_decode(struct ape_ctx_t* ape_ctx, memset(decoded1, 0, blockstodecode * sizeof(int32_t)); } else { if (ape_ctx->fileversion > 3970) { - while (blockstodecode--) { + while (LIKELY(blockstodecode--)) { *(decoded0++) = entropy_decode3980(&riceY); if (decoded1 != NULL) *(decoded1++) = entropy_decode3980(&riceX); } } else { - while (blockstodecode--) { + while (LIKELY(blockstodecode--)) { *(decoded0++) = entropy_decode3970(&riceY); if (decoded1 != NULL) *(decoded1++) = entropy_decode3970(&riceX); -- cgit v1.2.3