Skip to content

Commit

Permalink
baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Nov 28, 2024
1 parent edfe285 commit c0dd4e1
Showing 1 changed file with 198 additions and 0 deletions.
198 changes: 198 additions & 0 deletions test/hotspot/gtest/riscv/test_assembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,202 @@ TEST_VM(RiscV, cmov) {
}
}


template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
class CmpxchgTester {
public:
typedef TESTSIZE (*cmpxchg_func)(intptr_t addr, TESTSIZE expected, TESTSIZE new_value, TESTSIZE result);
typedef TESTSIZE (*cmpxchg_func_spec)(intptr_t addr, TESTSIZE expected, TESTSIZE new_value);

static TESTSIZE simple_cmpxchg(intptr_t addr, TESTSIZE expected, TESTSIZE new_value, TESTSIZE result, bool boolean_result = false) {
BufferBlob* bb = BufferBlob::create("riscvTest", 128);
CodeBuffer code(bb);
MacroAssembler _masm(&code);
address entry = _masm.pc();
{
_masm.cmpxchg(/*addr*/ c_rarg0, /*expected*/ c_rarg1, /*new_value*/c_rarg2,
ASMSIZE, Assembler::relaxed, Assembler::relaxed,
/*result*/ c_rarg3, boolean_result);
_masm.mv(c_rarg0, c_rarg3);
_masm.ret();
}
_masm.flush();
OrderAccess::cross_modify_fence();
TESTSIZE ret = ((cmpxchg_func)entry)(addr, expected, new_value, result);
BufferBlob::free(bb);
return ret;
}

// expected == result
static TESTSIZE simple_cmpxchg_spec1(intptr_t addr, TESTSIZE expected, TESTSIZE new_value, bool boolean_result = false) {
BufferBlob* bb = BufferBlob::create("riscvTest", 128);
CodeBuffer code(bb);
MacroAssembler _masm(&code);
address entry = _masm.pc();
{
_masm.cmpxchg(/*addr*/ c_rarg0, /*expected*/ c_rarg1, /*new_value*/c_rarg2,
ASMSIZE, Assembler::relaxed, Assembler::relaxed,
/*result*/ c_rarg1, boolean_result);
_masm.mv(c_rarg0, c_rarg1);
_masm.ret();
}
_masm.flush();
OrderAccess::cross_modify_fence();
TESTSIZE ret = ((cmpxchg_func_spec)entry)(addr, expected, new_value);
BufferBlob::free(bb);
return ret;
}

// new_value == result
static TESTSIZE simple_cmpxchg_spec2(intptr_t addr, TESTSIZE expected, TESTSIZE new_value, bool boolean_result = false) {
BufferBlob* bb = BufferBlob::create("riscvTest", 128);
CodeBuffer code(bb);
MacroAssembler _masm(&code);
address entry = _masm.pc();
{
_masm.cmpxchg(/*addr*/ c_rarg0, /*expected*/ c_rarg1, /*new_value*/c_rarg2,
ASMSIZE, Assembler::relaxed, Assembler::relaxed,
/*result*/ c_rarg2, boolean_result);
_masm.mv(c_rarg0, c_rarg2);
_masm.ret();
}
_masm.flush();
OrderAccess::cross_modify_fence();
TESTSIZE ret = ((cmpxchg_func_spec)entry)(addr, expected, new_value);
BufferBlob::free(bb);
return ret;
}

// expected == new_value
static TESTSIZE simple_cmpxchg_spec3(intptr_t addr, TESTSIZE new_value, TESTSIZE result, bool boolean_result = false) {
BufferBlob* bb = BufferBlob::create("riscvTest", 128);
CodeBuffer code(bb);
MacroAssembler _masm(&code);
address entry = _masm.pc();
{
_masm.cmpxchg(/*addr*/ c_rarg0, /*expected*/ c_rarg1, /*new_value*/ c_rarg1,
ASMSIZE, Assembler::relaxed, Assembler::relaxed,
/*result*/ c_rarg2, boolean_result);
_masm.mv(c_rarg0, c_rarg2);
_masm.ret();
}
_masm.flush();
OrderAccess::cross_modify_fence();
TESTSIZE ret = ((cmpxchg_func_spec)entry)(addr, new_value, result);
BufferBlob::free(bb);
return ret;
}
};

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
void run_plain_cmpxchg_tests() {
TESTSIZE data = 1337;
TESTSIZE ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg((intptr_t)&data, 1337, 42, /* dummy */ 67);
ASSERT_EQ(ret, 1337); // ret should be old value
ASSERT_EQ(data, 42); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg((intptr_t)&data, 1336, 42, /* dummy */ 67);
ASSERT_EQ(ret, 1337); // ret should be old value
ASSERT_EQ(data, 1337); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg((intptr_t)&data, 1337, 42, /* dummy */ 67, true);
ASSERT_EQ(ret, 1); // ret should be boolean truee
ASSERT_EQ(data, 42); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg((intptr_t)&data, 1336, 42, /* dummy */ 67, true);
ASSERT_EQ(ret, 0); // ret should be boolean false
ASSERT_EQ(data, 1337); // data should be new value

// Register _result_ may be the same register as _new_val_ or _expected_.
data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec1((intptr_t)&data, 1337, 42);
ASSERT_EQ(ret, 1337); // ret should be old value
ASSERT_EQ(data, 42); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec2((intptr_t)&data, 1337, 42);
ASSERT_EQ(ret, 1337); // ret should be old value
ASSERT_EQ(data, 42); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec1((intptr_t)&data, 1336, 42);
ASSERT_EQ(ret, 1337); // ret should be old value
ASSERT_EQ(data, 1337); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec2((intptr_t)&data, 1336, 42);
ASSERT_EQ(ret, 1337); // ret should be old value
ASSERT_EQ(data, 1337); // data should be new value

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec1((intptr_t)&data, 1337, 42, true);
ASSERT_EQ(ret, 1);
ASSERT_EQ(data, 42);

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec2((intptr_t)&data, 1337, 42, true);
ASSERT_EQ(ret, 1);
ASSERT_EQ(data, 42);

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec1((intptr_t)&data, 1336, 42, true);
ASSERT_EQ(ret, 0);
ASSERT_EQ(data, 1337);

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec2((intptr_t)&data, 1336, 42, true);
ASSERT_EQ(ret, 0);
ASSERT_EQ(data, 1337);

// Register _expected_ may be the same register as _new_val_ and is assumed to be preserved.
data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec3((intptr_t)&data, 1337, /* dummy */ 66);
ASSERT_EQ(ret, 1337);
ASSERT_EQ(data, 1337);

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec3((intptr_t)&data, 1336, /* dummy */ 66);
ASSERT_EQ(ret, 1337);
ASSERT_EQ(data, 1337);

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec3((intptr_t)&data, 1337, /* dummy */ 66, true);
ASSERT_EQ(ret, 1);
ASSERT_EQ(data, 1337);

data = 1337;
ret = CmpxchgTester<TESTSIZE, ASMSIZE>::simple_cmpxchg_spec3((intptr_t)&data, 1336, /* dummy */ 66, true);
ASSERT_EQ(ret, 0);
ASSERT_EQ(data, 1337);
}

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

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

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

TEST_VM(RiscV, cmpxchg_int32_plain_zacas) {
if (UseZacas) {
run_plain_cmpxchg_tests<int32_t, Assembler::int32>();
}
}

#endif // RISCV

0 comments on commit c0dd4e1

Please sign in to comment.