diff options
-rw-r--r-- | apps/codecs/libtremor/codebook.c | 10 | ||||
-rw-r--r-- | apps/codecs/libtremor/misc.h | 12 | ||||
-rw-r--r-- | apps/plugins/midi/synth.c | 36 | ||||
-rw-r--r-- | apps/plugins/mpegplayer/attributes.h | 7 | ||||
-rw-r--r-- | firmware/export/system.h | 9 |
5 files changed, 32 insertions, 42 deletions
diff --git a/apps/codecs/libtremor/codebook.c b/apps/codecs/libtremor/codebook.c index 8c319ab49e..5ffd0e308b 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 (EXPECT(lok >= 0, 1)) { | 157 | if (likely(lok >= 0)) { |
158 | long entry = book->dec_firsttable[lok]; | 158 | long entry = book->dec_firsttable[lok]; |
159 | if(EXPECT(entry&0x80000000UL, 0)){ | 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 (EXPECT(cachesize<book->dec_maxlength, 0)) { | 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(EXPECT(entry&0x80000000UL, 0)){ | 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(EXPECT(hi-lo>1, 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/codecs/libtremor/misc.h b/apps/codecs/libtremor/misc.h index 7d8b846381..e94236c2a8 100644 --- a/apps/codecs/libtremor/misc.h +++ b/apps/codecs/libtremor/misc.h | |||
@@ -275,17 +275,5 @@ static inline ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, | |||
275 | return(a); | 275 | return(a); |
276 | } | 276 | } |
277 | 277 | ||
278 | #ifdef __GNUC__ | ||
279 | #if __GNUC__ >= 3 | ||
280 | #define EXPECT(a, b) __builtin_expect((a), (b)) | ||
281 | #else | ||
282 | #define EXPECT(a, b) (a) | ||
283 | #endif | ||
284 | #else | ||
285 | #define EXPECT(a, b) (a) | ||
286 | #endif | 278 | #endif |
287 | 279 | ||
288 | #endif | ||
289 | |||
290 | |||
291 | |||
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index 0819722030..bae6149860 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c | |||
@@ -296,7 +296,7 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
296 | while(samples-- > 0) | 296 | while(samples-- > 0) |
297 | { | 297 | { |
298 | /* Is voice being ramped? */ | 298 | /* Is voice being ramped? */ |
299 | if(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(mode_mask28) | 321 | if(likely(mode_mask28)) |
322 | { | 322 | { |
323 | /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ | 323 | /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ |
324 | if(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(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(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(!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(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(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(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(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(so -> curOffset > so->targetOffset && so->curPoint != 2) | 377 | if(unlikely(so -> curOffset > so->targetOffset && so->curPoint != 2)) |
378 | { | 378 | { |
379 | if(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,10 +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(so -> curOffset < so->targetOffset && so->curPoint != 2) | 391 | if(unlikely(so -> curOffset < so->targetOffset && so->curPoint != 2)) |
392 | { | 392 | { |
393 | 393 | if(unlikely(so->curPoint != 5)) | |
394 | if(so->curPoint != 5) | ||
395 | { | 394 | { |
396 | setPoint(so, so->curPoint+1); | 395 | setPoint(so, so->curPoint+1); |
397 | } | 396 | } |
@@ -404,7 +403,7 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
404 | } | 403 | } |
405 | } | 404 | } |
406 | 405 | ||
407 | if(so->curOffset < 0) | 406 | if(unlikely(so->curOffset < 0)) |
408 | { | 407 | { |
409 | so->curOffset = so->targetOffset; | 408 | so->curOffset = so->targetOffset; |
410 | stopVoice(so); | 409 | stopVoice(so); |
@@ -417,7 +416,7 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
417 | s1 = s1 * volscale >> 14; | 416 | s1 = s1 * volscale >> 14; |
418 | 417 | ||
419 | /* need to set ramp beginning */ | 418 | /* need to set ramp beginning */ |
420 | if(so->state == STATE_RAMPDOWN && so->decay == 0) | 419 | if(unlikely(so->state == STATE_RAMPDOWN && so->decay == 0)) |
421 | { | 420 | { |
422 | so->decay = s1; | 421 | so->decay = s1; |
423 | if(so->decay == 0) | 422 | if(so->decay == 0) |
@@ -443,7 +442,7 @@ int32_t samp_buf[512] IBSS_ATTR; | |||
443 | 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; |
444 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) | 443 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) |
445 | { | 444 | { |
446 | if (num_samples > 512) | 445 | if (unlikely(num_samples > 512)) |
447 | DEBUGF("num_samples is too big!\n"); | 446 | DEBUGF("num_samples is too big!\n"); |
448 | else | 447 | else |
449 | { | 448 | { |
@@ -463,6 +462,7 @@ void synthSamples(int32_t *buf_ptr, unsigned int num_samples) | |||
463 | 462 | ||
464 | rb->memcpy(buf_ptr, samp_buf, num_samples*4); | 463 | rb->memcpy(buf_ptr, samp_buf, num_samples*4); |
465 | } | 464 | } |
465 | |||
466 | /* TODO: Automatic Gain Control, anyone? */ | 466 | /* TODO: Automatic Gain Control, anyone? */ |
467 | /* Or, should this be implemented on the DSP's output volume instead? */ | 467 | /* Or, should this be implemented on the DSP's output volume instead? */ |
468 | 468 | ||
diff --git a/apps/plugins/mpegplayer/attributes.h b/apps/plugins/mpegplayer/attributes.h index 9d708061c0..7ad83a3e6e 100644 --- a/apps/plugins/mpegplayer/attributes.h +++ b/apps/plugins/mpegplayer/attributes.h | |||
@@ -32,10 +32,3 @@ | |||
32 | #define ATTR_ALIGN(align) | 32 | #define ATTR_ALIGN(align) |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #ifdef HAVE_BUILTIN_EXPECT | ||
36 | #define likely(x) __builtin_expect ((x) != 0, 1) | ||
37 | #define unlikely(x) __builtin_expect ((x) != 0, 0) | ||
38 | #else | ||
39 | #define likely(x) (x) | ||
40 | #define unlikely(x) (x) | ||
41 | #endif | ||
diff --git a/firmware/export/system.h b/firmware/export/system.h index 71422e17d6..cce7df6884 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -168,6 +168,15 @@ int get_cpu_boost_counter(void); | |||
168 | #define TYPE_FROM_MEMBER(type, memberptr, membername) \ | 168 | #define TYPE_FROM_MEMBER(type, memberptr, membername) \ |
169 | ((type *)((intptr_t)(memberptr) - OFFSETOF(type, membername))) | 169 | ((type *)((intptr_t)(memberptr) - OFFSETOF(type, membername))) |
170 | 170 | ||
171 | /* Use to give gcc hints on which branch is most likely taken */ | ||
172 | #if defined(__GNUC__) && __GNUC__ >= 3 | ||
173 | #define likely(x) __builtin_expect(!!(x), 1) | ||
174 | #define unlikely(x) __builtin_expect(!!(x), 0) | ||
175 | #else | ||
176 | #define likely(x) (x) | ||
177 | #define unlikely(x) (x) | ||
178 | #endif | ||
179 | |||
171 | /* 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 */ |
172 | int find_first_set_bit(uint32_t val); | 181 | int find_first_set_bit(uint32_t val); |
173 | 182 | ||