Commit c85cc472 authored by hpayer@chromium.org's avatar hpayer@chromium.org

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
parent 05670b63
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
typedef char Atomic8;
typedef int32_t Atomic32; typedef int32_t Atomic32;
#ifdef V8_HOST_ARCH_64_BIT #ifdef V8_HOST_ARCH_64_BIT
// We need to be able to go between Atomic64 and AtomicWord implicitly. This // We need to be able to go between Atomic64 and AtomicWord implicitly. This
...@@ -120,10 +121,12 @@ Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -120,10 +121,12 @@ Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 new_value); Atomic32 new_value);
void MemoryBarrier(); void MemoryBarrier();
void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value);
void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
void Acquire_Store(volatile Atomic32* ptr, Atomic32 value); void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
void Release_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 NoBarrier_Load(volatile const Atomic32* ptr);
Atomic32 Acquire_Load(volatile const Atomic32* ptr); Atomic32 Acquire_Load(volatile const Atomic32* ptr);
Atomic32 Release_Load(volatile const Atomic32* ptr); Atomic32 Release_Load(volatile const Atomic32* ptr);
......
...@@ -144,6 +144,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -144,6 +144,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
return prev; return prev;
} }
inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) {
*ptr = value;
}
inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
...@@ -162,6 +166,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ...@@ -162,6 +166,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
); // NOLINT ); // NOLINT
} }
inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) {
return *ptr;
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr; return *ptr;
} }
......
...@@ -311,6 +311,14 @@ inline Atomic32 Release_Load(volatile const Atomic32* ptr) { ...@@ -311,6 +311,14 @@ inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
return *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 } } // namespace v8::internal
#endif // V8_ATOMICOPS_INTERNALS_ARM_GCC_H_ #endif // V8_ATOMICOPS_INTERNALS_ARM_GCC_H_
...@@ -93,6 +93,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -93,6 +93,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
return Acquire_CompareAndSwap(ptr, old_value, new_value); 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) { inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
...@@ -107,6 +111,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ...@@ -107,6 +111,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) {
return *ptr;
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr; return *ptr;
} }
......
...@@ -136,6 +136,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -136,6 +136,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 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) { inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
...@@ -154,6 +158,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ...@@ -154,6 +158,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) {
return *ptr;
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr; return *ptr;
} }
......
...@@ -276,6 +276,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -276,6 +276,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
return cmp; 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) { inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
__tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed); __tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed);
} }
...@@ -289,6 +293,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ...@@ -289,6 +293,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
__tsan_atomic32_store(ptr, value, __tsan_memory_order_release); __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) { inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed); return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed);
} }
......
...@@ -107,6 +107,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -107,6 +107,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 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) { inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
...@@ -152,6 +156,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ...@@ -152,6 +156,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
// See comments in Atomic64 version of Release_Store(), below. // 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) { inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr; return *ptr;
} }
......
...@@ -100,6 +100,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, ...@@ -100,6 +100,10 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 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) { inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value; *ptr = value;
} }
...@@ -114,6 +118,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { ...@@ -114,6 +118,10 @@ inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
// See comments in Atomic64 version of Release_Store() below. // 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) { inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr; return *ptr;
} }
......
...@@ -214,6 +214,21 @@ static void TestStore() { ...@@ -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<Atomic8>();
const Atomic8 kVal2 = static_cast<Atomic8>(-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. // This is a simple sanity check to ensure that values are correct.
// Not testing atomicity. // Not testing atomicity.
template <class AtomicType> template <class AtomicType>
...@@ -240,6 +255,21 @@ static void TestLoad() { ...@@ -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<Atomic8>();
const Atomic8 kVal2 = static_cast<Atomic8>(-1);
Atomic8 value;
value = kVal1;
CHECK_EQU(kVal1, NoBarrier_Load(&value));
value = kVal2;
CHECK_EQU(kVal2, NoBarrier_Load(&value));
}
TEST(AtomicIncrement) { TEST(AtomicIncrement) {
TestAtomicIncrement<Atomic32>(); TestAtomicIncrement<Atomic32>();
TestAtomicIncrement<AtomicWord>(); TestAtomicIncrement<AtomicWord>();
...@@ -265,12 +295,14 @@ TEST(AtomicIncrementBounds) { ...@@ -265,12 +295,14 @@ TEST(AtomicIncrementBounds) {
TEST(Store) { TEST(Store) {
TestStoreAtomic8();
TestStore<Atomic32>(); TestStore<Atomic32>();
TestStore<AtomicWord>(); TestStore<AtomicWord>();
} }
TEST(Load) { TEST(Load) {
TestLoadAtomic8();
TestLoad<Atomic32>(); TestLoad<Atomic32>();
TestLoad<AtomicWord>(); TestLoad<AtomicWord>();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment