[libc-commits] [libc] [libc][mathvec] Avoid overlapping exhaustive test shards (PR #241106)
via libc-commits
libc-commits at lists.llvm.org
Tue Nov 10 20:11:22 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: sriramshastry
<details>
<summary>Changes</summary>
Adapt half-open worker shards to the inclusive checker and preserve the final storage value in full-range runs. Add range and endpoint regressions.
Assisted-by: GitHub Copilot
---
Full diff: https://github.com/llvm/llvm-project/pull/241106.diff
3 Files Affected:
- (modified) libc/test/src/mathvec/exhaustive/CMakeLists.txt (+14)
- (modified) libc/test/src/mathvec/exhaustive/exhaustive_test.h (+31-11)
- (added) libc/test/src/mathvec/exhaustive/range_test.cpp (+103)
``````````diff
diff --git a/libc/test/src/mathvec/exhaustive/CMakeLists.txt b/libc/test/src/mathvec/exhaustive/CMakeLists.txt
index 099678f5121f65..414ed34703dacd 100644
--- a/libc/test/src/mathvec/exhaustive/CMakeLists.txt
+++ b/libc/test/src/mathvec/exhaustive/CMakeLists.txt
@@ -473,3 +473,17 @@ add_fp_unittest(
LINK_LIBRARIES
-lpthread
)
+
+add_fp_unittest(
+ range_test
+ SUITE
+ libc-mathvec-tests
+ SRCS
+ range_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.CPP.simd
+ LINK_LIBRARIES
+ -lpthread
+)
diff --git a/libc/test/src/mathvec/exhaustive/exhaustive_test.h b/libc/test/src/mathvec/exhaustive/exhaustive_test.h
index 4a1249af7b7622..db6b683b890116 100644
--- a/libc/test/src/mathvec/exhaustive/exhaustive_test.h
+++ b/libc/test/src/mathvec/exhaustive/exhaustive_test.h
@@ -29,9 +29,10 @@
// - FloatType: define floating point type to be used.
// - FPBits: fputil::FPBits<FloatType>.
// - StorageType: define bit type for the corresponding floating point type.
-// - uint64_t check(start, stop, rounding_mode): a method to test in given
-// range for a given rounding mode, which returns the number of
-// failures.
+// - uint64_t check(start, stop, rounding_mode): a method to test the
+// inclusive
+// range [start, stop] for a given rounding mode, returning the number
+// of failures.
// 2. Use LlvmLibcExhaustiveMathTest<Checker> class
// 3. Call: test_full_range_<RoundingMode>(start, stop)
// or test_full_range_all_roundings(start, stop).
@@ -50,12 +51,12 @@ struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<FloatType>;
using StorageType = typename FPBits::StorageType;
- // Check in a range, return the number of failures.
+ // Check the inclusive range [start, stop], returning the number of failures.
uint64_t check(StorageType start, StorageType stop,
LIBC_NAMESPACE::fputil::testing::RoundingMode rounding) {
LIBC_NAMESPACE::fputil::testing::ForceRoundingMode r(rounding);
if (!r.success)
- return (stop > start);
+ return (stop >= start);
StorageType bits = start;
uint64_t failed = 0;
@@ -151,7 +152,7 @@ struct LlvmLibcExhaustiveMathvecTest
}
uint64_t failed_in_range =
- Checker::check(range_begin, range_end, rounding);
+ Checker::check(range_begin, range_end - 1, rounding);
if (failed_in_range > 0) {
std::stringstream msg;
msg << "Test failed for " << std::dec << failed_in_range
@@ -215,16 +216,35 @@ struct LlvmLibcExhaustiveMathvecTest
static constexpr StorageType STORAGE_MAX =
LIBC_NAMESPACE::cpp::numeric_limits<StorageType>::max();
- void test_full_range_RN() { test_full_range_RN(0, STORAGE_MAX); }
+ void test_last_input(LIBC_NAMESPACE::fputil::testing::RoundingMode rounding) {
+ ASSERT_EQ(Checker::check(STORAGE_MAX, STORAGE_MAX, rounding), uint64_t(0));
+ }
+
+ void test_full_range_RN() {
+ test_full_range_RN(0, STORAGE_MAX);
+ test_last_input(LIBC_NAMESPACE::fputil::testing::RoundingMode::Nearest);
+ }
- void test_full_range_RU() { test_full_range_RU(0, STORAGE_MAX); }
+ void test_full_range_RU() {
+ test_full_range_RU(0, STORAGE_MAX);
+ test_last_input(LIBC_NAMESPACE::fputil::testing::RoundingMode::Upward);
+ }
- void test_full_range_RD() { test_full_range_RD(0, STORAGE_MAX); }
+ void test_full_range_RD() {
+ test_full_range_RD(0, STORAGE_MAX);
+ test_last_input(LIBC_NAMESPACE::fputil::testing::RoundingMode::Downward);
+ }
- void test_full_range_RZ() { test_full_range_RZ(0, STORAGE_MAX); }
+ void test_full_range_RZ() {
+ test_full_range_RZ(0, STORAGE_MAX);
+ test_last_input(LIBC_NAMESPACE::fputil::testing::RoundingMode::TowardZero);
+ }
void test_full_range_all_roundings() {
- test_full_range_all_roundings(0, STORAGE_MAX);
+ test_full_range_RN();
+ test_full_range_RU();
+ test_full_range_RD();
+ test_full_range_RZ();
}
};
diff --git a/libc/test/src/mathvec/exhaustive/range_test.cpp b/libc/test/src/mathvec/exhaustive/range_test.cpp
new file mode 100644
index 00000000000000..9af40fd83cdaeb
--- /dev/null
+++ b/libc/test/src/mathvec/exhaustive/range_test.cpp
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "exhaustive_test.h"
+#include "test/UnitTest/Test.h"
+
+namespace {
+
+std::atomic<uint64_t> seen[256];
+uint64_t scalar_calls;
+
+float identity(float x) {
+ ++scalar_calls;
+ return x;
+}
+
+LIBC_VECTOR_PCS LIBC_NAMESPACE::cpp::simd<float>
+vector_identity(LIBC_NAMESPACE::cpp::simd<float> x) {
+ return x;
+}
+
+using LlvmLibcMathvecMaxInputTest =
+ UnaryOpChecker<float, float, identity, vector_identity>;
+
+struct CountingChecker : public virtual LIBC_NAMESPACE::testing::Test {
+ using FloatType = float;
+ // Keep the full storage domain small enough for a unit test.
+ using StorageType = uint8_t;
+ struct FPBits {
+ explicit FPBits(StorageType bits) : bits(bits) {}
+ FloatType get_val() const {
+ return LIBC_NAMESPACE::fputil::FPBits<FloatType>(uint32_t(bits))
+ .get_val();
+ }
+ StorageType bits;
+ };
+
+ uint64_t check(StorageType start, StorageType stop,
+ LIBC_NAMESPACE::fputil::testing::RoundingMode) {
+ for (unsigned bits = start; bits <= stop; ++bits)
+ seen[bits].fetch_add(1, std::memory_order_relaxed);
+ return 0;
+ }
+};
+
+struct LlvmLibcMathvecRangeTest
+ : public LlvmLibcExhaustiveMathvecTest<CountingChecker, 3> {
+ void SetUp() override {
+ for (auto &count : seen)
+ count.store(0, std::memory_order_relaxed);
+ }
+
+ void expect_counts(unsigned start, unsigned stop, uint64_t count = 1) {
+ for (unsigned bits = 0; bits < 256; ++bits)
+ EXPECT_EQ(seen[bits].load(std::memory_order_relaxed),
+ bits >= start && bits < stop ? count : uint64_t(0));
+ }
+};
+
+} // namespace
+
+TEST_F(LlvmLibcMathvecMaxInputTest, MaximumBitPatternOnce) {
+ scalar_calls = 0;
+ EXPECT_EQ(check(UINT32_MAX, UINT32_MAX,
+ LIBC_NAMESPACE::fputil::testing::RoundingMode::Nearest),
+ uint64_t(0));
+ EXPECT_EQ(scalar_calls, uint64_t(1));
+}
+
+TEST_F(LlvmLibcMathvecRangeTest, EmptyRange) {
+ test_full_range_RN(7, 7);
+ expect_counts(0, 0);
+}
+
+TEST_F(LlvmLibcMathvecRangeTest, SingleInput) {
+ test_full_range_RN(7, 8);
+ expect_counts(7, 8);
+}
+
+TEST_F(LlvmLibcMathvecRangeTest, AdjacentShards) {
+ test_full_range_RN(5, 15);
+ expect_counts(5, 15);
+}
+
+TEST_F(LlvmLibcMathvecRangeTest, FinalShard) {
+ test_full_range_RN(250, 255);
+ expect_counts(250, 255);
+}
+
+TEST_F(LlvmLibcMathvecRangeTest, FullStorageRange) {
+ test_full_range_RN();
+ expect_counts(0, 256);
+}
+
+TEST_F(LlvmLibcMathvecRangeTest, FullStorageRangeAllRoundings) {
+ test_full_range_all_roundings();
+ expect_counts(0, 256, 4);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/241106
More information about the libc-commits
mailing list