[libc-commits] [libc] [llvm] [libc][math] Refactor log10f16 to Header Only. (PR #176523)

via libc-commits libc-commits at lists.llvm.org
Fri Jan 16 18:12:49 PST 2026


https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/176523

>From bf93ee74d43c0aa6b1dd8d90952e05a24b13e0da Mon Sep 17 00:00:00 2001
From: anonmiraj <nabilmalek48 at gmail.com>
Date: Sat, 17 Jan 2026 03:09:03 +0200
Subject: [PATCH] [libc][math] Refactor log10f16 to Header Only.

---
 libc/shared/math.h                            |   1 +
 libc/shared/math/log10f16.h                   |  28 +++
 libc/src/__support/math/CMakeLists.txt        |  18 ++
 libc/src/__support/math/log10f16.h            | 182 ++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt          |  13 +-
 libc/src/math/generic/log10f16.cpp            | 157 +--------------
 libc/test/shared/CMakeLists.txt               |   1 +
 libc/test/shared/shared_math_test.cpp         |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel     |  18 +-
 9 files changed, 252 insertions(+), 167 deletions(-)
 create mode 100644 libc/shared/math/log10f16.h
 create mode 100644 libc/src/__support/math/log10f16.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 017c94f8ad54a..0cf0380c7049b 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -71,6 +71,7 @@
 #include "math/ldexpf16.h"
 #include "math/llogbf.h"
 #include "math/log.h"
+#include "math/log10f16.h"
 #include "math/logbf.h"
 #include "math/logbf128.h"
 #include "math/logbf16.h"
diff --git a/libc/shared/math/log10f16.h b/libc/shared/math/log10f16.h
new file mode 100644
index 0000000000000..883191c1385e2
--- /dev/null
+++ b/libc/shared/math/log10f16.h
@@ -0,0 +1,28 @@
+//===-- Shared log10f16 function --------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_LOG10F16_H
+#define LLVM_LIBC_SHARED_MATH_LOG10F16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "shared/libc_common.h"
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/log10f16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::log10f16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_LOG10F16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index cb03b18678145..14917b6542495 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1103,6 +1103,24 @@ add_header_library(
     libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  log10f16
+  HDRS
+    log10f16.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.FPUtil.polyeval
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.cpu_features
+    libc.src.__support.math.expxf16_utils
+)
+
 add_header_library(
   logbf128
   HDRS
diff --git a/libc/src/__support/math/log10f16.h b/libc/src/__support/math/log10f16.h
new file mode 100644
index 0000000000000..fc9505e413c39
--- /dev/null
+++ b/libc/src/__support/math/log10f16.h
@@ -0,0 +1,182 @@
+//===-- Implementation header for log10f16 ----------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/cpu_features.h"
+#include "src/__support/math/expxf16_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+static constexpr size_t N_LOG10F16_EXCEPTS = 11;
+#else
+static constexpr size_t N_LOG10F16_EXCEPTS = 17;
+#endif
+
+static constexpr fputil::ExceptValues<float16, N_LOG10F16_EXCEPTS>
+    LOG10F16_EXCEPTS = {{
+        // (input, RZ output, RU offset, RD offset, RN offset)
+        // x = 0x1.e3cp-3, log10f16(x) = -0x1.40cp-1 (RZ)
+        {0x338fU, 0xb903U, 0U, 1U, 0U},
+        // x = 0x1.fep-3, log10f16(x) = -0x1.35p-1 (RZ)
+        {0x33f8U, 0xb8d4U, 0U, 1U, 1U},
+#ifndef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+        // x = 0x1.394p-1, log10f16(x) = -0x1.b4cp-3 (RZ)
+        {0x38e5U, 0xb2d3U, 0U, 1U, 1U},
+#endif
+        // x = 0x1.ea8p-1, log10f16(x) = -0x1.31p-6 (RZ)
+        {0x3baaU, 0xa4c4U, 0U, 1U, 1U},
+        // x = 0x1.ebp-1, log10f16(x) = -0x1.29cp-6 (RZ)
+        {0x3bacU, 0xa4a7U, 0U, 1U, 1U},
+        // x = 0x1.f3p-1, log10f16(x) = -0x1.6dcp-7 (RZ)
+        {0x3bccU, 0xa1b7U, 0U, 1U, 1U},
+// x = 0x1.f38p-1, log10f16(x) = -0x1.5f8p-7 (RZ)
+#ifndef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+        {0x3bceU, 0xa17eU, 0U, 1U, 1U},
+        // x = 0x1.fd8p-1, log10f16(x) = -0x1.168p-9 (RZ)
+        {0x3bf6U, 0x985aU, 0U, 1U, 1U},
+        // x = 0x1.ff8p-1, log10f16(x) = -0x1.bccp-12 (RZ)
+        {0x3bfeU, 0x8ef3U, 0U, 1U, 1U},
+        // x = 0x1.374p+0, log10f16(x) = 0x1.5b8p-4 (RZ)
+        {0x3cddU, 0x2d6eU, 1U, 0U, 1U},
+        // x = 0x1.3ecp+1, log10f16(x) = 0x1.958p-2 (RZ)
+        {0x40fbU, 0x3656U, 1U, 0U, 1U},
+#endif
+        // x = 0x1.4p+3, log10f16(x) = 0x1p+0 (RZ)
+        {0x4900U, 0x3c00U, 0U, 0U, 0U},
+        // x = 0x1.9p+6, log10f16(x) = 0x1p+1 (RZ)
+        {0x5640U, 0x4000U, 0U, 0U, 0U},
+        // x = 0x1.f84p+6, log10f16(x) = 0x1.0ccp+1 (RZ)
+        {0x57e1U, 0x4033U, 1U, 0U, 0U},
+        // x = 0x1.f4p+9, log10f16(x) = 0x1.8p+1 (RZ)
+        {0x63d0U, 0x4200U, 0U, 0U, 0U},
+        // x = 0x1.388p+13, log10f16(x) = 0x1p+2 (RZ)
+        {0x70e2U, 0x4400U, 0U, 0U, 0U},
+        // x = 0x1.674p+13, log10f16(x) = 0x1.03cp+2 (RZ)
+        {0x719dU, 0x440fU, 1U, 0U, 0U},
+    }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+LIBC_INLINE static constexpr float16 log10f16(float16 x) {
+  using namespace math::expxf16_internal;
+  using FPBits = fputil::FPBits<float16>;
+  FPBits x_bits(x);
+
+  uint16_t x_u = x_bits.uintval();
+
+  // If x <= 0, or x is 1, or x is +inf, or x is NaN.
+  if (LIBC_UNLIKELY(x_u == 0U || x_u == 0x3c00U || x_u >= 0x7c00U)) {
+    // log10(NaN) = NaN
+    if (x_bits.is_nan()) {
+      if (x_bits.is_signaling_nan()) {
+        fputil::raise_except_if_required(FE_INVALID);
+        return FPBits::quiet_nan().get_val();
+      }
+
+      return x;
+    }
+
+    // log10(+/-0) = −inf
+    if ((x_u & 0x7fffU) == 0U) {
+      fputil::raise_except_if_required(FE_DIVBYZERO);
+      return FPBits::inf(Sign::NEG).get_val();
+    }
+
+    if (x_u == 0x3c00U)
+      return FPBits::zero().get_val();
+
+    // When x < 0.
+    if (x_u > 0x8000U) {
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
+    }
+
+    // log10(+inf) = +inf
+    return FPBits::inf().get_val();
+  }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  if (auto r = LOG10F16_EXCEPTS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
+    return r.value();
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  // To compute log10(x), we perform the following range reduction:
+  //   x = 2^m * 1.mant,
+  //   log10(x) = m * log10(2) + log10(1.mant).
+  // To compute log10(1.mant), let f be the highest 6 bits including the hidden
+  // bit, and d be the difference (1.mant - f), i.e., the remaining 5 bits of
+  // the mantissa, then:
+  //   log10(1.mant) = log10(f) + log10(1.mant / f)
+  //                 = log10(f) + log10(1 + d/f)
+  // since d/f is sufficiently small.
+  // We store log10(f) and 1/f in the lookup tables LOG10F_F and ONE_OVER_F_F
+  // respectively.
+
+  int m = -FPBits::EXP_BIAS;
+
+  // When x is subnormal, normalize it.
+  if ((x_u & FPBits::EXP_MASK) == 0U) {
+    // Can't pass an integer to fputil::cast directly.
+    constexpr float NORMALIZE_EXP = 1U << FPBits::FRACTION_LEN;
+    x_bits = FPBits(x_bits.get_val() * fputil::cast<float16>(NORMALIZE_EXP));
+    x_u = x_bits.uintval();
+    m -= FPBits::FRACTION_LEN;
+  }
+
+  uint16_t mant = x_bits.get_mantissa();
+  // Leading 10 - 5 = 5 bits of the mantissa.
+  int f = mant >> 5;
+  // Unbiased exponent.
+  m += x_u >> FPBits::FRACTION_LEN;
+
+  // Set bits to 1.mant instead of 2^m * 1.mant.
+  x_bits.set_biased_exponent(FPBits::EXP_BIAS);
+  float mant_f = x_bits.get_val();
+  // v = 1.mant * 1/f - 1 = d/f
+  float v = fputil::multiply_add(mant_f, ONE_OVER_F_F[f], -1.0f);
+
+  // Degree-3 minimax polynomial generated by Sollya with the following
+  // commands:
+  //   > display = hexadecimal;
+  //   > P = fpminimax(log10(1 + x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
+  //   > x * P;
+  float log10p1_d_over_f =
+      v * fputil::polyeval(v, 0x1.bcb7bp-2f, -0x1.bce168p-3f, 0x1.28acb8p-3f);
+  // log10(1.mant) = log10(f) + log10(1 + d/f)
+  float log10_1_mant = LOG10F_F[f] + log10p1_d_over_f;
+  return fputil::cast<float16>(
+      fputil::multiply_add(static_cast<float>(m), LOG10F_2, log10_1_mant));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index e4ad6fcafeaf0..c5f0ad73640a9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1993,17 +1993,8 @@ add_entrypoint_object(
   HDRS
     ../log10f16.h
   DEPENDS
-    libc.hdr.errno_macros
-    libc.hdr.fenv_macros
-    libc.src.__support.FPUtil.cast
-    libc.src.__support.FPUtil.except_value_utils
-    libc.src.__support.FPUtil.fenv_impl
-    libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.multiply_add
-    libc.src.__support.FPUtil.polyeval
-    libc.src.__support.macros.optimization
-    libc.src.__support.macros.properties.cpu_features
-    libc.src.__support.math.expxf16_utils
+    libc.src.__support.math.log10f16
+    libc.src.errno.errno
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/log10f16.cpp b/libc/src/math/generic/log10f16.cpp
index 4bb684a2206cc..57f8e57e31b27 100644
--- a/libc/src/math/generic/log10f16.cpp
+++ b/libc/src/math/generic/log10f16.cpp
@@ -7,163 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/log10f16.h"
-#include "hdr/errno_macros.h"
-#include "hdr/fenv_macros.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.h"
-#include "src/__support/FPUtil/cast.h"
-#include "src/__support/FPUtil/except_value_utils.h"
-#include "src/__support/FPUtil/multiply_add.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h"
-#include "src/__support/macros/properties/cpu_features.h"
-#include "src/__support/math/expxf16_utils.h"
+#include "src/__support/math/log10f16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-static constexpr size_t N_LOG10F16_EXCEPTS = 11;
-#else
-static constexpr size_t N_LOG10F16_EXCEPTS = 17;
-#endif
-
-static constexpr fputil::ExceptValues<float16, N_LOG10F16_EXCEPTS>
-    LOG10F16_EXCEPTS = {{
-        // (input, RZ output, RU offset, RD offset, RN offset)
-        // x = 0x1.e3cp-3, log10f16(x) = -0x1.40cp-1 (RZ)
-        {0x338fU, 0xb903U, 0U, 1U, 0U},
-        // x = 0x1.fep-3, log10f16(x) = -0x1.35p-1 (RZ)
-        {0x33f8U, 0xb8d4U, 0U, 1U, 1U},
-#ifndef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-        // x = 0x1.394p-1, log10f16(x) = -0x1.b4cp-3 (RZ)
-        {0x38e5U, 0xb2d3U, 0U, 1U, 1U},
-#endif
-        // x = 0x1.ea8p-1, log10f16(x) = -0x1.31p-6 (RZ)
-        {0x3baaU, 0xa4c4U, 0U, 1U, 1U},
-        // x = 0x1.ebp-1, log10f16(x) = -0x1.29cp-6 (RZ)
-        {0x3bacU, 0xa4a7U, 0U, 1U, 1U},
-        // x = 0x1.f3p-1, log10f16(x) = -0x1.6dcp-7 (RZ)
-        {0x3bccU, 0xa1b7U, 0U, 1U, 1U},
-// x = 0x1.f38p-1, log10f16(x) = -0x1.5f8p-7 (RZ)
-#ifndef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-        {0x3bceU, 0xa17eU, 0U, 1U, 1U},
-        // x = 0x1.fd8p-1, log10f16(x) = -0x1.168p-9 (RZ)
-        {0x3bf6U, 0x985aU, 0U, 1U, 1U},
-        // x = 0x1.ff8p-1, log10f16(x) = -0x1.bccp-12 (RZ)
-        {0x3bfeU, 0x8ef3U, 0U, 1U, 1U},
-        // x = 0x1.374p+0, log10f16(x) = 0x1.5b8p-4 (RZ)
-        {0x3cddU, 0x2d6eU, 1U, 0U, 1U},
-        // x = 0x1.3ecp+1, log10f16(x) = 0x1.958p-2 (RZ)
-        {0x40fbU, 0x3656U, 1U, 0U, 1U},
-#endif
-        // x = 0x1.4p+3, log10f16(x) = 0x1p+0 (RZ)
-        {0x4900U, 0x3c00U, 0U, 0U, 0U},
-        // x = 0x1.9p+6, log10f16(x) = 0x1p+1 (RZ)
-        {0x5640U, 0x4000U, 0U, 0U, 0U},
-        // x = 0x1.f84p+6, log10f16(x) = 0x1.0ccp+1 (RZ)
-        {0x57e1U, 0x4033U, 1U, 0U, 0U},
-        // x = 0x1.f4p+9, log10f16(x) = 0x1.8p+1 (RZ)
-        {0x63d0U, 0x4200U, 0U, 0U, 0U},
-        // x = 0x1.388p+13, log10f16(x) = 0x1p+2 (RZ)
-        {0x70e2U, 0x4400U, 0U, 0U, 0U},
-        // x = 0x1.674p+13, log10f16(x) = 0x1.03cp+2 (RZ)
-        {0x719dU, 0x440fU, 1U, 0U, 0U},
-    }};
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-LLVM_LIBC_FUNCTION(float16, log10f16, (float16 x)) {
-  using namespace math::expxf16_internal;
-  using FPBits = fputil::FPBits<float16>;
-  FPBits x_bits(x);
-
-  uint16_t x_u = x_bits.uintval();
-
-  // If x <= 0, or x is 1, or x is +inf, or x is NaN.
-  if (LIBC_UNLIKELY(x_u == 0U || x_u == 0x3c00U || x_u >= 0x7c00U)) {
-    // log10(NaN) = NaN
-    if (x_bits.is_nan()) {
-      if (x_bits.is_signaling_nan()) {
-        fputil::raise_except_if_required(FE_INVALID);
-        return FPBits::quiet_nan().get_val();
-      }
-
-      return x;
-    }
-
-    // log10(+/-0) = −inf
-    if ((x_u & 0x7fffU) == 0U) {
-      fputil::raise_except_if_required(FE_DIVBYZERO);
-      return FPBits::inf(Sign::NEG).get_val();
-    }
-
-    if (x_u == 0x3c00U)
-      return FPBits::zero().get_val();
-
-    // When x < 0.
-    if (x_u > 0x8000U) {
-      fputil::set_errno_if_required(EDOM);
-      fputil::raise_except_if_required(FE_INVALID);
-      return FPBits::quiet_nan().get_val();
-    }
-
-    // log10(+inf) = +inf
-    return FPBits::inf().get_val();
-  }
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  if (auto r = LOG10F16_EXCEPTS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
-    return r.value();
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-  // To compute log10(x), we perform the following range reduction:
-  //   x = 2^m * 1.mant,
-  //   log10(x) = m * log10(2) + log10(1.mant).
-  // To compute log10(1.mant), let f be the highest 6 bits including the hidden
-  // bit, and d be the difference (1.mant - f), i.e., the remaining 5 bits of
-  // the mantissa, then:
-  //   log10(1.mant) = log10(f) + log10(1.mant / f)
-  //                 = log10(f) + log10(1 + d/f)
-  // since d/f is sufficiently small.
-  // We store log10(f) and 1/f in the lookup tables LOG10F_F and ONE_OVER_F_F
-  // respectively.
-
-  int m = -FPBits::EXP_BIAS;
-
-  // When x is subnormal, normalize it.
-  if ((x_u & FPBits::EXP_MASK) == 0U) {
-    // Can't pass an integer to fputil::cast directly.
-    constexpr float NORMALIZE_EXP = 1U << FPBits::FRACTION_LEN;
-    x_bits = FPBits(x_bits.get_val() * fputil::cast<float16>(NORMALIZE_EXP));
-    x_u = x_bits.uintval();
-    m -= FPBits::FRACTION_LEN;
-  }
-
-  uint16_t mant = x_bits.get_mantissa();
-  // Leading 10 - 5 = 5 bits of the mantissa.
-  int f = mant >> 5;
-  // Unbiased exponent.
-  m += x_u >> FPBits::FRACTION_LEN;
-
-  // Set bits to 1.mant instead of 2^m * 1.mant.
-  x_bits.set_biased_exponent(FPBits::EXP_BIAS);
-  float mant_f = x_bits.get_val();
-  // v = 1.mant * 1/f - 1 = d/f
-  float v = fputil::multiply_add(mant_f, ONE_OVER_F_F[f], -1.0f);
-
-  // Degree-3 minimax polynomial generated by Sollya with the following
-  // commands:
-  //   > display = hexadecimal;
-  //   > P = fpminimax(log10(1 + x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
-  //   > x * P;
-  float log10p1_d_over_f =
-      v * fputil::polyeval(v, 0x1.bcb7bp-2f, -0x1.bce168p-3f, 0x1.28acb8p-3f);
-  // log10(1.mant) = log10(f) + log10(1 + d/f)
-  float log10_1_mant = LOG10F_F[f] + log10p1_d_over_f;
-  return fputil::cast<float16>(
-      fputil::multiply_add(static_cast<float>(m), LOG10F_2, log10_1_mant));
-}
+LLVM_LIBC_FUNCTION(float16, log10f16, (float16 x)) { return math::log10f16(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 61625c0bc0444..0ac62775a8cdf 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -63,6 +63,7 @@ add_fp_unittest(
     libc.src.__support.math.ilogbf16
     libc.src.__support.math.ilogbl
     libc.src.__support.math.log
+    libc.src.__support.math.log10f16
     libc.src.__support.math.logbf
     libc.src.__support.math.logbf128
     libc.src.__support.math.logbf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 49047631fb227..4134eb77b5337 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -42,6 +42,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_EQ(exponent, 5);
 
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbf16(1.0f16));
+  EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::log10f16(10.0f16));
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::logbf16(1.0f16));
 
   EXPECT_FP_EQ(0x1.921fb6p+0f16, LIBC_NAMESPACE::shared::acosf16(0.0f16));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 3d9491e8baa0c..34c9265529e78 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2932,6 +2932,21 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_log10f16",
+    hdrs = ["src/__support/math/log10f16.h"],
+    deps = [
+        ":__support_fputil_cast",
+        ":__support_fputil_except_value_utils",
+        ":__support_fputil_fenv_impl",
+        ":__support_fputil_fp_bits",
+        ":__support_fputil_multiply_add",
+        ":__support_fputil_polyeval",
+        ":__support_macros_optimization",
+        ":__support_math_expxf16_utils",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_logbf",
     hdrs = ["src/__support/math/logbf.h"],
@@ -4548,7 +4563,8 @@ libc_math_function(
 libc_math_function(
     name = "log10f16",
     additional_deps = [
-        ":__support_math_expxf16_utils",
+        ":__support_math_log10f16",
+        ":errno",
     ],
 )
 



More information about the libc-commits mailing list