Skip to content

Commit

Permalink
Better conc
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Dec 4, 2024
1 parent 919d445 commit 21e87e6
Showing 1 changed file with 76 additions and 20 deletions.
96 changes: 76 additions & 20 deletions test/hotspot/gtest/riscv/test_assembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CmovTester {
}
};

void run_cmov_tests() {
static void run_cmov_tests() {
// If 42(a0) eq 42(a1): assign dest(a2/66) the src(a3/77), expect result: 77
CmovTester::test(&MacroAssembler::cmov_eq, 42, 42, 66, 77, 77);
// If 41(a0) eq 42(a1): assign dest(a2/66) the src(a3/77), expect result: 66
Expand Down Expand Up @@ -166,7 +166,7 @@ class CmpxchgTester {
};

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
void plain_cmpxchg_test(int variant, TESTSIZE dv, TESTSIZE ex, TESTSIZE nv, TESTSIZE eret, TESTSIZE edata, bool bv) {
static void plain_cmpxchg_test(int variant, TESTSIZE dv, TESTSIZE ex, TESTSIZE nv, TESTSIZE eret, TESTSIZE edata, bool bv) {
CmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg(variant, bv);
TESTSIZE data = dv;
TESTSIZE ret = cmpxchg.cmpxchg((intptr_t)&data, ex, nv);
Expand All @@ -175,7 +175,7 @@ void plain_cmpxchg_test(int variant, TESTSIZE dv, TESTSIZE ex, TESTSIZE nv, TEST
}

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
void run_plain_cmpxchg_tests() {
static void run_plain_cmpxchg_tests() {
// Normal
plain_cmpxchg_test<TESTSIZE, ASMSIZE>( 0 /* variant */ , 1337 /* start value*/,
1337 /* expected */, 42 /* new value */,
Expand Down Expand Up @@ -245,27 +245,27 @@ void run_plain_cmpxchg_tests() {
0 /* return */ , 1337 /* end value*/, true /* boolean ret*/);
}

TEST_VM(RiscV, cmpxchg_int64_plain_lr_sc) {
TEST_VM(RiscV, cmpxchg_int64_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_plain_cmpxchg_tests<int64_t, Assembler::int64>();
UseZacas = zacas;
}

TEST_VM(RiscV, cmpxchg_int64_plain_maybe_zacas) {
TEST_VM(RiscV, cmpxchg_int64_maybe_zacas) {
if (UseZacas) {
run_plain_cmpxchg_tests<int64_t, Assembler::int64>();
}
}

TEST_VM(RiscV, cmpxchg_int32_plain_lr_sc) {
TEST_VM(RiscV, cmpxchg_int32_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_plain_cmpxchg_tests<int32_t, Assembler::int32>();
UseZacas = zacas;
}

TEST_VM(RiscV, cmpxchg_int32_plain_maybe_zacas) {
TEST_VM(RiscV, cmpxchg_int32_maybe_zacas) {
if (UseZacas) {
run_plain_cmpxchg_tests<int32_t, Assembler::int32>();
}
Expand All @@ -277,14 +277,13 @@ void run_concurrent_cmpxchg_tests() {
int num_threads = 4;
CmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg(0, false); // variant 0, not bool ret
auto incThread = [&](Thread* _current, int _id) {
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 10000; i++) {
TESTSIZE oldvalue = _id + num_threads * i;
TESTSIZE newvalue = oldvalue + 1;
TESTSIZE ret;
do {
ret = cmpxchg.cmpxchg((intptr_t)&data, oldvalue, newvalue);
} while (ret != oldvalue);
break;
}
};
TestThreadGroup<decltype(incThread)> ttg(incThread, num_threads);
Expand Down Expand Up @@ -320,13 +319,16 @@ TEST_VM(RiscV, cmpxchg_int32_concurrent_maybe_zacas) {

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
class NarrowCmpxchgTester {
public:
typedef TESTSIZE (*cmpxchg_func)(intptr_t addr, TESTSIZE expected, TESTSIZE new_value, TESTSIZE result,
int64_t scratch0, int64_t scratch1, int64_t scratch2);

static TESTSIZE narrow_cmpxchg(intptr_t addr, TESTSIZE expected, TESTSIZE new_value, TESTSIZE result, bool boolean_result = false) {
BufferBlob* bb = BufferBlob::create("riscvTest", 128);
CodeBuffer code(bb);
BufferBlob* _bb;
cmpxchg_func _func;

public:
NarrowCmpxchgTester(bool boolean_result) {
_bb = BufferBlob::create("riscvTest", 128);
CodeBuffer code(_bb);
MacroAssembler _masm(&code);
address entry = _masm.pc();
{
Expand All @@ -337,37 +339,45 @@ class NarrowCmpxchgTester {
_masm.ret();
}
_masm.flush(); // icache invalidate
TESTSIZE ret = ((cmpxchg_func)entry)(addr, expected, new_value, result, -1, -1, -1);
BufferBlob::free(bb);
return ret;
_func = ((cmpxchg_func)entry);
}

~NarrowCmpxchgTester() {
BufferBlob::free(_bb);
}

TESTSIZE narrow_cmpxchg(intptr_t addr, TESTSIZE expected, TESTSIZE new_value) {
return _func(addr, expected, new_value, /* dummy result */ 67, -1, -1, -1);
}
};

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
void run_narrow_cmpxchg_tests() {
NarrowCmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg(false);
NarrowCmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg_bool(true);
// Assume natural aligned
TESTSIZE data[8];
TESTSIZE ret;
for (int i = 0; i < 7; i++) {
memset(data, -1, sizeof(data));

data[i] = 121;
ret = NarrowCmpxchgTester<TESTSIZE, ASMSIZE>::narrow_cmpxchg((intptr_t)&data[i], 121, 42, /* result */ 67, false);
ret = cmpxchg.narrow_cmpxchg((intptr_t)&data[i], 121, 42);
ASSERT_EQ(ret, 121);
ASSERT_EQ(data[i], 42);

data[i] = 121;
ret = NarrowCmpxchgTester<TESTSIZE, ASMSIZE>::narrow_cmpxchg((intptr_t)&data[i], 120, 42, /* result */ 67, false);
ret = cmpxchg.narrow_cmpxchg((intptr_t)&data[i], 120, 42);
ASSERT_EQ(ret, 121);
ASSERT_EQ(data[i], 121);

data[i] = 121;
ret = NarrowCmpxchgTester<TESTSIZE, ASMSIZE>::narrow_cmpxchg((intptr_t)&data[i], 121, 42, /* result */ 67, true);
ret = cmpxchg_bool.narrow_cmpxchg((intptr_t)&data[i], 121, 42);
ASSERT_EQ(ret, 1);
ASSERT_EQ(data[i], 42);

data[i] = 121;
ret = NarrowCmpxchgTester<TESTSIZE, ASMSIZE>::narrow_cmpxchg((intptr_t)&data[i], 120, 42, /* result */ 67, true);
ret = cmpxchg_bool.narrow_cmpxchg((intptr_t)&data[i], 120, 42);
ASSERT_EQ(ret, 0);
ASSERT_EQ(data[i], 121);
}
Expand Down Expand Up @@ -399,4 +409,50 @@ TEST_VM(RiscV, cmpxchg_int8_maybe_zacas) {
}
}

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
void run_concurrent_narrow_cmpxchg_tests() {
volatile TESTSIZE data = 0;
int num_threads = 4;
NarrowCmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg(false); // variant 0, not bool ret
auto incThread = [&](Thread* _current, int _id) {
for (int i = 0; i < 10000; i++) {
TESTSIZE oldvalue = _id + num_threads * i;
TESTSIZE newvalue = oldvalue + 1;
TESTSIZE ret;
do {
ret = cmpxchg.narrow_cmpxchg((intptr_t)&data, oldvalue, newvalue);
} while (ret != oldvalue);
}
};
TestThreadGroup<decltype(incThread)> ttg(incThread, num_threads);
ttg.doit();
ttg.join();
}

TEST_VM(RiscV, cmpxchg_int16_concurrent_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_concurrent_narrow_cmpxchg_tests<int16_t, Assembler::int16>();
UseZacas = zacas;
}

TEST_VM(RiscV, cmpxchg_int16_concurrent_maybe_zacas) {
if (UseZacas) {
run_concurrent_narrow_cmpxchg_tests<int16_t, Assembler::int16>();
}
}

TEST_VM(RiscV, cmpxchg_int8_concurrent_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_concurrent_narrow_cmpxchg_tests<int8_t, Assembler::int8>();
UseZacas = zacas;
}

TEST_VM(RiscV, cmpxchg_int8_concurrent_maybe_zacas) {
if (UseZacas) {
run_concurrent_narrow_cmpxchg_tests<int8_t, Assembler::int8>();
}
}

#endif // RISCV

0 comments on commit 21e87e6

Please sign in to comment.