diff options
-rw-r--r-- | apps/codecs/libtremor/codebook.c | 10 | ||||
-rw-r--r-- | apps/plugins/midi/synth.c | 36 | ||||
-rw-r--r-- | apps/plugins/mpegplayer/attributes.h | 8 | ||||
-rw-r--r-- | firmware/export/system.h | 8 |
4 files changed, 35 insertions, 27 deletions
diff --git a/apps/codecs/libtremor/codebook.c b/apps/codecs/libtremor/codebook.c index 5ffd0e308b..f291686870 100644 --- a/apps/codecs/libtremor/codebook.c +++ b/apps/codecs/libtremor/codebook.c | |||
@@ -154,9 +154,9 @@ STIN long decode_packed_entry_number(codebook *book, | |||
154 | long lo,hi; | 154 | long lo,hi; |
155 | long lok = oggpack_look(b,book->dec_firsttablen); | 155 | long lok = oggpack_look(b,book->dec_firsttablen); |
156 | 156 | ||
157 | if (likely(lok >= 0)) { | 157 | if (LIKELY(lok >= 0)) { |
158 | long entry = book->dec_firsttable[lok]; | 158 | long entry = book->dec_firsttable[lok]; |
159 | if(unlikely(entry&0x80000000UL)){ | 159 | if(UNLIKELY(entry&0x80000000UL)){ |
160 | lo=(entry>>15)&0x7fff; | 160 | lo=(entry>>15)&0x7fff; |
161 | hi=book->used_entries-(entry&0x7fff); | 161 | hi=book->used_entries-(entry&0x7fff); |
162 | }else{ | 162 | }else{ |
@@ -218,7 +218,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, | |||
218 | bitend = ((adr&3)+b->headend)*8; | 218 | bitend = ((adr&3)+b->headend)*8; |
219 | while (bufptr<bufend){ | 219 | while (bufptr<bufend){ |
220 | long entry, lo, hi; | 220 | long entry, lo, hi; |
221 | if (unlikely(cachesize<book->dec_maxlength)) { | 221 | if (UNLIKELY(cachesize<book->dec_maxlength)) { |
222 | if (bit-cachesize+32>=bitend) | 222 | if (bit-cachesize+32>=bitend) |
223 | break; | 223 | break; |
224 | bit-=cachesize; | 224 | bit-=cachesize; |
@@ -230,13 +230,13 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, | |||
230 | } | 230 | } |
231 | 231 | ||
232 | entry=book->dec_firsttable[cache&((1<<book->dec_firsttablen)-1)]; | 232 | entry=book->dec_firsttable[cache&((1<<book->dec_firsttablen)-1)]; |
233 | if(unlikely(entry&0x80000000UL)){ | 233 | if(UNLIKELY(entry&0x80000000UL)){ |
234 | lo=(entry>>15)&0x7fff; | 234 | lo=(entry>>15)&0x7fff; |
235 | hi=book->used_entries-(entry&0x7fff); | 235 | hi=book->used_entries-(entry&0x7fff); |
236 | { | 236 | { |
237 | ogg_uint32_t testword=bitreverse((ogg_uint32_t)cache); | 237 | ogg_uint32_t testword=bitreverse((ogg_uint32_t)cache); |
238 | 238 | ||
239 | while(likely(hi-lo>1)){ | 239 | while(LIKELY(hi-lo>1)){ |
240 | long p=(hi-lo)>>1; | 240 | long p=(hi-lo)>>1; |
241 | if (book->codelist[lo+p]>testword) | 241 | if (book->codelist[lo+p]>testword) |
242 | hi-=p; | 242 | hi-=p; |
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index 7e283d4ef1..969d9b939a 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c | |||
@@ -293,10 +293,10 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
293 | const unsigned int start_loop = wf->startLoop << FRACTSIZE; | 293 | const unsigned int start_loop = wf->startLoop << FRACTSIZE; |
294 | const int diff_loop = end_loop-start_loop; | 294 | const int diff_loop = end_loop-start_loop; |
295 | 295 | ||
296 | while(likely(samples-- > 0)) | 296 | while(LIKELY(samples-- > 0)) |
297 | { | 297 | { |
298 | /* Is voice being ramped? */ | 298 | /* Is voice being ramped? */ |
299 | if(unlikely(so->state == STATE_RAMPDOWN)) | 299 | if(UNLIKELY(so->state == STATE_RAMPDOWN)) |
300 | { | 300 | { |
301 | if(so->decay != 0) /* Ramp has been started */ | 301 | if(so->decay != 0) /* Ramp has been started */ |
302 | { | 302 | { |
@@ -318,12 +318,12 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
318 | 318 | ||
319 | s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); | 319 | s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); |
320 | 320 | ||
321 | if(likely(mode_mask28)) | 321 | if(LIKELY(mode_mask28)) |
322 | { | 322 | { |
323 | /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ | 323 | /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ |
324 | if(unlikely(mode_mask24 && so->loopState == STATE_LOOPING && (cp_temp < start_loop))) | 324 | if(UNLIKELY(mode_mask24 && so->loopState == STATE_LOOPING && (cp_temp < start_loop))) |
325 | { | 325 | { |
326 | if(unlikely(mode_mask_looprev)) | 326 | if(UNLIKELY(mode_mask_looprev)) |
327 | { | 327 | { |
328 | cp_temp += diff_loop; | 328 | cp_temp += diff_loop; |
329 | s2=getSample((cp_temp >> FRACTSIZE), wf); | 329 | s2=getSample((cp_temp >> FRACTSIZE), wf); |
@@ -334,10 +334,10 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | if(unlikely(cp_temp >= end_loop)) | 337 | if(UNLIKELY(cp_temp >= end_loop)) |
338 | { | 338 | { |
339 | so->loopState = STATE_LOOPING; | 339 | so->loopState = STATE_LOOPING; |
340 | if(unlikely(!mode_mask24)) | 340 | if(UNLIKELY(!mode_mask24)) |
341 | { | 341 | { |
342 | cp_temp -= diff_loop; | 342 | cp_temp -= diff_loop; |
343 | s2=getSample((cp_temp >> FRACTSIZE), wf); | 343 | s2=getSample((cp_temp >> FRACTSIZE), wf); |
@@ -350,7 +350,7 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
350 | } | 350 | } |
351 | 351 | ||
352 | /* Have we overrun? */ | 352 | /* Have we overrun? */ |
353 | if(unlikely(cp_temp >= num_samples)) | 353 | if(UNLIKELY(cp_temp >= num_samples)) |
354 | { | 354 | { |
355 | cp_temp -= so->delta; | 355 | cp_temp -= so->delta; |
356 | s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); | 356 | s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); |
@@ -362,21 +362,21 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
362 | 362 | ||
363 | s1 +=((signed)((s2 - s1) * (cp_temp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); | 363 | s1 +=((signed)((s2 - s1) * (cp_temp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); |
364 | 364 | ||
365 | if(unlikely(so->curRate == 0)) | 365 | if(UNLIKELY(so->curRate == 0)) |
366 | { | 366 | { |
367 | stopVoice(so); | 367 | stopVoice(so); |
368 | // so->isUsed = false; | 368 | // so->isUsed = false; |
369 | 369 | ||
370 | } | 370 | } |
371 | 371 | ||
372 | if(likely(so->ch != 9 && so->state != STATE_RAMPDOWN)) /* Stupid ADSR code... and don't do ADSR for drums */ | 372 | if(LIKELY(so->ch != 9 && so->state != STATE_RAMPDOWN)) /* Stupid ADSR code... and don't do ADSR for drums */ |
373 | { | 373 | { |
374 | if(unlikely(so->curOffset < so->targetOffset)) | 374 | if(UNLIKELY(so->curOffset < so->targetOffset)) |
375 | { | 375 | { |
376 | so->curOffset += (so->curRate); | 376 | so->curOffset += (so->curRate); |
377 | if(unlikely(so -> curOffset > so->targetOffset && so->curPoint != 2)) | 377 | if(UNLIKELY(so -> curOffset > so->targetOffset && so->curPoint != 2)) |
378 | { | 378 | { |
379 | if(unlikely(so->curPoint != 5)) | 379 | if(UNLIKELY(so->curPoint != 5)) |
380 | { | 380 | { |
381 | setPoint(so, so->curPoint+1); | 381 | setPoint(so, so->curPoint+1); |
382 | } | 382 | } |
@@ -388,9 +388,9 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
388 | } else | 388 | } else |
389 | { | 389 | { |
390 | so->curOffset -= (so->curRate); | 390 | so->curOffset -= (so->curRate); |
391 | if(unlikely(so -> curOffset < so->targetOffset && so->curPoint != 2)) | 391 | if(UNLIKELY(so -> curOffset < so->targetOffset && so->curPoint != 2)) |
392 | { | 392 | { |
393 | if(unlikely(so->curPoint != 5)) | 393 | if(UNLIKELY(so->curPoint != 5)) |
394 | { | 394 | { |
395 | setPoint(so, so->curPoint+1); | 395 | setPoint(so, so->curPoint+1); |
396 | } | 396 | } |
@@ -403,7 +403,7 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
403 | } | 403 | } |
404 | } | 404 | } |
405 | 405 | ||
406 | if(unlikely(so->curOffset < 0)) | 406 | if(UNLIKELY(so->curOffset < 0)) |
407 | { | 407 | { |
408 | so->curOffset = so->targetOffset; | 408 | so->curOffset = so->targetOffset; |
409 | stopVoice(so); | 409 | stopVoice(so); |
@@ -416,7 +416,7 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
416 | s1 = s1 * volscale >> 14; | 416 | s1 = s1 * volscale >> 14; |
417 | 417 | ||
418 | /* need to set ramp beginning */ | 418 | /* need to set ramp beginning */ |
419 | if(unlikely(so->state == STATE_RAMPDOWN && so->decay == 0)) | 419 | if(UNLIKELY(so->state == STATE_RAMPDOWN && so->decay == 0)) |
420 | { | 420 | { |
421 | so->decay = s1; | 421 | so->decay = s1; |
422 | if(so->decay == 0) | 422 | if(so->decay == 0) |
@@ -442,7 +442,7 @@ int32_t samp_buf[512] IBSS_ATTR; | |||
442 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) ICODE_ATTR; | 442 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) ICODE_ATTR; |
443 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) | 443 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) |
444 | { | 444 | { |
445 | if (unlikely(num_samples > 512)) | 445 | if (UNLIKELY(num_samples > 512)) |
446 | DEBUGF("num_samples is too big!\n"); | 446 | DEBUGF("num_samples is too big!\n"); |
447 | else | 447 | else |
448 | { | 448 | { |
diff --git a/apps/plugins/mpegplayer/attributes.h b/apps/plugins/mpegplayer/attributes.h index 7ad83a3e6e..24b069223b 100644 --- a/apps/plugins/mpegplayer/attributes.h +++ b/apps/plugins/mpegplayer/attributes.h | |||
@@ -32,3 +32,11 @@ | |||
32 | #define ATTR_ALIGN(align) | 32 | #define ATTR_ALIGN(align) |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #if defined(LIKELY) && defined (UNLIKELY) | ||
36 | #define likely(x) LIKELY(x) | ||
37 | #define unlikely(x) UNLIKELY(x) | ||
38 | #else | ||
39 | #define likely(x) (x) | ||
40 | #define unlikely(x) (x) | ||
41 | #endif | ||
42 | |||
diff --git a/firmware/export/system.h b/firmware/export/system.h index cce7df6884..b82e2b1ad0 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -170,11 +170,11 @@ int get_cpu_boost_counter(void); | |||
170 | 170 | ||
171 | /* Use to give gcc hints on which branch is most likely taken */ | 171 | /* Use to give gcc hints on which branch is most likely taken */ |
172 | #if defined(__GNUC__) && __GNUC__ >= 3 | 172 | #if defined(__GNUC__) && __GNUC__ >= 3 |
173 | #define likely(x) __builtin_expect(!!(x), 1) | 173 | #define LIKELY(x) __builtin_expect(!!(x), 1) |
174 | #define unlikely(x) __builtin_expect(!!(x), 0) | 174 | #define UNLIKELY(x) __builtin_expect(!!(x), 0) |
175 | #else | 175 | #else |
176 | #define likely(x) (x) | 176 | #define LIKELY(x) (x) |
177 | #define unlikely(x) (x) | 177 | #define UNLIKELY(x) (x) |
178 | #endif | 178 | #endif |
179 | 179 | ||
180 | /* returns index of first set bit + 1 or 0 if no bits are set */ | 180 | /* returns index of first set bit + 1 or 0 if no bits are set */ |