mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
macro: Move PA_LIKELY()/PA_UNLIKELY(), PA_CLAMP()/PA_CLAMP_UNLIKELY() to pulse/gccmacro.h
PA_CLAMP_VOLUME() in pulse/volume.h makes use of PA_CLAMP_UNLIKELY() see https://bugs.freedesktop.org/show_bug.cgi?id=89515 Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
This commit is contained in:
parent
1f5da4c20b
commit
d6b69444be
2 changed files with 38 additions and 38 deletions
|
|
@ -129,4 +129,42 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PA_LIKELY
|
||||
#ifdef __GNUC__
|
||||
#define PA_LIKELY(x) (__builtin_expect(!!(x),1))
|
||||
#define PA_UNLIKELY(x) (__builtin_expect(!!(x),0))
|
||||
#else
|
||||
#define PA_LIKELY(x) (x)
|
||||
#define PA_UNLIKELY(x) (x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define PA_CLAMP(x, low, high) \
|
||||
__extension__ ({ \
|
||||
typeof(x) _x = (x); \
|
||||
typeof(low) _low = (low); \
|
||||
typeof(high) _high = (high); \
|
||||
((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
|
||||
})
|
||||
#else
|
||||
#define PA_CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define PA_CLAMP_UNLIKELY(x, low, high) \
|
||||
__extension__ ({ \
|
||||
typeof(x) _x = (x); \
|
||||
typeof(low) _low = (low); \
|
||||
typeof(high) _high = (high); \
|
||||
(PA_UNLIKELY(_x > _high) ? _high : (PA_UNLIKELY(_x < _low) ? _low : _x)); \
|
||||
})
|
||||
#else
|
||||
#define PA_CLAMP_UNLIKELY(x, low, high) (PA_UNLIKELY((x) > (high)) ? (high) : (PA_UNLIKELY((x) < (low)) ? (low) : (x)))
|
||||
#endif
|
||||
|
||||
/* We don't define a PA_CLAMP_LIKELY here, because it doesn't really
|
||||
* make sense: we cannot know if it is more likely that the value is
|
||||
* lower or greater than the boundaries. */
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue