[x265] [PATCH 1 of 6] move ATOM operators to threading.h

Min Chen chenm003 at 163.com
Tue Aug 20 08:18:39 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1376979213 -28800
# Node ID 942d33e2d30dc5328f6394308839cd384b97065d
# Parent  f5834b464a7c1a7b5204282aa7b87777194456c4
move ATOM operators to threading.h

diff -r f5834b464a7c -r 942d33e2d30d source/common/threading.h
--- a/source/common/threading.h	Mon Aug 19 23:57:31 2013 -0500
+++ b/source/common/threading.h	Tue Aug 20 14:13:33 2013 +0800
@@ -33,6 +33,7 @@
 #include <semaphore.h>
 #include <stdlib.h>
 #endif
+#include <stdint.h>
 
 namespace x265 {
 // x265 private namespace
@@ -209,4 +210,96 @@
 };
 } // end namespace x265
 
+
+#if MACOS
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
+#ifdef __GNUC__                         /* GCCs builtin atomics */
+
+#include <unistd.h>
+#include <limits.h>
+
+#define CLZ64(id, x)                        id = 63 - (unsigned long)__builtin_clzll(x)
+#define ATOMIC_OR(ptr, mask)                __sync_or_and_fetch(ptr, mask)
+#define ATOMIC_CAS(ptr, oldval, newval)     __sync_val_compare_and_swap(ptr, oldval, newval)
+#define ATOMIC_CAS32(ptr, oldval, newval)   __sync_val_compare_and_swap(ptr, oldval, newval)
+#define ATOMIC_INC(ptr)                     __sync_add_and_fetch((volatile int*)ptr, 1)
+#define ATOMIC_DEC(ptr)                     __sync_add_and_fetch((volatile int*)ptr, -1)
+#define GIVE_UP_TIME()                      usleep(0)
+
+#elif defined(_MSC_VER)                 /* Windows atomic intrinsics */
+
+#include <intrin.h>
+
+#if !_WIN64
+inline int _BitScanReverse64(DWORD *id, uint64_t x64) // fake 64bit CLZ
+{
+    uint32_t high32 = (uint32_t)(x64 >> 32);
+    uint32_t low32 = (uint32_t)x64;
+
+    if (high32)
+    {
+        _BitScanReverse(id, high32);
+        *id += 32;
+        return 1;
+    }
+    else if (low32)
+        return _BitScanReverse(id, low32);
+    else
+        return *id = 0;
+}
+
+inline int _BitScanForward64(DWORD *id, uint64_t x64) // fake 64bit CLZ
+{
+    uint32_t high32 = (uint32_t)(x64 >> 32);
+    uint32_t low32 = (uint32_t)x64;
+
+    if (high32)
+    {
+        _BitScanForward(id, high32);
+        *id += 32;
+        return 1;
+    }
+    else if (low32)
+        return _BitScanForward(id, low32);
+    else
+        return *id = 0;
+}
+#endif // if !_WIN64
+
+#if _WIN32_WINNT <= _WIN32_WINNT_WINXP
+/* Windows XP did not define this intrinsic */
+FORCEINLINE LONGLONG _InterlockedOr64(__inout LONGLONG volatile *Destination,
+                                      __in    LONGLONG           Value)
+{
+    LONGLONG Old;
+
+    do
+    {
+        Old = *Destination;
+    }
+    while (_InterlockedCompareExchange64(Destination, Old | Value, Old) != Old);
+
+    return Old;
+}
+
+#define ATOMIC_OR(ptr, mask)            _InterlockedOr64((volatile LONG64*)ptr, mask)
+#if defined(__MSC_VER) && !defined(__INTEL_COMPILER)
+#pragma intrinsic(_InterlockedCompareExchange64)
+#endif
+#else // if _WIN32_WINNT <= _WIN32_WINNT_WINXP
+#define ATOMIC_OR(ptr, mask)            InterlockedOr64((volatile LONG64*)ptr, mask)
+#endif // if _WIN32_WINNT <= _WIN32_WINNT_WINXP
+
+#define CLZ64(id, x)                        _BitScanForward64(&id, x)
+#define ATOMIC_CAS(ptr, oldval, newval)     (uint64_t)_InterlockedCompareExchange64((volatile LONG64*)ptr, newval, oldval)
+#define ATOMIC_CAS32(ptr, oldval, newval)   (uint64_t)_InterlockedCompareExchange((volatile LONG*)ptr, newval, oldval)
+#define ATOMIC_INC(ptr)                     InterlockedIncrement((volatile LONG*)ptr)
+#define ATOMIC_DEC(ptr)                     InterlockedDecrement((volatile LONG*)ptr)
+#define GIVE_UP_TIME()                      Sleep(0)
+
+#endif // ifdef __GNUC__
+
 #endif // ifndef _THREADING_H_
diff -r f5834b464a7c -r 942d33e2d30d source/common/threadpool.cpp
--- a/source/common/threadpool.cpp	Mon Aug 19 23:57:31 2013 -0500
+++ b/source/common/threadpool.cpp	Tue Aug 20 14:13:33 2013 +0800
@@ -34,23 +34,6 @@
 #include <sys/sysctl.h>
 #endif
 
-#ifdef __GNUC__          /* GCCs builtin atomics */
-
-#include <unistd.h>
-#include <limits.h>
-#define ATOMIC_INC(ptr) __sync_add_and_fetch((volatile int*)ptr, 1)
-#define ATOMIC_DEC(ptr) __sync_add_and_fetch((volatile int*)ptr, -1)
-#define GIVE_UP_TIME()  usleep(0)
-
-#elif defined(_MSC_VER)  /* Windows atomic intrinsics */
-
-#include <intrin.h>
-#define ATOMIC_INC(ptr) InterlockedIncrement((volatile LONG*)ptr)
-#define ATOMIC_DEC(ptr) InterlockedDecrement((volatile LONG*)ptr)
-#define GIVE_UP_TIME()  Sleep(0)
-
-#endif // ifdef __GNUC__
-
 namespace x265 {
 // x265 private namespace
 
diff -r f5834b464a7c -r 942d33e2d30d source/common/wavefront.cpp
--- a/source/common/wavefront.cpp	Mon Aug 19 23:57:31 2013 -0500
+++ b/source/common/wavefront.cpp	Tue Aug 20 14:13:33 2013 +0800
@@ -28,89 +28,6 @@
 #include <string.h>
 #include <new>
 
-#if MACOS
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#endif
-
-#ifdef __GNUC__                         /* GCCs builtin atomics */
-
-#include <unistd.h>
-#include <limits.h>
-
-#define CLZ64(id, x)                    id = 63 - (unsigned long)__builtin_clzll(x)
-#define ATOMIC_OR(ptr, mask)            __sync_or_and_fetch(ptr, mask)
-#define ATOMIC_CAS(ptr, oldval, newval) __sync_val_compare_and_swap(ptr, oldval, newval)
-
-#elif defined(_MSC_VER)                 /* Windows atomic intrinsics */
-
-#include <intrin.h>
-
-#if !_WIN64
-inline int _BitScanReverse64(DWORD *id, uint64_t x64) // fake 64bit CLZ
-{
-    uint32_t high32 = (uint32_t)(x64 >> 32);
-    uint32_t low32 = (uint32_t)x64;
-
-    if (high32)
-    {
-        _BitScanReverse(id, high32);
-        *id += 32;
-        return 1;
-    }
-    else if (low32)
-        return _BitScanReverse(id, low32);
-    else
-        return *id = 0;
-}
-
-inline int _BitScanForward64(DWORD *id, uint64_t x64) // fake 64bit CLZ
-{
-    uint32_t high32 = (uint32_t)(x64 >> 32);
-    uint32_t low32 = (uint32_t)x64;
-
-    if (high32)
-    {
-        _BitScanForward(id, high32);
-        *id += 32;
-        return 1;
-    }
-    else if (low32)
-        return _BitScanForward(id, low32);
-    else
-        return *id = 0;
-}
-#endif // if !_WIN64
-
-#if _WIN32_WINNT <= _WIN32_WINNT_WINXP
-/* Windows XP did not define this intrinsic */
-FORCEINLINE LONGLONG _InterlockedOr64(__inout LONGLONG volatile *Destination,
-                                      __in    LONGLONG           Value)
-{
-    LONGLONG Old;
-
-    do
-    {
-        Old = *Destination;
-    }
-    while (_InterlockedCompareExchange64(Destination, Old | Value, Old) != Old);
-
-    return Old;
-}
-
-#define ATOMIC_OR(ptr, mask)            _InterlockedOr64((volatile LONG64*)ptr, mask)
-#if defined(__MSC_VER) && !defined(__INTEL_COMPILER)
-#pragma intrinsic(_InterlockedCompareExchange64)
-#endif
-#else // if _WIN32_WINNT <= _WIN32_WINNT_WINXP
-#define ATOMIC_OR(ptr, mask)            InterlockedOr64((volatile LONG64*)ptr, mask)
-#endif // if _WIN32_WINNT <= _WIN32_WINNT_WINXP
-
-#define CLZ64(id, x)                    _BitScanForward64(&id, x)
-#define ATOMIC_CAS(ptr, oldval, newval) (uint64_t)_InterlockedCompareExchange64((volatile LONG64*)ptr, newval, oldval)
-
-#endif // ifdef __GNUC__
-
 namespace x265 {
 // x265 private namespace
 



More information about the x265-devel mailing list