Commit d6b69444 authored by Peter Meerwald's avatar Peter Meerwald Committed by Tanu Kaskinen
Browse files

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's avatarPeter Meerwald <pmeerw@pmeerw.net>
parent 1f5da4c2
......@@ -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__ ({ \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment