[libc-commits] [libc] [libc][mathvec] Vectorise logf (PR #231190)
via libc-commits
libc-commits at lists.llvm.org
Wed Oct 21 07:00:11 PDT 2026
================
@@ -7,30 +7,118 @@
//===----------------------------------------------------------------------===//
///
/// \file
-/// This file contains the implemenation for single-precision SIMD log.
+/// This file contains the implementation for single-precision SIMD log.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_MATHVEC_LOGF_H
#define LLVM_LIBC_SRC___SUPPORT_MATHVEC_LOGF_H
+#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/simd.h"
-#define LIBC_MATH_HAS_NO_ERRNO
-#define LIBC_MATH_HAS_NO_EXCEPT
-#define LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
-#include "src/__support/math/logf.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/macros/properties/cpu_features.h"
+#include "src/__support/math/common_constants.h"
+#include "src/__support/mathvec/common_constants.h"
namespace LIBC_NAMESPACE_DECL {
namespace mathvec {
template <size_t N>
-LIBC_INLINE cpp::simd<float, N> logf(cpp::simd<float, N> x) {
- return cpp::map(x, [](float a) { return math::logf(a); });
+LIBC_INLINE cpp::simd<float, N>
+inline_logf(cpp::simd<uint32_t, N> ux, cpp::simd<int32_t, N> exponent_bias) {
+ using namespace common_constants_internal;
+
+ // Extract the 7 leading bits of the mantissa
+ cpp::simd<uint32_t, N> index = (ux >> 16) & 0x7fU;
+
+ // Compute unbiased exponent
+ cpp::simd<int32_t, N> m = cpp::simd_cast<int32_t>(ux >> 23);
+ m += exponent_bias;
+
+ // Sets the exponent such that 1 <= u < 2
+ cpp::simd<float, N> u =
+ cpp::bit_cast<cpp::simd<float, N>>((ux & 0x007f'ffffU) | 0x3f80'0000U);
+
+ cpp::simd<double, N> log_r =
+ cpp::gather<cpp::simd<double, N>>(true, index, LOG_TABLE);
+
+#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+ cpp::simd<float, N> r = cpp::gather<cpp::simd<float, N>>(true, index, R);
+ cpp::simd<double, N> v = cpp::simd_cast<double>(
+ cpp::multiply_add(u, r, cpp::simd<float, N>(-1.0f)));
+#else
+ cpp::simd<double, N> r = cpp::gather<cpp::simd<double, N>>(true, index, RD);
+ cpp::simd<double, N> v = cpp::simd_cast<double>(u) * r - 1.0;
----------------
DylanFleming-arm wrote:
It's possible, but I don't think we need to worry about it here, the no-float-fma path still correctly rounds if you have FMAs, so if a target does have FP64 FMAs it'll still be correct.
https://github.com/llvm/llvm-project/pull/231190
More information about the libc-commits
mailing list