mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8307926: Support byte-sized atomic bitset operations
Reviewed-by: aboldtch, coleenp
This commit is contained in:
@@ -168,7 +168,7 @@ public:
|
||||
//
|
||||
// Requirements:
|
||||
// - T is an integral type
|
||||
// - sizeof(T) == sizeof(int) || sizeof(T) == sizeof(void*)
|
||||
// - sizeof(T) == 1 || sizeof(T) == sizeof(int) || sizeof(T) == sizeof(void*)
|
||||
|
||||
// Performs atomic bitwise-and of *dest and bits, storing the result in
|
||||
// *dest. Returns the prior value of *dest. That is, atomically performs
|
||||
|
||||
@@ -205,14 +205,15 @@ struct AtomicBitopsTestSupport {
|
||||
volatile T _test_value;
|
||||
|
||||
// At least one byte differs between _old_value and _old_value op _change_value.
|
||||
static const T _old_value = static_cast<T>(UCONST64(0x7f5300007f530000));
|
||||
static const T _change_value = static_cast<T>(UCONST64(0x3800530038005300));
|
||||
static const T _old_value = static_cast<T>(UCONST64(0x7f5300007f530044));
|
||||
static const T _change_value = static_cast<T>(UCONST64(0x3800530038005322));
|
||||
|
||||
AtomicBitopsTestSupport() : _test_value(0) {}
|
||||
|
||||
void fetch_then_and() {
|
||||
Atomic::store(&_test_value, _old_value);
|
||||
T expected = _old_value & _change_value;
|
||||
EXPECT_NE(_old_value, expected);
|
||||
T result = Atomic::fetch_then_and(&_test_value, _change_value);
|
||||
EXPECT_EQ(_old_value, result);
|
||||
EXPECT_EQ(expected, Atomic::load(&_test_value));
|
||||
@@ -221,6 +222,7 @@ struct AtomicBitopsTestSupport {
|
||||
void fetch_then_or() {
|
||||
Atomic::store(&_test_value, _old_value);
|
||||
T expected = _old_value | _change_value;
|
||||
EXPECT_NE(_old_value, expected);
|
||||
T result = Atomic::fetch_then_or(&_test_value, _change_value);
|
||||
EXPECT_EQ(_old_value, result);
|
||||
EXPECT_EQ(expected, Atomic::load(&_test_value));
|
||||
@@ -229,6 +231,7 @@ struct AtomicBitopsTestSupport {
|
||||
void fetch_then_xor() {
|
||||
Atomic::store(&_test_value, _old_value);
|
||||
T expected = _old_value ^ _change_value;
|
||||
EXPECT_NE(_old_value, expected);
|
||||
T result = Atomic::fetch_then_xor(&_test_value, _change_value);
|
||||
EXPECT_EQ(_old_value, result);
|
||||
EXPECT_EQ(expected, Atomic::load(&_test_value));
|
||||
@@ -237,6 +240,7 @@ struct AtomicBitopsTestSupport {
|
||||
void and_then_fetch() {
|
||||
Atomic::store(&_test_value, _old_value);
|
||||
T expected = _old_value & _change_value;
|
||||
EXPECT_NE(_old_value, expected);
|
||||
T result = Atomic::and_then_fetch(&_test_value, _change_value);
|
||||
EXPECT_EQ(expected, result);
|
||||
EXPECT_EQ(expected, Atomic::load(&_test_value));
|
||||
@@ -245,6 +249,7 @@ struct AtomicBitopsTestSupport {
|
||||
void or_then_fetch() {
|
||||
Atomic::store(&_test_value, _old_value);
|
||||
T expected = _old_value | _change_value;
|
||||
EXPECT_NE(_old_value, expected);
|
||||
T result = Atomic::or_then_fetch(&_test_value, _change_value);
|
||||
EXPECT_EQ(expected, result);
|
||||
EXPECT_EQ(expected, Atomic::load(&_test_value));
|
||||
@@ -253,6 +258,7 @@ struct AtomicBitopsTestSupport {
|
||||
void xor_then_fetch() {
|
||||
Atomic::store(&_test_value, _old_value);
|
||||
T expected = _old_value ^ _change_value;
|
||||
EXPECT_NE(_old_value, expected);
|
||||
T result = Atomic::xor_then_fetch(&_test_value, _change_value);
|
||||
EXPECT_EQ(expected, result);
|
||||
EXPECT_EQ(expected, Atomic::load(&_test_value));
|
||||
@@ -278,6 +284,14 @@ const T AtomicBitopsTestSupport<T>::_old_value;
|
||||
template<typename T>
|
||||
const T AtomicBitopsTestSupport<T>::_change_value;
|
||||
|
||||
TEST(AtomicBitopsTest, int8) {
|
||||
AtomicBitopsTestSupport<int8_t>()();
|
||||
}
|
||||
|
||||
TEST(AtomicBitopsTest, uint8) {
|
||||
AtomicBitopsTestSupport<uint8_t>()();
|
||||
}
|
||||
|
||||
TEST(AtomicBitopsTest, int32) {
|
||||
AtomicBitopsTestSupport<int32_t>()();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user