From fe57fa0375faec172027f38b645e6169633826af Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 4 Feb 2018 03:11:10 +0300 Subject: [PATCH] Added specialized negate_and_test and complement_and_test for MSVC 32-bit x86 target. --- .../atomic/detail/extra_ops_msvc_x86.hpp | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/include/boost/atomic/detail/extra_ops_msvc_x86.hpp b/include/boost/atomic/detail/extra_ops_msvc_x86.hpp index c19b13c..c522e7e 100644 --- a/include/boost/atomic/detail/extra_ops_msvc_x86.hpp +++ b/include/boost/atomic/detail/extra_ops_msvc_x86.hpp @@ -136,6 +136,27 @@ struct extra_operations< Base, 1u, Signed > : return old_val; } + static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT + { + base_type::fence_before(order); + bool result; + __asm + { + mov ecx, storage + movzx eax, byte ptr [ecx] + align 16 + again: + mov edx, eax + neg dl + lock cmpxchg byte ptr [ecx], dl + jne again + test dl, dl + setnz result + }; + base_type::fence_after(order); + return result; + } + static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT { base_type::fence_before(order); @@ -173,6 +194,27 @@ struct extra_operations< Base, 1u, Signed > : return old_val; } + static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT + { + base_type::fence_before(order); + bool result; + __asm + { + mov ecx, storage + movzx eax, byte ptr [ecx] + align 16 + again: + mov edx, eax + not dl + lock cmpxchg byte ptr [ecx], dl + jne again + test dl, dl + setnz result + }; + base_type::fence_after(order); + return result; + } + static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT { base_type::fence_before(order); @@ -377,6 +419,27 @@ struct extra_operations< Base, 2u, Signed > : return old_val; } + static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT + { + base_type::fence_before(order); + bool result; + __asm + { + mov ecx, storage + movzx eax, word ptr [ecx] + align 16 + again: + mov edx, eax + neg dx + lock cmpxchg word ptr [ecx], dx + jne again + test dx, dx + setnz result + }; + base_type::fence_after(order); + return result; + } + static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT { base_type::fence_before(order); @@ -414,6 +477,27 @@ struct extra_operations< Base, 2u, Signed > : return old_val; } + static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT + { + base_type::fence_before(order); + bool result; + __asm + { + mov ecx, storage + movzx eax, word ptr [ecx] + align 16 + again: + mov edx, eax + not dx + lock cmpxchg word ptr [ecx], dx + jne again + test dx, dx + setnz result + }; + base_type::fence_after(order); + return result; + } + static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT { base_type::fence_before(order); @@ -618,6 +702,27 @@ struct extra_operations< Base, 4u, Signed > : return old_val; } + static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT + { + base_type::fence_before(order); + bool result; + __asm + { + mov ecx, storage + mov eax, dword ptr [ecx] + align 16 + again: + mov edx, eax + neg edx + lock cmpxchg dword ptr [ecx], edx + jne again + test edx, edx + setnz result + }; + base_type::fence_after(order); + return result; + } + static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT { base_type::fence_before(order); @@ -655,6 +760,27 @@ struct extra_operations< Base, 4u, Signed > : return old_val; } + static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT + { + base_type::fence_before(order); + bool result; + __asm + { + mov ecx, storage + mov eax, dword ptr [ecx] + align 16 + again: + mov edx, eax + not edx + lock cmpxchg dword ptr [ecx], edx + jne again + test edx, edx + setnz result + }; + base_type::fence_after(order); + return result; + } + static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT { base_type::fence_before(order);