From 1284c127f8e1f2ab693d523a009b7b2e553024a5 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Thu, 20 Nov 2008 20:20:43 +0000 Subject: Introduce likely() and unlikely() macros, use to give gcc hints about which branch is likely to be taken in a conditional, use them in the midi player for a small speedup, use instead of similar EXPECT macros in tremor and use in mpegplayer git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19162 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/system.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'firmware/export') 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); #define TYPE_FROM_MEMBER(type, memberptr, membername) \ ((type *)((intptr_t)(memberptr) - OFFSETOF(type, membername))) +/* Use to give gcc hints on which branch is most likely taken */ +#if defined(__GNUC__) && __GNUC__ >= 3 +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else +#define likely(x) (x) +#define unlikely(x) (x) +#endif + /* returns index of first set bit + 1 or 0 if no bits are set */ int find_first_set_bit(uint32_t val); -- cgit v1.2.3