From a7a6c41325a92fb4b1f0596bfa5bc5d14e05cb79 Mon Sep 17 00:00:00 2001 From: Robbin Ehn Date: Wed, 11 Dec 2024 10:16:09 +0100 Subject: [PATCH] Reviews comments, added uint32 --- .../gtest/riscv/test_assembler_riscv.cpp | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/test/hotspot/gtest/riscv/test_assembler_riscv.cpp b/test/hotspot/gtest/riscv/test_assembler_riscv.cpp index 3a0e4c50bf839..1e06ab19369f7 100644 --- a/test/hotspot/gtest/riscv/test_assembler_riscv.cpp +++ b/test/hotspot/gtest/riscv/test_assembler_riscv.cpp @@ -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 + 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); @@ -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(); + UseZacas = zacas; +} + +TEST_VM(RiscV, cmpxchg_uint32_maybe_zacas) { + if (UseZacas) { + run_plain_cmpxchg_tests(); + } +} + template static void run_narrow_cmpxchg_tests() { CmpxchgTester cmpxchg(0, false); @@ -351,7 +367,7 @@ TESTSIZE next_count(TESTSIZE now, TESTSIZE add) { return now + add; } TESTSIZE diff = std::numeric_limits::max() - now; - add -= diff; + add -= diff + 1; // add one to the diff for the wrap around. return std::numeric_limits::min() + add; } @@ -359,20 +375,16 @@ constexpr int64_t PAR_IT_END = 10000; constexpr int64_t NUMBER_THREADS = 4; constexpr int64_t TOTAL_ITERATIONS = NUMBER_THREADS * PAR_IT_END; -template +template ::max() < (std::numeric_limits::min() + TOTAL_ITERATIONS))> constexpr TESTSIZE result_count() { - if (std::numeric_limits::max() > (std::numeric_limits::min() + TOTAL_ITERATIONS)) { - return std::numeric_limits::min() + TOTAL_ITERATIONS; - } - int64_t range = std::numeric_limits::max(); - range -= std::numeric_limits::min(); + int64_t range = std::numeric_limits::max() - std::numeric_limits::min() + 1; int64_t rest = TOTAL_ITERATIONS % range; return std::numeric_limits::min() + rest; } -template<> -constexpr int64_t result_count() { - return std::numeric_limits::min() + TOTAL_ITERATIONS; +template ::max() > (std::numeric_limits::min() + TOTAL_ITERATIONS))> +constexpr TESTSIZE result_count() { + return std::numeric_limits::min() + TOTAL_ITERATIONS; } template @@ -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(); + run_concurrent_alt_cmpxchg_tests(); + UseZacas = zacas; +} + +TEST_VM(RiscV, cmpxchg_uint32_concurrent_maybe_zacas) { + if (UseZacas) { + run_concurrent_cmpxchg_tests(); + run_concurrent_alt_cmpxchg_tests(); + } +} + TEST_VM(RiscV, cmpxchg_int16_concurrent_lr_sc) { bool zacas = UseZacas; UseZacas = false; @@ -532,13 +559,13 @@ void run_weak_cmpxchg_tests() { WeakCmpxchgTester 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) { @@ -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(); + UseZacas = zacas; +} + +TEST_VM(RiscV, weak_cmpxchg_uint32_maybe_zacas) { + if (UseZacas) { + run_weak_cmpxchg_tests(); + } +} + TEST_VM(RiscV, weak_cmpxchg_int16_lr_sc) { bool zacas = UseZacas; UseZacas = false;