summaryrefslogtreecommitdiff
path: root/apps/codecs/demac/libdemac/entropy.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/demac/libdemac/entropy.c')
-rw-r--r--apps/codecs/demac/libdemac/entropy.c17
1 files changed, 9 insertions, 8 deletions
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)
283{ 283{
284 rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5); 284 rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5);
285 285
286 if (rice->k == 0) { 286 if (UNLIKELY(rice->k == 0)) {
287 rice->k = 1; 287 rice->k = 1;
288 } else { 288 } else {
289 uint32_t lim = 1 << (rice->k + 4); 289 uint32_t lim = 1 << (rice->k + 4);
290 if (rice->ksum < lim) { 290 if (UNLIKELY(rice->ksum < lim)) {
291 rice->k--; 291 rice->k--;
292 } else if (rice->ksum >= 2 * lim) { 292 } else if (UNLIKELY(rice->ksum >= 2 * lim)) {
293 rice->k++; 293 rice->k++;
294 } 294 }
295 } 295 }
@@ -300,11 +300,12 @@ static inline int entropy_decode3980(struct rice_t* rice)
300 int base, x, pivot, overflow; 300 int base, x, pivot, overflow;
301 301
302 pivot = rice->ksum >> 5; 302 pivot = rice->ksum >> 5;
303 if (pivot == 0) pivot=1; 303 if (UNLIKELY(pivot == 0))
304 pivot=1;
304 305
305 overflow = range_get_symbol_3980(); 306 overflow = range_get_symbol_3980();
306 307
307 if (overflow == (MODEL_ELEMENTS-1)) { 308 if (UNLIKELY(overflow == (MODEL_ELEMENTS-1))) {
308 overflow = range_decode_short() << 16; 309 overflow = range_decode_short() << 16;
309 overflow |= range_decode_short(); 310 overflow |= range_decode_short();
310 } 311 }
@@ -352,7 +353,7 @@ static inline int entropy_decode3970(struct rice_t* rice)
352 353
353 int overflow = range_get_symbol_3970(); 354 int overflow = range_get_symbol_3970();
354 355
355 if (overflow == (MODEL_ELEMENTS - 1)) { 356 if (UNLIKELY(overflow == (MODEL_ELEMENTS - 1))) {
356 tmpk = range_decode_bits(5); 357 tmpk = range_decode_bits(5);
357 overflow = 0; 358 overflow = 0;
358 } else { 359 } else {
@@ -435,13 +436,13 @@ int ICODE_ATTR_DEMAC entropy_decode(struct ape_ctx_t* ape_ctx,
435 memset(decoded1, 0, blockstodecode * sizeof(int32_t)); 436 memset(decoded1, 0, blockstodecode * sizeof(int32_t));
436 } else { 437 } else {
437 if (ape_ctx->fileversion > 3970) { 438 if (ape_ctx->fileversion > 3970) {
438 while (blockstodecode--) { 439 while (LIKELY(blockstodecode--)) {
439 *(decoded0++) = entropy_decode3980(&riceY); 440 *(decoded0++) = entropy_decode3980(&riceY);
440 if (decoded1 != NULL) 441 if (decoded1 != NULL)
441 *(decoded1++) = entropy_decode3980(&riceX); 442 *(decoded1++) = entropy_decode3980(&riceX);
442 } 443 }
443 } else { 444 } else {
444 while (blockstodecode--) { 445 while (LIKELY(blockstodecode--)) {
445 *(decoded0++) = entropy_decode3970(&riceY); 446 *(decoded0++) = entropy_decode3970(&riceY);
446 if (decoded1 != NULL) 447 if (decoded1 != NULL)
447 *(decoded1++) = entropy_decode3970(&riceX); 448 *(decoded1++) = entropy_decode3970(&riceX);