Skip to content

Commit

Permalink
Reviews comments, added uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Dec 11, 2024
1 parent 5c7d9f9 commit a7a6c41
Showing 1 changed file with 54 additions and 14 deletions.
68 changes: 54 additions & 14 deletions test/hotspot/gtest/riscv/test_assembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
#include "asm/assembler.inline.hpp"
#include "asm/macroAssembler.hpp"
#include "memory/resourceArea.hpp"
#include "metaprogramming/enableIf.hpp"
#include "runtime/orderAccess.hpp"
#include "threadHelper.inline.hpp"
#include "unittest.hpp"

#include <limits>

typedef int64_t (*zicond_func)(int64_t cmp1, int64_t cmp2, int64_t dst, int64_t src);
typedef void (MacroAssembler::*cmov_func)(Register cmp1, Register cmp2, Register dst, Register src);

Expand Down Expand Up @@ -287,6 +290,19 @@ TEST_VM(RiscV, cmpxchg_int32_maybe_zacas) {
}
}

TEST_VM(RiscV, cmpxchg_uint32_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_plain_cmpxchg_tests<uint32_t, Assembler::uint32>();
UseZacas = zacas;
}

TEST_VM(RiscV, cmpxchg_uint32_maybe_zacas) {
if (UseZacas) {
run_plain_cmpxchg_tests<uint32_t, Assembler::uint32>();
}
}

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
static void run_narrow_cmpxchg_tests() {
CmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg(0, false);
Expand Down Expand Up @@ -351,28 +367,24 @@ TESTSIZE next_count(TESTSIZE now, TESTSIZE add) {
return now + add;
}
TESTSIZE diff = std::numeric_limits<TESTSIZE>::max() - now;
add -= diff;
add -= diff + 1; // add one to the diff for the wrap around.
return std::numeric_limits<TESTSIZE>::min() + add;
}

constexpr int64_t PAR_IT_END = 10000;
constexpr int64_t NUMBER_THREADS = 4;
constexpr int64_t TOTAL_ITERATIONS = NUMBER_THREADS * PAR_IT_END;

template <typename TESTSIZE>
template <typename TESTSIZE, ENABLE_IF(std::numeric_limits<TESTSIZE>::max() < (std::numeric_limits<TESTSIZE>::min() + TOTAL_ITERATIONS))>
constexpr TESTSIZE result_count() {
if (std::numeric_limits<TESTSIZE>::max() > (std::numeric_limits<TESTSIZE>::min() + TOTAL_ITERATIONS)) {
return std::numeric_limits<TESTSIZE>::min() + TOTAL_ITERATIONS;
}
int64_t range = std::numeric_limits<TESTSIZE>::max();
range -= std::numeric_limits<TESTSIZE>::min();
int64_t range = std::numeric_limits<TESTSIZE>::max() - std::numeric_limits<TESTSIZE>::min() + 1;
int64_t rest = TOTAL_ITERATIONS % range;
return std::numeric_limits<TESTSIZE>::min() + rest;
}

template<>
constexpr int64_t result_count<int64_t>() {
return std::numeric_limits<int64_t>::min() + TOTAL_ITERATIONS;
template <typename TESTSIZE, ENABLE_IF(std::numeric_limits<TESTSIZE>::max() > (std::numeric_limits<TESTSIZE>::min() + TOTAL_ITERATIONS))>
constexpr TESTSIZE result_count() {
return std::numeric_limits<TESTSIZE>::min() + TOTAL_ITERATIONS;
}

template <typename TESTSIZE, Assembler::operand_size ASMSIZE>
Expand Down Expand Up @@ -449,6 +461,21 @@ TEST_VM(RiscV, cmpxchg_int32_concurrent_maybe_zacas) {
}
}

TEST_VM(RiscV, cmpxchg_uint32_concurrent_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_concurrent_cmpxchg_tests<uint32_t, Assembler::uint32>();
run_concurrent_alt_cmpxchg_tests<uint32_t, Assembler::uint32>();
UseZacas = zacas;
}

TEST_VM(RiscV, cmpxchg_uint32_concurrent_maybe_zacas) {
if (UseZacas) {
run_concurrent_cmpxchg_tests<uint32_t, Assembler::uint32>();
run_concurrent_alt_cmpxchg_tests<uint32_t, Assembler::uint32>();
}
}

TEST_VM(RiscV, cmpxchg_int16_concurrent_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
Expand Down Expand Up @@ -532,13 +559,13 @@ void run_weak_cmpxchg_tests() {
WeakCmpxchgTester<TESTSIZE, ASMSIZE> cmpxchg;
TESTSIZE data = 121;
TESTSIZE ret = cmpxchg.weak_cmpxchg((intptr_t)&data, 121, 42);
ASSERT_EQ(ret, 1);
ASSERT_EQ(data, 42);
ASSERT_EQ(ret, (TESTSIZE)1);
ASSERT_EQ(data, (TESTSIZE)42);

data = 121;
ret = cmpxchg.weak_cmpxchg((intptr_t)&data, 120, 42);
ASSERT_EQ(ret, 0);
ASSERT_EQ(data, 121);
ASSERT_EQ(ret, (TESTSIZE)0);
ASSERT_EQ(data, (TESTSIZE)121);
}

TEST_VM(RiscV, weak_cmpxchg_int64_lr_sc) {
Expand Down Expand Up @@ -567,6 +594,19 @@ TEST_VM(RiscV, weak_cmpxchg_int32_maybe_zacas) {
}
}

TEST_VM(RiscV, weak_cmpxchg_uint32_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
run_weak_cmpxchg_tests<uint32_t, Assembler::uint32>();
UseZacas = zacas;
}

TEST_VM(RiscV, weak_cmpxchg_uint32_maybe_zacas) {
if (UseZacas) {
run_weak_cmpxchg_tests<uint32_t, Assembler::uint32>();
}
}

TEST_VM(RiscV, weak_cmpxchg_int16_lr_sc) {
bool zacas = UseZacas;
UseZacas = false;
Expand Down

0 comments on commit a7a6c41

Please sign in to comment.