[libc-commits] [libc] [llvm] [libc][math] Optimize exp10 to share evaluations with exp and exp2. (PR #236973)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 29 14:48:11 PDT 2026


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/236973

- Refactor double precision exp10 into exp10_double_eval.h and share evaluations with exp and exp2.
- Optimize range reduction using fp-bitwise operations.

Assisted by: Gemini for analysis and refactoring

>From 1ed98dc075d1b6dbc6b5f9a85979ef7247dd377e Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Thu, 29 Oct 2026 21:42:28 +0000
Subject: [PATCH] [libc][math] Optimize exp10 to share evaluations with exp and
 exp2.

- Refactor double precision exp10 into exp10_double_eval.h and share evaluations with exp and exp2.
- Optimize range reduction using fp-bitwise operations.

Assisted by: Gemini for analysis and refactoring
---
 libc/src/__support/math/CMakeLists.txt        |  31 +-
 libc/src/__support/math/exp10.h               | 512 +-----------------
 libc/src/__support/math/exp10_double_eval.h   | 233 ++++++++
 libc/src/__support/math/exp2_accurate_128.h   |  19 +
 libc/test/src/math/CMakeLists.txt             |   3 +
 libc/test/src/math/exp10_test.cpp             | 296 ++++++----
 libc/test/src/math/smoke/CMakeLists.txt       |   3 +
 libc/test/src/math/smoke/exp10_test.cpp       | 126 +++--
 .../llvm-project-overlay/libc/BUILD.bazel     |  28 +-
 .../libc/test/src/math/BUILD.bazel            |   8 +-
 .../libc/test/src/math/smoke/BUILD.bazel      |   8 +-
 11 files changed, 582 insertions(+), 685 deletions(-)
 create mode 100644 libc/src/__support/math/exp10_double_eval.h

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0458f480ab1c0d..2fa418e53009a3 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4546,23 +4546,32 @@ add_header_library(
 )
 
 add_header_library(
-  exp10
+  exp10_double_eval
   HDRS
-    exp10.h
+    exp10_double_eval.h
   DEPENDS
-    .exp_constants
+    .exp_double_utils
     .exp_utils
     libc.src.__support.CPP.bit
-    libc.src.__support.CPP.optional
-    libc.src.__support.FPUtil.dyadic_float
-    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.double_double
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.fp_bitwise
     libc.src.__support.FPUtil.multiply_add
-    libc.src.__support.FPUtil.nearest_integer
-    libc.src.__support.FPUtil.polyeval
-    libc.src.__support.FPUtil.rounding_mode
-    libc.src.__support.FPUtil.triple_double
-    libc.src.__support.integer_literals
+    libc.src.__support.common
+    libc.src.__support.macros.attributes
+    libc.src.__support.macros.config
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.cpu_features
+)
+
+add_header_library(
+  exp10
+  HDRS
+    exp10.h
+  DEPENDS
+    .exp10_double_eval
+    libc.src.__support.common
+    libc.src.__support.macros.config
     libc.src.__support.macros.optimization
 )
 
diff --git a/libc/src/__support/math/exp10.h b/libc/src/__support/math/exp10.h
index 010348748001ca..7c7190e11ca562 100644
--- a/libc/src/__support/math/exp10.h
+++ b/libc/src/__support/math/exp10.h
@@ -1,520 +1,34 @@
-//===-- Implementation header for exp10 ------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for exp10.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP10_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_EXP10_H
 
-#include "exp_constants.h" // Lookup tables EXP2_MID1 and EXP_M2.
-#include "exp_utils.h"     // ziv_test_denorm.
-#include "src/__support/CPP/bit.h"
-#include "src/__support/CPP/optional.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.h"
-#include "src/__support/FPUtil/double_double.h"
-#include "src/__support/FPUtil/dyadic_float.h"
-#include "src/__support/FPUtil/multiply_add.h"
-#include "src/__support/FPUtil/nearest_integer.h"
-#include "src/__support/FPUtil/rounding_mode.h"
-#include "src/__support/FPUtil/triple_double.h"
 #include "src/__support/common.h"
-#include "src/__support/integer_literals.h"
 #include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-
-namespace LIBC_NAMESPACE_DECL {
-
-using fputil::DoubleDouble;
-using fputil::TripleDouble;
-using DFloat128 = typename fputil::DyadicFloat<128>;
-
-using LIBC_NAMESPACE::operator""_u128;
-
-// log2(10)
-LIBC_INLINE_VAR constexpr double LOG2_10 = 0x1.a934f0979a371p+1;
-
-// -2^-12 * log10(2)
-// > a = -2^-12 * log10(2);
-// > b = round(a, 32, RN);
-// > c = round(a - b, 32, RN);
-// > d = round(a - b - c, D, RN);
-// Errors < 1.5 * 2^-144
-LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_M12_HI = -0x1.3441350ap-14;
-LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_M12_MID = 0x1.0c0219dc1da99p-51;
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_M12_MID_32 = 0x1.0c0219dcp-51;
-LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_M12_LO = 0x1.da994fd20dba2p-87;
-#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-// Error bounds:
-// Errors when using double precision.
-LIBC_INLINE_VAR constexpr double EXP10_ERR_D = 0x1.8p-63;
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-// Errors when using double-double precision.
-LIBC_INLINE_VAR constexpr double EXP10_ERR_DD = 0x1.8p-99;
-#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-// Polynomial approximations with double precision.  Generated by Sollya with:
-// > P = fpminimax((10^x - 1)/x, 3, [|D...|], [-2^-14, 2^-14]);
-// > P;
-// Error bounds:
-//   | output - (10^dx - 1) / dx | < 2^-52.
-LIBC_INLINE double exp10_poly_approx_d(double dx) {
-  // dx^2
-  double dx2 = dx * dx;
-  double c0 =
-      fputil::multiply_add(dx, 0x1.53524c73cea6ap+1, 0x1.26bb1bbb55516p+1);
-  double c1 =
-      fputil::multiply_add(dx, 0x1.2bd75cc6afc65p+0, 0x1.0470587aa264cp+1);
-  double p = fputil::multiply_add(dx2, c1, c0);
-  return p;
-}
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-// Polynomial approximation with double-double precision.  Generated by Solya
-// with:
-// > P = fpminimax((10^x - 1)/x, 5, [|DD...|], [-2^-14, 2^-14]);
-// Error bounds:
-//   | output - 10^(dx) | < 2^-101
-LIBC_INLINE DoubleDouble exp10_poly_approx_dd(const DoubleDouble &dx) {
-  // Taylor polynomial.
-  constexpr DoubleDouble COEFFS[] = {
-      {0, 0x1p0},
-      {-0x1.f48ad494e927bp-53, 0x1.26bb1bbb55516p1},
-      {-0x1.e2bfab3191cd2p-53, 0x1.53524c73cea69p1},
-      {0x1.80fb65ec3b503p-53, 0x1.0470591de2ca4p1},
-      {0x1.338fc05e21e55p-54, 0x1.2bd7609fd98c4p0},
-      {0x1.d4ea116818fbp-56, 0x1.1429ffd519865p-1},
-      {-0x1.872a8ff352077p-57, 0x1.a7ed70847c8b3p-3},
-
-  };
-
-  DoubleDouble p = fputil::polyeval(dx, COEFFS[0], COEFFS[1], COEFFS[2],
-                                    COEFFS[3], COEFFS[4], COEFFS[5], COEFFS[6]);
-  return p;
-}
-
-// Polynomial approximation with 128-bit precision:
-// Return exp(dx) ~ 1 + a0 * dx + a1 * dx^2 + ... + a6 * dx^7
-// For |dx| < 2^-14:
-//   | output - 10^dx | < 1.5 * 2^-124.
-LIBC_INLINE DFloat128 exp10_poly_approx_f128(const DFloat128 &dx) {
-  constexpr DFloat128 COEFFS_128[]{
-      {Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
-      {Sign::POS, -126, 0x935d8ddd'aaa8ac16'ea56d62b'82d30a2d_u128},
-      {Sign::POS, -126, 0xa9a92639'e753443a'80a99ce7'5f4d5bdb_u128},
-      {Sign::POS, -126, 0x82382c8e'f1652304'6a4f9d7d'bf6c9635_u128},
-      {Sign::POS, -124, 0x12bd7609'fd98c44c'34578701'9216c7af_u128},
-      {Sign::POS, -127, 0x450a7ff4'7535d889'cc41ed7e'0d27aee5_u128},
-      {Sign::POS, -130, 0xd3f6b844'702d636b'8326bb91'a6e7601d_u128},
-      {Sign::POS, -130, 0x45b937f0'd05bb1cd'fa7b46df'314112a9_u128},
-  };
-
-  DFloat128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1],
-                                 COEFFS_128[2], COEFFS_128[3], COEFFS_128[4],
-                                 COEFFS_128[5], COEFFS_128[6], COEFFS_128[7]);
-  return p;
-}
-
-// Compute 10^(x) using 128-bit precision.
-// TODO(lntue): investigate triple-double precision implementation for this
-// step.
-LIBC_INLINE DFloat128 exp10_f128(double x, double kd, int idx1, int idx2) {
-  double t1 = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_HI, x); // exact
-  double t2 = kd * MLOG10_2_EXP2_M12_MID_32;                     // exact
-  double t3 = kd * MLOG10_2_EXP2_M12_LO; // Error < 2^-144
-
-  DFloat128 dx = fputil::quick_add(
-      DFloat128(t1), fputil::quick_add(DFloat128(t2), DFloat128(t3)));
-
-  // TODO: Skip recalculating exp_mid1 and exp_mid2.
-  DFloat128 exp_mid1 =
-      fputil::quick_add(DFloat128(EXP2_MID1[idx1].hi),
-                        fputil::quick_add(DFloat128(EXP2_MID1[idx1].mid),
-                                          DFloat128(EXP2_MID1[idx1].lo)));
-
-  DFloat128 exp_mid2 =
-      fputil::quick_add(DFloat128(EXP2_MID2[idx2].hi),
-                        fputil::quick_add(DFloat128(EXP2_MID2[idx2].mid),
-                                          DFloat128(EXP2_MID2[idx2].lo)));
-
-  DFloat128 exp_mid = fputil::quick_mul(exp_mid1, exp_mid2);
-
-  DFloat128 p = exp10_poly_approx_f128(dx);
-
-  DFloat128 r = fputil::quick_mul(exp_mid, p);
-
-  r.exponent += static_cast<int>(kd) >> 12;
-
-  return r;
-}
-
-// Compute 10^x with double-double precision.
-LIBC_INLINE DoubleDouble exp10_double_double(double x, double kd,
-                                             const DoubleDouble &exp_mid) {
-  // Recalculate dx:
-  //   dx = x - k * 2^-12 * log10(2)
-  double t1 = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_HI, x); // exact
-  double t2 = kd * MLOG10_2_EXP2_M12_MID_32;                     // exact
-  double t3 = kd * MLOG10_2_EXP2_M12_LO; // Error < 2^-140
-
-  DoubleDouble dx = fputil::exact_add(t1, t2);
-  dx.lo += t3;
-
-  // Degree-6 polynomial approximation in double-double precision.
-  // | p - 10^x | < 2^-103.
-  DoubleDouble p = exp10_poly_approx_dd(dx);
-
-  // Error bounds: 2^-102.
-  DoubleDouble r = fputil::quick_mult(exp_mid, p);
-
-  return r;
-}
-#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-// When output is denormal.
-LIBC_INLINE double exp10_denorm(double x) {
-  // Range reduction.
-  double tmp = fputil::multiply_add(x, LOG2_10, 0x1.8000'0000'4p21);
-  int k = static_cast<int>(cpp::bit_cast<uint64_t>(tmp) >> 19);
-  double kd = static_cast<double>(k);
-
-  uint32_t idx1 = (k >> 6) & 0x3f;
-  uint32_t idx2 = k & 0x3f;
-
-  int hi = k >> 12;
-
-  DoubleDouble exp_mid1{EXP2_MID1[idx1].mid, EXP2_MID1[idx1].hi};
-  DoubleDouble exp_mid2{EXP2_MID2[idx2].mid, EXP2_MID2[idx2].hi};
-  DoubleDouble exp_mid = fputil::quick_mult(exp_mid1, exp_mid2);
-
-  // |dx| < 1.5 * 2^-15 + 2^-31 < 2^-14
-  double lo_h = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_HI, x); // exact
-  double dx = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_MID, lo_h);
-
-  double mid_lo = dx * exp_mid.hi;
-
-  // Approximate (10^dx - 1)/dx ~ 1 + a0*dx + a1*dx^2 + a2*dx^3 + a3*dx^4.
-  double p = exp10_poly_approx_d(dx);
+#include "src/__support/macros/optimization.h"
 
-  double lo = fputil::multiply_add(p, mid_lo, exp_mid.lo);
-
-#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo,
-                                                 EXP10_ERR_D)
-      .value();
-#else
-  using FPBits = fputil::FPBits<double>;
-
-  if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, EXP10_ERR_D);
-      LIBC_LIKELY(r.has_value())) {
-    double res = r.value();
-    if (LIBC_UNLIKELY(FPBits(res).is_normal()))
-      return res;
-    fputil::set_errno_if_required(ERANGE);
-    fputil::raise_underflow_except_if_required<double>();
-    return res;
-  }
-
-  // Use double-double
-  DoubleDouble r_dd = exp10_double_double(x, kd, exp_mid);
-
-  if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, EXP10_ERR_DD);
-      LIBC_LIKELY(r.has_value())) {
-    double res = r.value();
-    if (LIBC_UNLIKELY(FPBits(res).is_normal()))
-      return res;
-    fputil::set_errno_if_required(ERANGE);
-    fputil::raise_underflow_except_if_required<double>();
-    return res;
-  }
-
-  // Use 128-bit precision
-  DFloat128 r_f128 = exp10_f128(x, kd, idx1, idx2);
-
-  return static_cast<double>(r_f128);
-#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-}
-
-// Check for exceptional cases when:
-//  * log10(1 - 2^-54) < x < log10(1 + 2^-53)
-//  * x >= log10(2^1024)
-//  * x <= log10(2^-1022)
-//  * x is inf or nan
-LIBC_INLINE double exp10_set_exceptional(double x) {
-  using FPBits = typename fputil::FPBits<double>;
-  FPBits xbits(x);
-
-  uint64_t x_u = xbits.uintval();
-  uint64_t x_abs = xbits.abs().uintval();
-
-  // |x| < log10(1 + 2^-53)
-  if (x_abs <= 0x3c8bcb7b1526e50e) {
-    // 10^(x) ~ 1 + x/2
-    return fputil::multiply_add(x, 0.5, 1.0);
-  }
-
-  // x <= log10(2^-1022) || x >= log10(2^1024) or inf/nan.
-  if (x_u >= 0xc0733a7146f72a42) {
-    // x <= log10(2^-1075) or -inf/nan
-    if (x_u > 0xc07439b746e36b52) {
-      // exp(-Inf) = 0
-      if (xbits.is_inf())
-        return 0.0;
-
-      // exp(nan) = nan
-      if (xbits.is_nan())
-        return x + FPBits::inf().get_val();
-
-      fputil::set_errno_if_required(ERANGE);
-      fputil::raise_underflow_except_if_required<double>();
-#ifndef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
-      if (fputil::quick_get_round() == FE_UPWARD)
-        return FPBits::min_subnormal().get_val();
-#endif
-      return 0.0;
-    }
-
-    return exp10_denorm(x);
-  }
-
-  // x >= log10(2^1024) or +inf/nan
-  // x is finite
-  if (x_u < 0x7ff0'0000'0000'0000ULL) {
-    fputil::set_errno_if_required(ERANGE);
-    fputil::raise_overflow_except_if_required<double>();
-#ifndef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
-    int rounding = fputil::quick_get_round();
-    if (rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO)
-      return FPBits::max_normal().get_val();
-#endif
-    return FPBits::inf().get_val();
-  }
-  // x is +inf or nan
-  return x + FPBits::inf().get_val();
-}
+#include "src/__support/math/exp10_double_eval.h"
+#define LIBC_MATH_EXP10_IMPL double_eval
 
+namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE double exp10(double x) {
-  using FPBits = typename fputil::FPBits<double>;
-  FPBits xbits(x);
-
-  uint64_t x_u = xbits.uintval();
-
-  // x <= log10(2^-1022) or x >= log10(2^1024) or
-  // log10(1 - 2^-54) < x < log10(1 + 2^-53).
-  if (LIBC_UNLIKELY(x_u >= 0xc0733a7146f72a42 ||
-                    (x_u <= 0xbc7bcb7b1526e50e && x_u >= 0x40734413509f79ff) ||
-                    x_u < 0x3c8bcb7b1526e50e)) {
-    return exp10_set_exceptional(x);
-  }
-
-  // Now log10(2^-1075) < x <= log10(1 - 2^-54) or
-  //     log10(1 + 2^-53) < x < log10(2^1024)
-
-  // Range reduction:
-  // Let x = log10(2) * (hi + mid1 + mid2) + lo
-  // in which:
-  //   hi is an integer
-  //   mid1 * 2^6 is an integer
-  //   mid2 * 2^12 is an integer
-  // then:
-  //   10^(x) = 2^hi * 2^(mid1) * 2^(mid2) * 10^(lo).
-  // With this formula:
-  //   - multiplying by 2^hi is exact and cheap, simply by adding the exponent
-  //     field.
-  //   - 2^(mid1) and 2^(mid2) are stored in 2 x 64-element tables.
-  //   - 10^(lo) ~ 1 + a0*lo + a1 * lo^2 + ...
-  //
-  // We compute (hi + mid1 + mid2) together by perform the rounding on
-  //   x * log2(10) * 2^12.
-  // Since |x| < |log10(2^-1075)| < 2^9,
-  //   |x * 2^12| < 2^9 * 2^12 < 2^21,
-  // So we can fit the rounded result round(x * 2^12) in int32_t.
-  // Thus, the goal is to be able to use an additional addition and fixed width
-  // shift to get an int32_t representing round(x * 2^12).
-  //
-  // Assuming int32_t using 2-complement representation, since the mantissa part
-  // of a double precision is unsigned with the leading bit hidden, if we add an
-  // extra constant C = 2^e1 + 2^e2 with e1 > e2 >= 2^23 to the product, the
-  // part that are < 2^e2 in resulted mantissa of (x*2^12*L2E + C) can be
-  // considered as a proper 2-complement representations of x*2^12.
-  //
-  // One small problem with this approach is that the sum (x*2^12 + C) in
-  // double precision is rounded to the least significant bit of the dorminant
-  // factor C.  In order to minimize the rounding errors from this addition, we
-  // want to minimize e1.  Another constraint that we want is that after
-  // shifting the mantissa so that the least significant bit of int32_t
-  // corresponds to the unit bit of (x*2^12*L2E), the sign is correct without
-  // any adjustment.  So combining these 2 requirements, we can choose
-  //   C = 2^33 + 2^32, so that the sign bit corresponds to 2^31 bit, and hence
-  // after right shifting the mantissa, the resulting int32_t has correct sign.
-  // With this choice of C, the number of mantissa bits we need to shift to the
-  // right is: 52 - 33 = 19.
-  //
-  // Moreover, since the integer right shifts are equivalent to rounding down,
-  // we can add an extra 0.5 so that it will become round-to-nearest, tie-to-
-  // +infinity.  So in particular, we can compute:
-  //   hmm = x * 2^12 + C,
-  // where C = 2^33 + 2^32 + 2^-1, then if
-  //   k = int32_t(lower 51 bits of double(x * 2^12 + C) >> 19),
-  // the reduced argument:
-  //   lo = x - log10(2) * 2^-12 * k is bounded by:
-  //   |lo|  = |x - log10(2) * 2^-12 * k|
-  //         = log10(2) * 2^-12 * | x * log2(10) * 2^12 - k |
-  //        <= log10(2) * 2^-12 * (2^-1 + 2^-19)
-  //         < 1.5 * 2^-2 * (2^-13 + 2^-31)
-  //         = 1.5 * (2^-15 * 2^-31)
-  //
-  // Finally, notice that k only uses the mantissa of x * 2^12, so the
-  // exponent 2^12 is not needed.  So we can simply define
-  //   C = 2^(33 - 12) + 2^(32 - 12) + 2^(-13 - 12), and
-  //   k = int32_t(lower 51 bits of double(x + C) >> 19).
-
-  // Rounding errors <= 2^-31.
-  double tmp = fputil::multiply_add(x, LOG2_10, 0x1.8000'0000'4p21);
-  int k = static_cast<int>(cpp::bit_cast<uint64_t>(tmp) >> 19);
-  double kd = static_cast<double>(k);
-
-  uint32_t idx1 = (k >> 6) & 0x3f;
-  uint32_t idx2 = k & 0x3f;
-
-  int hi = k >> 12;
-
-  DoubleDouble exp_mid1{EXP2_MID1[idx1].mid, EXP2_MID1[idx1].hi};
-  DoubleDouble exp_mid2{EXP2_MID2[idx2].mid, EXP2_MID2[idx2].hi};
-  DoubleDouble exp_mid = fputil::quick_mult(exp_mid1, exp_mid2);
-
-  // |dx| < 1.5 * 2^-15 + 2^-31 < 2^-14
-  double lo_h = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_HI, x); // exact
-  double dx = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_MID, lo_h);
-
-  // We use the degree-4 polynomial to approximate 10^(lo):
-  //   10^(lo) ~ 1 + a0 * lo + a1 * lo^2 + a2 * lo^3 + a3 * lo^4
-  //           = 1 + lo * P(lo)
-  // So that the errors are bounded by:
-  //   |P(lo) - (10^lo - 1)/lo| < |lo|^4 / 64 < 2^(-13 * 4) / 64 = 2^-58
-  // Let P_ be an evaluation of P where all intermediate computations are in
-  // double precision.  Using either Horner's or Estrin's schemes, the evaluated
-  // errors can be bounded by:
-  //      |P_(lo) - P(lo)| < 2^-51
-  //   => |lo * P_(lo) - (2^lo - 1) | < 2^-65
-  //   => 2^(mid1 + mid2) * |lo * P_(lo) - expm1(lo)| < 2^-64.
-  // Since we approximate
-  //   2^(mid1 + mid2) ~ exp_mid.hi + exp_mid.lo,
-  // We use the expression:
-  //    (exp_mid.hi + exp_mid.lo) * (1 + dx * P_(dx)) ~
-  //  ~ exp_mid.hi + (exp_mid.hi * dx * P_(dx) + exp_mid.lo)
-  // with errors bounded by 2^-64.
-
-  double mid_lo = dx * exp_mid.hi;
-
-  // Approximate (10^dx - 1)/dx ~ 1 + a0*dx + a1*dx^2 + a2*dx^3 + a3*dx^4.
-  double p = exp10_poly_approx_d(dx);
-
-  double lo = fputil::multiply_add(p, mid_lo, exp_mid.lo);
-
-#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  int64_t exp_hi = static_cast<int64_t>(hi) * (1LL << FPBits::FRACTION_LEN);
-  double r =
-      cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(exp_mid.hi + lo));
-  return r;
-#else
-  double upper = exp_mid.hi + (lo + EXP10_ERR_D);
-  double lower = exp_mid.hi + (lo - EXP10_ERR_D);
-
-  if (LIBC_LIKELY(upper == lower)) {
-    // To multiply by 2^hi, a fast way is to simply add hi to the exponent
-    // field.
-    int64_t exp_hi = static_cast<int64_t>(hi) * (1LL << FPBits::FRACTION_LEN);
-    double r = cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(upper));
-    return r;
-  }
-
-  // Exact outputs when x = 1, 2, ..., 22 + hard to round with x = 23.
-  // Quick check mask: 0x800f'ffffU = ~(bits of 1.0 | ... | bits of 23.0)
-  if (LIBC_UNLIKELY((x_u & 0x8000'ffff'ffff'ffffULL) == 0ULL)) {
-    switch (x_u) {
-    case 0x3ff0000000000000: // x = 1.0
-      return 10.0;
-    case 0x4000000000000000: // x = 2.0
-      return 100.0;
-    case 0x4008000000000000: // x = 3.0
-      return 1'000.0;
-    case 0x4010000000000000: // x = 4.0
-      return 10'000.0;
-    case 0x4014000000000000: // x = 5.0
-      return 100'000.0;
-    case 0x4018000000000000: // x = 6.0
-      return 1'000'000.0;
-    case 0x401c000000000000: // x = 7.0
-      return 10'000'000.0;
-    case 0x4020000000000000: // x = 8.0
-      return 100'000'000.0;
-    case 0x4022000000000000: // x = 9.0
-      return 1'000'000'000.0;
-    case 0x4024000000000000: // x = 10.0
-      return 10'000'000'000.0;
-    case 0x4026000000000000: // x = 11.0
-      return 100'000'000'000.0;
-    case 0x4028000000000000: // x = 12.0
-      return 1'000'000'000'000.0;
-    case 0x402a000000000000: // x = 13.0
-      return 10'000'000'000'000.0;
-    case 0x402c000000000000: // x = 14.0
-      return 100'000'000'000'000.0;
-    case 0x402e000000000000: // x = 15.0
-      return 1'000'000'000'000'000.0;
-    case 0x4030000000000000: // x = 16.0
-      return 10'000'000'000'000'000.0;
-    case 0x4031000000000000: // x = 17.0
-      return 100'000'000'000'000'000.0;
-    case 0x4032000000000000: // x = 18.0
-      return 1'000'000'000'000'000'000.0;
-    case 0x4033000000000000: // x = 19.0
-      return 10'000'000'000'000'000'000.0;
-    case 0x4034000000000000: // x = 20.0
-      return 100'000'000'000'000'000'000.0;
-    case 0x4035000000000000: // x = 21.0
-      return 1'000'000'000'000'000'000'000.0;
-    case 0x4036000000000000: // x = 22.0
-      return 10'000'000'000'000'000'000'000.0;
-    case 0x4037000000000000: // x = 23.0
-      return 0x1.52d02c7e14af6p76 + x;
-    }
-  }
-
-  // Use double-double
-  DoubleDouble r_dd = exp10_double_double(x, kd, exp_mid);
-
-  double upper_dd = r_dd.hi + (r_dd.lo + EXP10_ERR_DD);
-  double lower_dd = r_dd.hi + (r_dd.lo - EXP10_ERR_DD);
-
-  if (LIBC_LIKELY(upper_dd == lower_dd)) {
-    // To multiply by 2^hi, a fast way is to simply add hi to the exponent
-    // field.
-    int64_t exp_hi = static_cast<int64_t>(hi) * (1LL << FPBits::FRACTION_LEN);
-    double r = cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(upper_dd));
-    return r;
-  }
-
-  // Use 128-bit precision
-  DFloat128 r_f128 = exp10_f128(x, kd, idx1, idx2);
-
-  return static_cast<double>(r_f128);
-#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-}
+using LIBC_MATH_EXP10_IMPL::exp10;
 
 } // namespace math
-
 } // namespace LIBC_NAMESPACE_DECL
 
+#undef LIBC_MATH_EXP10_IMPL
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP10_H
diff --git a/libc/src/__support/math/exp10_double_eval.h b/libc/src/__support/math/exp10_double_eval.h
new file mode 100644
index 00000000000000..f137027fdc4700
--- /dev/null
+++ b/libc/src/__support/math/exp10_double_eval.h
@@ -0,0 +1,233 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Double-precision implementation of exp10.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP10_DOUBLE_EVAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP10_DOUBLE_EVAL_H
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/fp_bitwise.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/cpu_features.h"
+
+#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+#include "src/__support/math/exp_double_utils.h"
+#else
+#include "src/__support/math/exp_utils.h"
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+namespace double_eval {
+
+// log2(10) = 0x1.a934f0979a371p+1 + 0x1.7f2495fb7fa7bp-52
+LIBC_INLINE_VAR constexpr double LOG2_10_HI = 0x1.a934f0979a371p+1;
+
+// log(10) = 0x1.26bb1bbb55516p+1 - 0x1.f48ad494ea3e9p-53
+LIBC_INLINE_VAR constexpr DoubleDouble LOG_10 = {-0x1.f48ad494ea3e9p-53,
+                                                 0x1.26bb1bbb55516p+1};
+
+#if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) &&                               \
+    defined(LIBC_MATH_HAS_SMALL_TABLES)
+// Splitting -2^-3 * log10(2) ~ hi + lo with 36-bit-precision hi part so that
+// kd * MLOG10_2_EXP2_HI is exact for |kd| < 2^14:
+// > a = -2^-3 * log10(2);
+// > hi = round(a, 36, RN); // -0x1.34413509f8p-5
+// > lo = round(a - hi, D, RN); // 0x1.80433b83b532ap-47
+LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_HI = -0x1.34413509f8p-5;
+LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_MID = 0x1.80433b83b532ap-47;
+#else
+// Splitting -2^-7 * log10(2) ~ hi + lo with 35-bit-precision hi part so that
+// kd * MLOG10_2_EXP2_HI is exact for |kd| < 2^18:
+// > a = -2^-7 * log10(2);
+// > hi = round(a, 35, RN); // -0x1.3441350ap-9
+// > lo = round(a - hi, D, RN); // 0x1.0c0219dc1da99p-46
+LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_HI = -0x1.3441350ap-9;
+LIBC_INLINE_VAR constexpr double MLOG10_2_EXP2_MID = 0x1.0c0219dc1da99p-46;
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS && LIBC_MATH_HAS_SMALL_TABLES
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+// Splitting log(10) ~ hi + lo with 12-bit-precision hi part for exact non-FMA
+// multiplication without Veltkamp splitting:
+// > hi = round(log(10), 12, RN);
+// > lo = round(log(10) - hi, D, RN);
+LIBC_INLINE_VAR constexpr double LOG_10_HI_12 = 0x1.26cp+1;
+LIBC_INLINE_VAR constexpr double LOG_10_LO_12 =
+    (LOG_10.hi - LOG_10_HI_12) + LOG_10.lo;
+
+// Fast-path Ziv error bound for exp10:
+LIBC_INLINE_VAR constexpr double EXP10_ERR_D = 0x1.8p-64;
+
+// Exact powers of 10 in double precision: 10^1, 10^2, ..., 10^22.
+LIBC_INLINE_VAR constexpr double EXP10_EXACT[22] = {
+    0x1.4p+3,              // 10^1
+    0x1.9p+6,              // 10^2
+    0x1.f4p+9,             // 10^3
+    0x1.388p+13,           // 10^4
+    0x1.86ap+16,           // 10^5
+    0x1.e848p+19,          // 10^6
+    0x1.312dp+23,          // 10^7
+    0x1.7d784p+26,         // 10^8
+    0x1.dcd65p+29,         // 10^9
+    0x1.2a05f2p+33,        // 10^10
+    0x1.74876e8p+36,       // 10^11
+    0x1.d1a94a2p+39,       // 10^12
+    0x1.2309ce54p+43,      // 10^13
+    0x1.6bcc41e9p+46,      // 10^14
+    0x1.c6bf52634p+49,     // 10^15
+    0x1.1c37937e08p+53,    // 10^16
+    0x1.6345785d8ap+56,    // 10^17
+    0x1.bc16d674ec8p+59,   // 10^18
+    0x1.158e460913d00p+63, // 10^19
+    0x1.5af1d78b58c40p+66, // 10^20
+    0x1.b1ae4d6e2ef50p+69, // 10^21
+    0x1.0f0cf064dd592p+73, // 10^22
+};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+LIBC_ALWAYS_INLINE double exp10(double x) {
+  using FPBits = fputil::FPBits<double>;
+  FPBits xbits(x);
+
+  uint64_t x_u = xbits.uintval();
+  uint64_t x_abs = xbits.abs().uintval();
+
+  // Bound constants (with biased exponent and mantissa bits):
+  // - Tiny bound: 10^x ~ 1 when |x| <= 2^-54 / log(10)
+  //   > round(2^-54 / log(10), D, RD) = 0x1.bcb7b1526e50ep-56
+  //   > round(2^-54 / log(10), D, RU) = 0x1.bcb7b1526e50fp-56
+  constexpr uint64_t TINY_BOUND = 0x3c7b'cb7b'1526'e50fULL;
+  // - Overflow bound: 10^x overflows when x >= log10(2^1024)
+  //   > round(log10(2^1024), D, RU) = 0x1.34413509f79ffp+8
+  constexpr uint64_t OVERFLOW_BOUND = 0x4073'4413'509f'79ffULL;
+  // -0x1.34413509f79ffp+8:
+  constexpr uint64_t NEG_OVERFLOW_BOUND = 0xc073'4413'509f'79ffULL;
+  // - Underflow bound: 10^x underflows to 0 when x <= log10(2^-1075)
+  //   > round(log10(2^-1075), D, RD) = -0x1.439b746e36b53p+8
+  constexpr uint64_t UNDERFLOW_BOUND = 0xc074'39b7'46e3'6b53ULL;
+
+  // Normal non-tiny range: TINY_BOUND <= |x| < OVERFLOW_BOUND.
+  if (LIBC_UNLIKELY(x_abs - TINY_BOUND >= OVERFLOW_BOUND - TINY_BOUND)) {
+    // Exclude non-underflowing negative inputs in
+    // (UNDERFLOW_BOUND, NEG_OVERFLOW_BOUND].
+    if (LIBC_LIKELY(x_u < NEG_OVERFLOW_BOUND || x_u >= UNDERFLOW_BOUND))
+      return set_exceptional(x);
+  }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  // Exact outputs when x = 1, 2, ..., 22 (must not raise FE_INEXACT).
+  // 0x3ff0 = high 16 bits of 0x1.0p+0 (1.0)
+  // 0x4036 = high 16 bits of 0x1.6p+4 (22.0)
+  if (LIBC_UNLIKELY((x_u << 16) == 0ULL)) {
+    uint32_t d = static_cast<uint32_t>(x_u >> 48) - 0x3ff0U;
+    if (d <= 0x46U) {
+      uint32_t scaled = (16U | (d & 0xfU)) << (d >> 4);
+      if ((scaled & 0xfU) == 0U)
+        return EXP10_EXACT[static_cast<size_t>(scaled >> 4) - 1];
+    }
+  }
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  // Now -0x1.439b746e36b53p+8 < x < -0x1.bcb7b1526e50ep-56 or
+  //     0x1.bcb7b1526e50ep-56 < x < 0x1.34413509f79ffp+8.
+
+  // Range reduction:
+  // Let x = k * (log10(2) / 2^N) + dx
+  // in which:
+  //   k   = round(x * 2^N * log2(10))
+  //   hi  = k >> N
+  //   idx = k & (2^N - 1)
+  // then:
+  //   10^x = 2^hi * 2^(idx / 2^N) * exp(dx * log(10)).
+  //
+  // Using ROUND_BIAS, ROUND_SHIFT, and ROUND_MASK (see exp_utils.h), we compute
+  // k_biased = fma(x, LOG2_10_SCALE, ROUND_BIAS) and extract in parallel:
+  //   kd  = (k_biased & ROUND_MASK) - ROUND_SHIFT
+  //   hi  = (int32_t)(k_bits >> 19) >> (13 + N)
+  //   idx = (k_bits >> 32) & (2^N - 1).
+  constexpr double LOG2_10_SCALE = EXP_SCALE * LOG2_10_HI;
+
+  double k_biased = fputil::multiply_add(x, LOG2_10_SCALE, ROUND_BIAS);
+  double kd = fputil::fp_and(k_biased, ROUND_MASK) - ROUND_SHIFT;
+  uint64_t k_bits = cpp::bit_cast<uint64_t>(k_biased);
+
+  int hi = static_cast<int32_t>(k_bits >> 19) >> (13 + EXP_N_BITS);
+  unsigned idx = static_cast<unsigned>(k_bits >> 32) & EXP_MASK;
+
+#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  double t1 = fputil::multiply_add(kd, MLOG10_2_EXP2_HI, x); // exact
+  double dx = fputil::multiply_add(kd, MLOG10_2_EXP2_MID, t1);
+  double u = dx * LOG_10.hi;
+  return exp2_eval(x, u, hi, idx);
+#else // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+#ifdef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+  // With FMA, we use the full 53-bit:
+  //   MLOG10_2_HI_53 = -2^-7 * log10(2) = -0x1.34413509f79ffp-9 (lsb = 2^-61)
+  // and pre-multiplied remainder:
+  //   MLOG10_2_MID_53_LOG10 = (-2^-7 * log10(2) - MLOG10_2_HI_53) * log(10)
+  //                         = 0x1.dc5b0a78f8364p-65
+  // to compute:
+  //   u = (x - k * 2^-7 * log10(2)) * log(10) ~ t1 * log(10) + corr
+  // where:
+  //   t1   = fma(kd, MLOG10_2_HI_53, x)   (exact for k != 0)
+  //   corr = kd * MLOG10_2_MID_53_LOG10   (|corr| < 2^18 * 2^-64 = 2^-46).
+  //
+  // Writing:
+  //   exp(u.hi + d) = exp(u.hi) * exp(d)
+  //                 ~ (1 + u.hi + u.hi^2 * P(u.hi)) * (1 + d),
+  // we fold the linear cross-term u.hi * corr into u.lo.
+  constexpr double MLOG10_2_HI_53 = -0x1.34413509f79ffp-2 * EXP_SCALE_INV;
+  constexpr double MLOG10_2_MID_53_LOG10 =
+      0x1.dc5b0a78f8364p-58 * EXP_SCALE_INV;
+
+  double t1 = fputil::multiply_add(kd, MLOG10_2_HI_53, x); // exact
+  double corr = kd * MLOG10_2_MID_53_LOG10;
+  DoubleDouble u = fputil::exact_mult(t1, LOG_10.hi);
+  double lo1 = fputil::multiply_add(t1, LOG_10.lo, corr);
+  double lo2 = fputil::multiply_add(u.hi, corr, lo1);
+  u.lo += lo2;
+  return exp2_eval(x, u, hi, idx, EXP10_ERR_D, &LOG2_10_192);
+#else  // !LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+  // Without FMA, we use a 35-bit-precision high part MLOG10_2_EXP2_HI (with
+  // lsb = 2^-43) so that:
+  //   dx1 = x + kd * MLOG10_2_EXP2_HI
+  // is exact for |kd| < 2^18.
+  //
+  // We then split dx1 at 2^-18 before multiplying by the 12-bit LOG_10_HI_12
+  // (with lsb = 2^-10):
+  //   dx_hi = (dx1 + SPLIT_18) - SPLIT_18   (exact, lsb = 2^-18)
+  //   dx_lo = (dx1 - dx_hi) + dx2           (|dx_lo| < 2^-18)
+  //   u_hi  = dx_hi * LOG_10_HI_12          (exact, lsb = 2^-28 >= 2^-30)
+  //   u_lo  = dx_lo * LOG_10_HI_12 + dx_sum * LOG_10_LO_12.
+  double dx1 = fputil::multiply_add(kd, MLOG10_2_EXP2_HI, x); // exact
+  double dx2 = kd * MLOG10_2_EXP2_MID;
+  double dx_sum = dx1 + dx2;
+  double dx_hi = (dx1 + SPLIT_18) - SPLIT_18;
+  double dx_lo = (dx1 - dx_hi) + dx2;
+  double u_hi = dx_hi * LOG_10_HI_12; // exact, lsb = 2^-28 >= 2^-30
+  double u_lo = dx_lo * LOG_10_HI_12 + dx_sum * LOG_10_LO_12;
+  return exp2_eval(x, {u_lo, u_hi}, hi, idx, EXP10_ERR_D, &LOG2_10_192);
+#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+}
+
+} // namespace double_eval
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP10_DOUBLE_EVAL_H
diff --git a/libc/src/__support/math/exp2_accurate_128.h b/libc/src/__support/math/exp2_accurate_128.h
index 31c8bde4259756..70e3c1ce9deb21 100644
--- a/libc/src/__support/math/exp2_accurate_128.h
+++ b/libc/src/__support/math/exp2_accurate_128.h
@@ -125,6 +125,25 @@ LIBC_INLINE_VAR constexpr ExpBase192 LOG2_E_192 = {
     }),
 };
 
+// log2(10) in 192-bit fixed-point format (lsb = 2^-190, base_exp = 1),
+// generated by Sollya with:
+// > display = hexadecimal!;
+// > prec = 500;
+// > c = round(log2(10) * 2^190, 192, RN);
+// > d2 = floor(c * 2^(-128));
+// > c = c - d2 * 2^128;
+// > d1 = floor(c * 2^(-64));
+// > d0 = c - d1 * 2^64;
+// > print("{", d0, ",", d1, ",", d2, "}");
+LIBC_INLINE_VAR constexpr ExpBase192 LOG2_10_192 = {
+    1,
+    UInt<192>({
+        0xd96c55fe37b3ad4fULL,
+        0x492bf6ff4dafdb4cULL,
+        0xd49a784bcd1b8afeULL,
+    }),
+};
+
 // Evaluate 2^(idx * 2^-4 + u) in [1, 2) as Frac128 (lsb = 2^-127) for
 // idx in [0, 15] and u in [0, 2^-4) (lsb = 2^-128).
 LIBC_INLINE Frac128 exp2_eval_frac128(unsigned idx, const Frac128 &u) {
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index ec824d2ec5df30..1b7d68176073dd 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1467,8 +1467,11 @@ add_fp_unittest(
   SRCS
     exp10_test.cpp
   DEPENDS
+    libc.hdr.fenv_macros
     libc.src.math.exp10
+    libc.src.__support.math.exp10_double_eval
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.macros.attributes
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/exp10_test.cpp b/libc/test/src/math/exp10_test.cpp
index f31b3b2957853d..e4c6efdcef673a 100644
--- a/libc/test/src/math/exp10_test.cpp
+++ b/libc/test/src/math/exp10_test.cpp
@@ -1,154 +1,214 @@
-//===-- Unittests for 10^x ------------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 unittests for exp10.
+///
+//===----------------------------------------------------------------------===//
 
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/macros/attributes.h"
 #include "src/__support/macros/optimization.h"
+#include "src/__support/math/exp10_double_eval.h"
 #include "src/math/exp10.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 
 #ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+#if defined(LIBC_MATH_HAS_SMALL_TABLES) &&                                     \
+    !defined(LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY)
+#define TOLERANCE 2
+#else
 #define TOLERANCE 1
+#endif // LIBC_MATH_HAS_SMALL_TABLES && !LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
 #else
 #define TOLERANCE 0
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
-using LlvmLibcExp10Test = LIBC_NAMESPACE::testing::FPTest<double>;
+#ifdef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
+#define ALL_ROUNDING false
+#else
+#define ALL_ROUNDING true
+#endif // LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
 
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 using LIBC_NAMESPACE::testing::tlog;
 
-TEST_F(LlvmLibcExp10Test, SpecialNumbers) {
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::exp10(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::exp10(inf));
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::exp10(neg_inf));
-  EXPECT_FP_EQ_WITH_EXCEPTION(zero, LIBC_NAMESPACE::exp10(-0x1.0p20),
-                              FE_UNDERFLOW);
-  EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp10(0x1.0p20),
-                              FE_OVERFLOW);
-  EXPECT_FP_EQ_ALL_ROUNDING(1.0, LIBC_NAMESPACE::exp10(0.0));
-  EXPECT_FP_EQ_ALL_ROUNDING(1.0, LIBC_NAMESPACE::exp10(-0.0));
+LIBC_NOINLINE double exp10_double_eval(double x) {
+  return LIBC_NAMESPACE::math::double_eval::exp10(x);
 }
 
-TEST_F(LlvmLibcExp10Test, TrickyInputs) {
-  constexpr int N = 41;
-  constexpr uint64_t INPUTS[N] = {
-      0x40033093317082F8, 0x3FD79289C6E6A5C0,
-      0x3FD05DE80A173EA0, // 0x1.05de80a173eap-2
-      0xbf1eb7a4cb841fcc, // -0x1.eb7a4cb841fccp-14
-      0xbf19a61fb925970d,
-      0x3fda7b764e2cf47a, // 0x1.a7b764e2cf47ap-2
-      0xc04757852a4b93aa, // -0x1.757852a4b93aap+5
-      0x4044c19e5712e377, // x=0x1.4c19e5712e377p+5
-      0xbf19a61fb925970d, // x=-0x1.9a61fb925970dp-14
-      0xc039a74cdab36c28, // x=-0x1.9a74cdab36c28p+4
-      0xc085b3e4e2e3bba9, // x=-0x1.5b3e4e2e3bba9p+9
-      0xc086960d591aec34, // x=-0x1.6960d591aec34p+9
-      0xc086232c09d58d91, // x=-0x1.6232c09d58d91p+9
-      0xc0874910d52d3051, // x=-0x1.74910d52d3051p9
-      0xc0867a172ceb0990, // x=-0x1.67a172ceb099p+9
-      0xc08ff80000000000, // x=-0x1.ff8p+9
-      0xbc971547652b82fe, // x=-0x1.71547652b82fep-54
-      0x0000000000000000, // x = 0
-      0x3ff0000000000000, // x = 1
-      0x4000000000000000, // x = 2
-      0x4008000000000000, // x = 3
-      0x4010000000000000, // x = 4
-      0x4014000000000000, // x = 5
-      0x4018000000000000, // x = 6
-      0x401c000000000000, // x = 7
-      0x4020000000000000, // x = 8
-      0x4022000000000000, // x = 9
-      0x4024000000000000, // x = 10
-      0x4026000000000000, // x = 11
-      0x4028000000000000, // x = 12
-      0x402a000000000000, // x = 13
-      0x402c000000000000, // x = 14
-      0x402e000000000000, // x = 15
-      0x4030000000000000, // x = 16
-      0x4031000000000000, // x = 17
-      0x4032000000000000, // x = 18
-      0x4033000000000000, // x = 19
-      0x4034000000000000, // x = 20
-      0x4035000000000000, // x = 21
-      0x4036000000000000, // x = 22
-      0x4037000000000000, // x = 23
-  };
-  for (int i = 0; i < N; ++i) {
-    double x = FPBits(INPUTS[i]).get_val();
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
-                                   LIBC_NAMESPACE::exp10(x), TOLERANCE + 0.5);
+class Exp10Test : public LIBC_NAMESPACE::testing::FPTest<double> {
+public:
+  void test_special_numbers(double (*func)(double)) {
+    EXPECT_FP_EQ(aNaN, func(aNaN));
+    EXPECT_FP_EQ(inf, func(inf));
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(neg_inf));
+    EXPECT_FP_EQ_ALL_ROUNDING(1.0, func(0.0));
+    EXPECT_FP_EQ_ALL_ROUNDING(1.0, func(-0.0));
   }
-}
 
-TEST_F(LlvmLibcExp10Test, InDoubleRange) {
-  constexpr uint64_t COUNT = 1'231;
-  constexpr uint64_t START = FPBits(0.25).uintval();
-  constexpr uint64_t STOP = FPBits(4.0).uintval();
-  constexpr uint64_t STEP = (STOP - START) / COUNT;
-
-  auto test = [&](mpfr::RoundingMode rounding_mode) {
-    mpfr::ForceRoundingMode __r(rounding_mode);
-    if (!__r.success)
-      return;
-
-    uint64_t fails = 0;
-    uint64_t count = 0;
-    uint64_t cc = 0;
-    double mx, mr = 0.0;
-    double tol = 0.5;
-
-    for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) {
-      double x = FPBits(v).get_val();
-      if (FPBits(v).is_nan() || FPBits(v).is_inf() || x < 0.0)
-        continue;
-      double result = LIBC_NAMESPACE::exp10(x);
-      ++cc;
-      if (FPBits(result).is_nan() || FPBits(result).is_inf())
-        continue;
-
-      ++count;
-
-      if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp10, x, result,
-                                             TOLERANCE + 0.5, rounding_mode)) {
-        ++fails;
-        while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp10, x,
-                                                  result, tol, rounding_mode)) {
-          mx = x;
-          mr = result;
-
-          if (tol > 1000.0)
-            break;
-
-          tol *= 2.0;
-        }
+  void test_overflow(double (*func)(double)) {
+    EXPECT_FP_EQ_WITH_EXCEPTION(inf, func(0x1.0p20), FE_OVERFLOW);
+  }
+
+  void test_underflow(double (*func)(double)) {
+    EXPECT_FP_EQ_WITH_EXCEPTION(zero, func(-0x1.0p20), FE_UNDERFLOW);
+  }
+
+  void test_tricky_inputs(double (*func)(double), double ulp_tolerance = 0.5,
+                          bool all_rounding = true) {
+    constexpr int N = 41;
+    constexpr uint64_t INPUTS[N] = {
+        0x40033093317082F8, 0x3FD79289C6E6A5C0,
+        0x3FD05DE80A173EA0, // 0x1.05de80a173eap-2
+        0xbf1eb7a4cb841fcc, // -0x1.eb7a4cb841fccp-14
+        0xbf19a61fb925970d,
+        0x3fda7b764e2cf47a, // 0x1.a7b764e2cf47ap-2
+        0xc04757852a4b93aa, // -0x1.757852a4b93aap+5
+        0x4044c19e5712e377, // x=0x1.4c19e5712e377p+5
+        0xbf19a61fb925970d, // x=-0x1.9a61fb925970dp-14
+        0xc039a74cdab36c28, // x=-0x1.9a74cdab36c28p+4
+        0xc085b3e4e2e3bba9, // x=-0x1.5b3e4e2e3bba9p+9
+        0xc086960d591aec34, // x=-0x1.6960d591aec34p+9
+        0xc086232c09d58d91, // x=-0x1.6232c09d58d91p+9
+        0xc0874910d52d3051, // x=-0x1.74910d52d3051p9
+        0xc0867a172ceb0990, // x=-0x1.67a172ceb099p+9
+        0xc08ff80000000000, // x=-0x1.ff8p+9
+        0xbc971547652b82fe, // x=-0x1.71547652b82fep-54
+        0x0000000000000000, // x = 0
+        0x3ff0000000000000, // x = 1
+        0x4000000000000000, // x = 2
+        0x4008000000000000, // x = 3
+        0x4010000000000000, // x = 4
+        0x4014000000000000, // x = 5
+        0x4018000000000000, // x = 6
+        0x401c000000000000, // x = 7
+        0x4020000000000000, // x = 8
+        0x4022000000000000, // x = 9
+        0x4024000000000000, // x = 10
+        0x4026000000000000, // x = 11
+        0x4028000000000000, // x = 12
+        0x402a000000000000, // x = 13
+        0x402c000000000000, // x = 14
+        0x402e000000000000, // x = 15
+        0x4030000000000000, // x = 16
+        0x4031000000000000, // x = 17
+        0x4032000000000000, // x = 18
+        0x4033000000000000, // x = 19
+        0x4034000000000000, // x = 20
+        0x4035000000000000, // x = 21
+        0x4036000000000000, // x = 22
+        0x4037000000000000, // x = 23
+    };
+    for (int i = 0; i < N; ++i) {
+      double x = FPBits(INPUTS[i]).get_val();
+      if (all_rounding) {
+        EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        EXPECT_MPFR_MATCH(mpfr::Operation::Exp10, x, func(x), ulp_tolerance);
       }
     }
-    if (fails) {
-      tlog << " Exp10 failed: " << fails << "/" << count << "/" << cc
-           << " tests.\n";
-      tlog << "   Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n";
-      EXPECT_MPFR_MATCH(mpfr::Operation::Exp10, mx, mr, 0.5, rounding_mode);
-    }
-  };
+  }
 
-  tlog << " Test Rounding To Nearest...\n";
-  test(mpfr::RoundingMode::Nearest);
+  void test_in_range(double (*func)(double), double ulp_tolerance = 0.5,
+                     bool all_rounding = true) {
+    constexpr uint64_t COUNT = 1'231;
+    constexpr uint64_t START = FPBits(0.25).uintval();
+    constexpr uint64_t STOP = FPBits(4.0).uintval();
+    constexpr uint64_t STEP = (STOP - START) / COUNT;
+
+    auto test = [&](mpfr::RoundingMode rounding_mode) {
+      mpfr::ForceRoundingMode __r(rounding_mode);
+      if (!__r.success)
+        return;
+
+      uint64_t fails = 0;
+      uint64_t count = 0;
+      uint64_t cc = 0;
+      double mx = 0.0, mr = 0.0;
+      double tol = 0.5;
+
+      for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) {
+        double x = FPBits(v).get_val();
+        if (FPBits(v).is_nan() || FPBits(v).is_inf() || x < 0.0)
+          continue;
+        double result = func(x);
+        ++cc;
+        if (FPBits(result).is_nan() || FPBits(result).is_inf())
+          continue;
+
+        ++count;
+        if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp10, x,
+                                               result, ulp_tolerance,
+                                               rounding_mode)) {
+          ++fails;
+          while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(
+              mpfr::Operation::Exp10, x, result, tol, rounding_mode)) {
+            mx = x;
+            mr = result;
+
+            if (tol > 1000.0)
+              break;
+
+            tol *= 2.0;
+          }
+        }
+      }
+      if (fails) {
+        tlog << " Exp10 failed: " << fails << "/" << count << "/" << cc
+             << " tests.\n";
+        tlog << "   Max ULPs is at most: " << static_cast<uint64_t>(tol)
+             << ".\n";
+        EXPECT_MPFR_MATCH(mpfr::Operation::Exp10, mx, mr, ulp_tolerance,
+                          rounding_mode);
+      }
+    };
 
-  tlog << " Test Rounding Downward...\n";
-  test(mpfr::RoundingMode::Downward);
+    tlog << " Test Rounding To Nearest...\n";
+    test(mpfr::RoundingMode::Nearest);
 
-  tlog << " Test Rounding Upward...\n";
-  test(mpfr::RoundingMode::Upward);
+    if (all_rounding) {
+      tlog << " Test Rounding Downward...\n";
+      test(mpfr::RoundingMode::Downward);
 
-  tlog << " Test Rounding Toward Zero...\n";
-  test(mpfr::RoundingMode::TowardZero);
-}
+      tlog << " Test Rounding Upward...\n";
+      test(mpfr::RoundingMode::Upward);
+
+      tlog << " Test Rounding Toward Zero...\n";
+      test(mpfr::RoundingMode::TowardZero);
+    }
+  }
+};
+
+#define LIST_EXP10_TESTS(suffix, func, ulp_tolerance, all_rounding)            \
+  using LlvmLibcExp10Test##suffix = Exp10Test;                                 \
+  TEST_F(LlvmLibcExp10Test##suffix, SpecialNumbers) {                          \
+    test_special_numbers(&func);                                               \
+  }                                                                            \
+  TEST_F(LlvmLibcExp10Test##suffix, Overflow) { test_overflow(&func); }        \
+  TEST_F(LlvmLibcExp10Test##suffix, Underflow) { test_underflow(&func); }      \
+  TEST_F(LlvmLibcExp10Test##suffix, TrickyInputs) {                            \
+    test_tricky_inputs(&func, ulp_tolerance, all_rounding);                    \
+  }                                                                            \
+  TEST_F(LlvmLibcExp10Test##suffix, InDoubleRange) {                           \
+    test_in_range(&func, ulp_tolerance, all_rounding);                         \
+  }                                                                            \
+  static_assert(true, "Require semicolon.")
+
+LIST_EXP10_TESTS(Default, LIBC_NAMESPACE::exp10,
+                 /*ulp_tolerance=*/TOLERANCE + 0.5,
+                 /*all_rounding=*/ALL_ROUNDING);
+LIST_EXP10_TESTS(DoubleEval, exp10_double_eval,
+                 /*ulp_tolerance=*/TOLERANCE + 0.5,
+                 /*all_rounding=*/ALL_ROUNDING);
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index e6d7ada0385592..31423f9a40bf7c 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1576,8 +1576,11 @@ add_fp_unittest(
     exp10_test.cpp
   DEPENDS
     libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.exp10
+    libc.src.__support.math.exp10_double_eval
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.macros.attributes
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/smoke/exp10_test.cpp b/libc/test/src/math/smoke/exp10_test.cpp
index 8f564de817f42a..33a7a30e391c0a 100644
--- a/libc/test/src/math/smoke/exp10_test.cpp
+++ b/libc/test/src/math/smoke/exp10_test.cpp
@@ -1,70 +1,108 @@
-//===-- Unittests for 10^x ------------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 smoke tests for exp10.
+///
+//===----------------------------------------------------------------------===//
 
 #include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/math/exp10_double_eval.h"
 #include "src/math/exp10.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-using LlvmLibcExp10Test = LIBC_NAMESPACE::testing::FPTest<double>;
+LIBC_NOINLINE double exp10_double_eval(double x) {
+  return LIBC_NAMESPACE::math::double_eval::exp10(x);
+}
 
-TEST_F(LlvmLibcExp10Test, SpecialNumbers) {
-  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::exp10(sNaN), FE_INVALID);
-  EXPECT_MATH_ERRNO(0);
+class Exp10Test : public LIBC_NAMESPACE::testing::FPTest<double> {
+public:
+  void test_special_numbers(double (*func)(double),
+                            bool check_snan_invalid = false) {
+    if (check_snan_invalid) {
+      EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(sNaN), FE_INVALID);
+    } else {
+      EXPECT_FP_EQ(aNaN, func(sNaN));
+    }
+    EXPECT_MATH_ERRNO(0);
 
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::exp10(aNaN));
-  EXPECT_MATH_ERRNO(0);
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::exp10(inf));
-  EXPECT_MATH_ERRNO(0);
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::exp10(neg_inf));
-  EXPECT_MATH_ERRNO(0);
+    EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN));
+    EXPECT_MATH_ERRNO(0);
 
-  EXPECT_FP_EQ_WITH_EXCEPTION(zero, LIBC_NAMESPACE::exp10(-0x1.0p20),
-                              FE_UNDERFLOW);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp10(0x1.0p20),
-                              FE_OVERFLOW);
-  EXPECT_MATH_ERRNO(ERANGE);
+    EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf));
+    EXPECT_MATH_ERRNO(0);
 
-  EXPECT_FP_EQ_ALL_ROUNDING(1.0, LIBC_NAMESPACE::exp10(0.0));
-  EXPECT_FP_EQ_ALL_ROUNDING(1.0, LIBC_NAMESPACE::exp10(-0.0));
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(neg_inf));
+    EXPECT_MATH_ERRNO(0);
 
-  EXPECT_FP_EQ_ALL_ROUNDING(10.0, LIBC_NAMESPACE::exp10(1.0));
-  EXPECT_FP_EQ_ALL_ROUNDING(100.0, LIBC_NAMESPACE::exp10(2.0));
-  EXPECT_FP_EQ_ALL_ROUNDING(1000.0, LIBC_NAMESPACE::exp10(3.0));
-}
+    EXPECT_FP_EQ_ALL_ROUNDING(1.0, func(0.0));
+    EXPECT_MATH_ERRNO(0);
 
-#ifdef LIBC_TEST_FTZ_DAZ
-
-using namespace LIBC_NAMESPACE::testing;
+    EXPECT_FP_EQ_ALL_ROUNDING(1.0, func(-0.0));
+    EXPECT_MATH_ERRNO(0);
 
-TEST_F(LlvmLibcExp10Test, FTZMode) {
-  ModifyMXCSR mxcsr(FTZ);
+    EXPECT_FP_EQ_ALL_ROUNDING(10.0, func(1.0));
+    EXPECT_FP_EQ_ALL_ROUNDING(100.0, func(2.0));
+    EXPECT_FP_EQ_ALL_ROUNDING(1000.0, func(3.0));
+  }
 
-  EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::exp10(min_denormal));
-  EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::exp10(max_denormal));
-}
+  void test_overflow(double (*func)(double)) {
+    EXPECT_FP_EQ_WITH_EXCEPTION(inf, func(0x1.0p20), FE_OVERFLOW);
+    EXPECT_MATH_ERRNO(ERANGE);
+  }
 
-TEST_F(LlvmLibcExp10Test, DAZMode) {
-  ModifyMXCSR mxcsr(DAZ);
+  void test_underflow(double (*func)(double)) {
+    EXPECT_FP_EQ_WITH_EXCEPTION(zero, func(-0x1.0p20), FE_UNDERFLOW);
+    EXPECT_MATH_ERRNO(ERANGE);
+  }
 
-  EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::exp10(min_denormal));
-  EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::exp10(max_denormal));
-}
-
-TEST_F(LlvmLibcExp10Test, FTZDAZMode) {
-  ModifyMXCSR mxcsr(FTZ | DAZ);
-
-  EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::exp10(min_denormal));
-  EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::exp10(max_denormal));
-}
+#ifdef LIBC_TEST_FTZ_DAZ
+  void test_denormals(double (*func)(double)) {
+    EXPECT_FP_EQ(1.0, func(min_denormal));
+    EXPECT_FP_EQ(1.0, func(max_denormal));
+  }
+#endif // LIBC_TEST_FTZ_DAZ
+};
 
-#endif
+#ifdef LIBC_TEST_FTZ_DAZ
+#define LIST_EXP10_FTZ_DAZ_TESTS(suffix, func)                                 \
+  TEST_F(LlvmLibcExp10Test##suffix, FTZMode) {                                 \
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ);  \
+    test_denormals(&func);                                                     \
+  }                                                                            \
+  TEST_F(LlvmLibcExp10Test##suffix, DAZMode) {                                 \
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::DAZ);  \
+    test_denormals(&func);                                                     \
+  }                                                                            \
+  TEST_F(LlvmLibcExp10Test##suffix, FTZDAZMode) {                              \
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ |  \
+                                               LIBC_NAMESPACE::testing::DAZ);  \
+    test_denormals(&func);                                                     \
+  }
+#else // !LIBC_TEST_FTZ_DAZ
+#define LIST_EXP10_FTZ_DAZ_TESTS(suffix, func)
+#endif // LIBC_TEST_FTZ_DAZ
+
+#define LIST_EXP10_TESTS(suffix, func, check_snan_invalid)                     \
+  using LlvmLibcExp10Test##suffix = Exp10Test;                                 \
+  TEST_F(LlvmLibcExp10Test##suffix, SpecialNumbers) {                          \
+    test_special_numbers(&func, check_snan_invalid);                           \
+  }                                                                            \
+  TEST_F(LlvmLibcExp10Test##suffix, Overflow) { test_overflow(&func); }        \
+  TEST_F(LlvmLibcExp10Test##suffix, Underflow) { test_underflow(&func); }      \
+  LIST_EXP10_FTZ_DAZ_TESTS(suffix, func)                                       \
+  static_assert(true, "Require semicolon.")
+
+LIST_EXP10_TESTS(Default, LIBC_NAMESPACE::exp10, /*check_snan_invalid=*/true);
+LIST_EXP10_TESTS(DoubleEval, exp10_double_eval, /*check_snan_invalid=*/false);
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 5f8fa7e58778af..80ddad9a601b51 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11181,29 +11181,35 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_exp10",
-    hdrs = ["src/__support/math/exp10.h"],
+    name = "__support_math_exp10_double_eval",
+    hdrs = ["src/__support/math/exp10_double_eval.h"],
     deps = [
         ":__support_common",
         ":__support_cpp_bit",
-        ":__support_cpp_optional",
         ":__support_fputil_double_double",
-        ":__support_fputil_dyadic_float",
-        ":__support_fputil_fenv_impl",
         ":__support_fputil_fp_bits",
+        ":__support_fputil_fp_bitwise",
         ":__support_fputil_multiply_add",
-        ":__support_fputil_nearest_integer",
-        ":__support_fputil_polyeval",
-        ":__support_fputil_rounding_mode",
-        ":__support_fputil_triple_double",
-        ":__support_integer_literals",
+        ":__support_macros_attributes",
         ":__support_macros_config",
         ":__support_macros_optimization",
-        ":__support_math_exp_constants",
+        ":__support_macros_properties_cpu_features",
+        ":__support_math_exp_double_utils",
         ":__support_math_exp_utils",
     ],
 )
 
+libc_support_library(
+    name = "__support_math_exp10",
+    hdrs = ["src/__support/math/exp10.h"],
+    deps = [
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_macros_optimization",
+        ":__support_math_exp10_double_eval",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_exp10f_utils",
     hdrs = ["src/__support/math/exp10f_utils.h"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
index 9460f690487f3b..c8f77b54073ed6 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
@@ -266,7 +266,13 @@ math_mpfr_test(
     ],
 )
 
-math_mpfr_test(name = "exp10")
+math_mpfr_test(
+    name = "exp10",
+    deps = [
+        "//libc:__support_macros_attributes",
+        "//libc:__support_math_exp10_double_eval",
+    ],
+)
 
 math_mpfr_test(
     name = "exp10f",
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 912d8a1cdb7501..216bf5f22a4210 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -583,7 +583,13 @@ math_test(
     ],
 )
 
-math_test(name = "exp10")
+math_test(
+    name = "exp10",
+    deps = [
+        "//libc:__support_macros_attributes",
+        "//libc:__support_math_exp10_double_eval",
+    ],
+)
 
 math_test(
     name = "exp10f",



More information about the libc-commits mailing list