[pulseaudio-discuss] [PATCH] macro: Move PA_LIKELY()/PA_UNLIKELY(), PA_CLAMP()/PA_CLAMP_UNLIKELY() to pulse/gccmacro.h

Peter Meerwald pmeerw at pmeerw.net
Wed May 20 13:46:35 PDT 2015


From: Peter Meerwald <p.meerwald at bct-electronic.com>

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 at pmeerw.net>
---
 src/pulse/gccmacro.h  | 38 ++++++++++++++++++++++++++++++++++++++
 src/pulsecore/macro.h | 38 --------------------------------------
 2 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/pulse/gccmacro.h b/src/pulse/gccmacro.h
index e5ba5bd..81729db 100644
--- a/src/pulse/gccmacro.h
+++ b/src/pulse/gccmacro.h
@@ -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
diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h
index 1716f81..e8edb23 100644
--- a/src/pulsecore/macro.h
+++ b/src/pulsecore/macro.h
@@ -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
-
 #if defined(PAGE_SIZE)
 #define PA_PAGE_SIZE ((size_t) PAGE_SIZE)
 #elif defined(PAGESIZE)
@@ -121,34 +111,6 @@ static inline size_t PA_PAGE_ALIGN(size_t l) {
 #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__ ({                            \
             typeof(a) _a = (a);                 \
-- 
1.9.1



More information about the pulseaudio-discuss mailing list