mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04: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
|
||||
|
|
|
|||
|
|
@ -34,16 +34,6 @@
|
|||
#error "Please include config.h before including this file!"
|
||||
#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
|
||||
|
||||
/* Rounds down */
|
||||
static inline void* PA_ALIGN_PTR(const void *p) {
|
||||
return (void*) (((size_t) p) & ~(sizeof(void*) - 1));
|
||||
|
|
@ -99,34 +89,6 @@ static inline size_t PA_ALIGN(size_t l) {
|
|||
#define PA_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#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 values is
|
||||
* lower or greater than the boundaries.*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define PA_ROUND_UP(a, b) \
|
||||
__extension__ ({ \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue