[libc-commits] [libc] [libc][mathvec] Initial commit for LIBC vector math component (PR #173058)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Fri Jan 9 13:48:34 PST 2026
================
@@ -0,0 +1,133 @@
+//===-- Unittests for expf ------------------------------------------------===//
+//
+// 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 "hdr/math_macros.h"
+#include "src/__support/CPP/simd.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/math/expf.h"
+#include "src/mathvec/expf.h"
+#include "test/UnitTest/SIMDMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/stdint_proxy.h"
+
+using LlvmLibcVecExpfTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+// Wrappers
+
+// In order to test vector we can either duplicate a scalar input
+// or do something more elaborate. In any case that requires a wrapper
+// since the function call is written in this file.
+
+// Run reference on a vector with lanes duplicated from a scalar input.
+
+// with control lane
+static LIBC_NAMESPACE::cpp::simd<float> wrap_ref_vexpf(float x, float control) {
+ LIBC_NAMESPACE::cpp::simd<float> v(x);
+ v[0] = control;
+ constexpr size_t N = LIBC_NAMESPACE::cpp::internal::native_vector_size<float>;
+ for (size_t i = 0; i < N; i++) {
+ v[i] = LIBC_NAMESPACE::expf(v[i]);
+ }
+ return v;
+}
+
+// without control lane
+static LIBC_NAMESPACE::cpp::simd<float> wrap_ref_vexpf(float x) {
+ return wrap_ref_vexpf(x, x);
+}
+
+// Run implementation on a vector with lanes duplicated from a scalar input.
+
+// with control lane
+static LIBC_NAMESPACE::cpp::simd<float> wrap_vexpf(float x, float control) {
+ LIBC_NAMESPACE::cpp::simd<float> v(x);
+ v[0] = control;
+ return LIBC_NAMESPACE::expf(v);
+}
+
+// without control lane
+static LIBC_NAMESPACE::cpp::simd<float> wrap_vexpf(float x) {
+ return wrap_vexpf(x, x);
+}
+
+TEST_F(LlvmLibcVecExpfTest, SpecialNumbers) {
+ EXPECT_SIMD_EQ(LIBC_NAMESPACE::cpp::splat(aNaN), wrap_vexpf(aNaN));
+
+ EXPECT_SIMD_EQ(LIBC_NAMESPACE::cpp::splat(inf), wrap_vexpf(inf));
+
+ EXPECT_SIMD_EQ(LIBC_NAMESPACE::cpp::splat(0.0f), wrap_vexpf(neg_inf));
+
+ EXPECT_SIMD_EQ(LIBC_NAMESPACE::cpp::splat(1.0f), wrap_vexpf(0.0f));
+
+ EXPECT_SIMD_EQ(LIBC_NAMESPACE::cpp::splat(1.0f), wrap_vexpf(-0.0f));
+}
+
+TEST_F(LlvmLibcVecExpfTest, Overflow) {
+ // Fails if tested with exceptions
+ EXPECT_SIMD_EQ(LIBC_NAMESPACE::cpp::splat(inf),
+ wrap_vexpf(FPBits(0x7f7fffffU).get_val()));
----------------
michaelrj-google wrote:
these float constants should probably be written as hex floats
https://github.com/llvm/llvm-project/pull/173058
More information about the libc-commits
mailing list