X-Git-Url: https://git.piment-noir.org/?p=deb_x265.git;a=blobdiff_plain;f=source%2Fcommon%2Fthreading.h;h=5f957829e243e1df89196b53f9bdb2d6ddc74545;hp=ef5642a601138cdef74d4fe25e03fc7d91c8fe1e;hb=b53f7c52d8280ab63876efd6eb292c21430ac607;hpb=5c9b45285dd64723ad1dac380b98a7b1f3095674 diff --git a/source/common/threading.h b/source/common/threading.h index ef5642a..5f95782 100644 --- a/source/common/threading.h +++ b/source/common/threading.h @@ -1,6 +1,4 @@ /***************************************************************************** - * x265: threading class and intrinsics - ***************************************************************************** * Copyright (C) 2013 x265 project * * Authors: Steve Borho @@ -49,11 +47,10 @@ #include #include -#define CLZ32(id, x) id = (unsigned long)__builtin_clz(x) ^ 31 -#define CTZ64(id, x) id = (unsigned long)__builtin_ctzll(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 CLZ(id, x) id = (unsigned long)__builtin_clz(x) ^ 31 +#define CTZ(id, x) id = (unsigned long)__builtin_ctz(x) +#define ATOMIC_OR(ptr, mask) __sync_fetch_and_or(ptr, mask) +#define ATOMIC_AND(ptr, mask) __sync_fetch_and_and(ptr, mask) #define ATOMIC_INC(ptr) __sync_add_and_fetch((volatile int32_t*)ptr, 1) #define ATOMIC_DEC(ptr) __sync_add_and_fetch((volatile int32_t*)ptr, -1) #define GIVE_UP_TIME() usleep(0) @@ -62,53 +59,12 @@ #include -#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 - -#ifndef ATOMIC_OR -#define ATOMIC_OR(ptr, mask) InterlockedOr64((volatile LONG64*)ptr, mask) -#endif - -#define CLZ32(id, x) _BitScanReverse(&id, x) -#define CTZ64(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 CLZ(id, x) _BitScanReverse(&id, x) +#define CTZ(id, x) _BitScanForward(&id, x) #define ATOMIC_INC(ptr) InterlockedIncrement((volatile LONG*)ptr) #define ATOMIC_DEC(ptr) InterlockedDecrement((volatile LONG*)ptr) +#define ATOMIC_OR(ptr, mask) _InterlockedOr((volatile LONG*)ptr, (LONG)mask) +#define ATOMIC_AND(ptr, mask) _InterlockedAnd((volatile LONG*)ptr, (LONG)mask) #define GIVE_UP_TIME() Sleep(0) #endif // ifdef __GNUC__