From: hpayer@chromium.org Date: Wed, 9 Apr 2014 08:20:10 +0000 (+0000) Subject: Introduced Atomic8 and added no-barrier Atomic8 accessors. X-Git-Tag: upstream/4.7.83~9750 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c85cc472e71583a8d93980fd727165677bc94057;p=platform%2Fupstream%2Fv8.git Introduced Atomic8 and added no-barrier Atomic8 accessors. BUG= R=jarin@chromium.org Review URL: https://codereview.chromium.org/228613005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20598 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/atomicops.h b/src/atomicops.h index 08be2a7..019e640 100644 --- a/src/atomicops.h +++ b/src/atomicops.h @@ -63,6 +63,7 @@ namespace v8 { namespace internal { +typedef char Atomic8; typedef int32_t Atomic32; #ifdef V8_HOST_ARCH_64_BIT // We need to be able to go between Atomic64 and AtomicWord implicitly. This @@ -120,10 +121,12 @@ Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, Atomic32 new_value); void MemoryBarrier(); +void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value); void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); void Acquire_Store(volatile Atomic32* ptr, Atomic32 value); void Release_Store(volatile Atomic32* ptr, Atomic32 value); +Atomic8 NoBarrier_Load(volatile const Atomic8* ptr); Atomic32 NoBarrier_Load(volatile const Atomic32* ptr); Atomic32 Acquire_Load(volatile const Atomic32* ptr); Atomic32 Release_Load(volatile const Atomic32* ptr); diff --git a/src/atomicops_internals_arm64_gcc.h b/src/atomicops_internals_arm64_gcc.h index f6ed5de..254bba9 100644 --- a/src/atomicops_internals_arm64_gcc.h +++ b/src/atomicops_internals_arm64_gcc.h @@ -144,6 +144,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, return prev; } +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + *ptr = value; +} + inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } @@ -162,6 +166,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ); // NOLINT } +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { + return *ptr; +} + inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { return *ptr; } diff --git a/src/atomicops_internals_arm_gcc.h b/src/atomicops_internals_arm_gcc.h index 918920d..258a668 100644 --- a/src/atomicops_internals_arm_gcc.h +++ b/src/atomicops_internals_arm_gcc.h @@ -311,6 +311,14 @@ inline Atomic32 Release_Load(volatile const Atomic32* ptr) { return *ptr; } +// Byte accessors. + +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + *ptr = value; +} + +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { return *ptr; } + } } // namespace v8::internal #endif // V8_ATOMICOPS_INTERNALS_ARM_GCC_H_ diff --git a/src/atomicops_internals_mac.h b/src/atomicops_internals_mac.h index 4bd0c09..80647f7 100644 --- a/src/atomicops_internals_mac.h +++ b/src/atomicops_internals_mac.h @@ -93,6 +93,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, return Acquire_CompareAndSwap(ptr, old_value, new_value); } +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + *ptr = value; +} + inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } @@ -107,6 +111,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { + return *ptr; +} + inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { return *ptr; } diff --git a/src/atomicops_internals_mips_gcc.h b/src/atomicops_internals_mips_gcc.h index cb8f8b9..13112e0 100644 --- a/src/atomicops_internals_mips_gcc.h +++ b/src/atomicops_internals_mips_gcc.h @@ -136,6 +136,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, return NoBarrier_CompareAndSwap(ptr, old_value, new_value); } +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + *ptr = value; +} + inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } @@ -154,6 +158,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { + return *ptr; +} + inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { return *ptr; } diff --git a/src/atomicops_internals_tsan.h b/src/atomicops_internals_tsan.h index 1819798..ce5774e 100644 --- a/src/atomicops_internals_tsan.h +++ b/src/atomicops_internals_tsan.h @@ -276,6 +276,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, return cmp; } +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + __tsan_atomic8_store(ptr, value, __tsan_memory_order_relaxed); +} + inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { __tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed); } @@ -289,6 +293,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { __tsan_atomic32_store(ptr, value, __tsan_memory_order_release); } +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { + return __tsan_atomic8_load(ptr, __tsan_memory_order_relaxed); +} + inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed); } diff --git a/src/atomicops_internals_x86_gcc.h b/src/atomicops_internals_x86_gcc.h index e58d598..1624b82 100644 --- a/src/atomicops_internals_x86_gcc.h +++ b/src/atomicops_internals_x86_gcc.h @@ -107,6 +107,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, return NoBarrier_CompareAndSwap(ptr, old_value, new_value); } +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + *ptr = value; +} + inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } @@ -152,6 +156,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { // See comments in Atomic64 version of Release_Store(), below. } +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { + return *ptr; +} + inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { return *ptr; } diff --git a/src/atomicops_internals_x86_msvc.h b/src/atomicops_internals_x86_msvc.h index ad9cf9d..6c7a22c 100644 --- a/src/atomicops_internals_x86_msvc.h +++ b/src/atomicops_internals_x86_msvc.h @@ -100,6 +100,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, return NoBarrier_CompareAndSwap(ptr, old_value, new_value); } +inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { + *ptr = value; +} + inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } @@ -114,6 +118,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { // See comments in Atomic64 version of Release_Store() below. } +inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { + return *ptr; +} + inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { return *ptr; } diff --git a/test/cctest/test-atomicops.cc b/test/cctest/test-atomicops.cc index eba956c..53df229 100644 --- a/test/cctest/test-atomicops.cc +++ b/test/cctest/test-atomicops.cc @@ -214,6 +214,21 @@ static void TestStore() { } +// Merge this test with TestStore as soon as we have Atomic8 acquire +// and release stores. +static void TestStoreAtomic8() { + const Atomic8 kVal1 = TestFillValue(); + const Atomic8 kVal2 = static_cast(-1); + + Atomic8 value; + + NoBarrier_Store(&value, kVal1); + CHECK_EQU(kVal1, value); + NoBarrier_Store(&value, kVal2); + CHECK_EQU(kVal2, value); +} + + // This is a simple sanity check to ensure that values are correct. // Not testing atomicity. template @@ -240,6 +255,21 @@ static void TestLoad() { } +// Merge this test with TestLoad as soon as we have Atomic8 acquire +// and release loads. +static void TestLoadAtomic8() { + const Atomic8 kVal1 = TestFillValue(); + const Atomic8 kVal2 = static_cast(-1); + + Atomic8 value; + + value = kVal1; + CHECK_EQU(kVal1, NoBarrier_Load(&value)); + value = kVal2; + CHECK_EQU(kVal2, NoBarrier_Load(&value)); +} + + TEST(AtomicIncrement) { TestAtomicIncrement(); TestAtomicIncrement(); @@ -265,12 +295,14 @@ TEST(AtomicIncrementBounds) { TEST(Store) { + TestStoreAtomic8(); TestStore(); TestStore(); } TEST(Load) { + TestLoadAtomic8(); TestLoad(); TestLoad(); }