[libc-commits] [libc] [libc][mathvec] Check every lane in exhaustive tests (PR #241104)
via libc-commits
libc-commits at lists.llvm.org
Wed Nov 18 19:40:25 PST 2026
https://github.com/sriramshastry updated https://github.com/llvm/llvm-project/pull/241104
>From 466e708ee246d7f5d71858bbdf3861bdb4720ec3 Mon Sep 17 00:00:00 2001
From: sriramshastry <sriramshastry at gmail.com>
Date: Tue, 10 Nov 2026 18:52:59 +0000
Subject: [PATCH] [libc][mathvec] Check every lane in exhaustive tests
Compare each broadcast result lane with the scalar reference and report the first mismatch. Add exact, tolerant, and signed-zero checker regressions.
Assisted-by: GitHub Copilot
Signed-off-by: sriramshastry <sriramshastry at gmail.com>
---
.../src/mathvec/exhaustive/CMakeLists.txt | 14 +++++
.../src/mathvec/exhaustive/checker_test.cpp | 61 +++++++++++++++++++
.../src/mathvec/exhaustive/exhaustive_test.h | 24 ++++++--
3 files changed, 93 insertions(+), 6 deletions(-)
create mode 100644 libc/test/src/mathvec/exhaustive/checker_test.cpp
diff --git a/libc/test/src/mathvec/exhaustive/CMakeLists.txt b/libc/test/src/mathvec/exhaustive/CMakeLists.txt
index 414ed34703dacd..8e547db8589687 100644
--- a/libc/test/src/mathvec/exhaustive/CMakeLists.txt
+++ b/libc/test/src/mathvec/exhaustive/CMakeLists.txt
@@ -9,6 +9,20 @@ add_header_library(
libc.src.__support.CPP.limits
)
+add_fp_unittest(
+ checker_test
+ SUITE
+ libc-mathvec-tests
+ SRCS
+ checker_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.CPP.simd
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
acosf_test
SUITE
diff --git a/libc/test/src/mathvec/exhaustive/checker_test.cpp b/libc/test/src/mathvec/exhaustive/checker_test.cpp
new file mode 100644
index 00000000000000..7c10f01dc25f1d
--- /dev/null
+++ b/libc/test/src/mathvec/exhaustive/checker_test.cpp
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains unit tests for the exhaustive mathvec lane checker.
+///
+//===----------------------------------------------------------------------===//
+
+#include "exhaustive_test.h"
+#include "test/UnitTest/Test.h"
+
+namespace {
+
+using Vector = LIBC_NAMESPACE::cpp::simd<float>;
+constexpr size_t LANES =
+ LIBC_NAMESPACE::cpp::internal::native_vector_size<float>;
+float identity(float x) { return x; }
+LIBC_VECTOR_PCS Vector vector_identity(Vector x) { return x; }
+using ExactChecker = UnaryOpChecker<float, float, identity, vector_identity>;
+using TolerantChecker =
+ UnaryOpChecker<float, float, identity, vector_identity, 1>;
+using LlvmLibcMathvecCheckerTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+} // namespace
+
+TEST_F(LlvmLibcMathvecCheckerTest, MatchingLanes) {
+ EXPECT_EQ(ExactChecker::first_mismatching_lane(1.0f, Vector(1.0f)), LANES);
+ EXPECT_EQ(ExactChecker::first_mismatching_lane(aNaN, Vector(aNaN)), LANES);
+}
+
+TEST_F(LlvmLibcMathvecCheckerTest, EveryLane) {
+ for (size_t lane = 0; lane < LANES; ++lane) {
+ Vector actual(1.0f);
+ actual[lane] = 2.0f;
+ EXPECT_EQ(ExactChecker::first_mismatching_lane(1.0f, actual), lane);
+ }
+}
+
+TEST_F(LlvmLibcMathvecCheckerTest, TolerantEveryLane) {
+ Vector actual(FPBits(0x3f800001U).get_val());
+ EXPECT_EQ(TolerantChecker::first_mismatching_lane(1.0f, actual), LANES);
+ for (size_t lane = 0; lane < LANES; ++lane) {
+ actual[lane] = FPBits(0x3f800002U).get_val();
+ EXPECT_EQ(TolerantChecker::first_mismatching_lane(1.0f, actual), lane);
+ actual[lane] = FPBits(0x3f800001U).get_val();
+ }
+}
+
+TEST_F(LlvmLibcMathvecCheckerTest, SignedZero) {
+ Vector actual(0.0f);
+ for (size_t lane = 0; lane < LANES; ++lane) {
+ actual[lane] = -0.0f;
+ EXPECT_EQ(ExactChecker::first_mismatching_lane(0.0f, actual), lane);
+ actual[lane] = 0.0f;
+ }
+}
diff --git a/libc/test/src/mathvec/exhaustive/exhaustive_test.h b/libc/test/src/mathvec/exhaustive/exhaustive_test.h
index db6b683b890116..e0aebe94e655b8 100644
--- a/libc/test/src/mathvec/exhaustive/exhaustive_test.h
+++ b/libc/test/src/mathvec/exhaustive/exhaustive_test.h
@@ -51,6 +51,21 @@ struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<FloatType>;
using StorageType = typename FPBits::StorageType;
+ static size_t
+ first_mismatching_lane(OutType expected,
+ LIBC_NAMESPACE::cpp::simd<OutType> actual) {
+ constexpr size_t LANES =
+ LIBC_NAMESPACE::cpp::internal::native_vector_size<OutType>;
+ for (size_t lane = 0; lane < LANES; ++lane) {
+ bool correct = TOL == 0 ? TEST_FP_EQ(expected, actual[lane])
+ : LIBC_NAMESPACE::testing::within_ulp_tolerance(
+ expected, actual[lane], TOL);
+ if (!correct)
+ return lane;
+ }
+ return LANES;
+ }
+
// Check the inclusive range [start, stop], returning the number of failures.
uint64_t check(StorageType start, StorageType stop,
LIBC_NAMESPACE::fputil::testing::RoundingMode rounding) {
@@ -66,13 +81,10 @@ struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
LIBC_NAMESPACE::cpp::simd<FloatType> vec_x(x);
LIBC_NAMESPACE::cpp::simd<OutType> vec_result = VectorFunc(vec_x);
- OutType vec_res = vec_result[0];
OutType scalar_result = ScalarFunc(x);
- bool correct = TOL == 0 ? TEST_FP_EQ(scalar_result, vec_res)
- : LIBC_NAMESPACE::testing::within_ulp_tolerance(
- scalar_result, vec_res, TOL);
-
- if (!correct) {
+ size_t lane = first_mismatching_lane(scalar_result, vec_result);
+ if (lane < LIBC_NAMESPACE::cpp::internal::native_vector_size<OutType>) {
+ OutType vec_res = vec_result[lane];
if constexpr (TOL == 0)
EXPECT_FP_EQ(scalar_result, vec_res);
else
More information about the libc-commits
mailing list