[libc-commits] [libc] [libc][math] Integer-only, statically rounded implementation of exp (PR #225803)

Hoàng Minh Thiên via libc-commits libc-commits at lists.llvm.org
Fri Nov 13 06:46:34 PST 2026


================
@@ -0,0 +1,250 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Shared utilities and constants for integer-only double-precision exponential
+/// functions.
+///
+//===----------------------------------------------------------------------===//
+//
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/frac128.h"
+#include "src/__support/frac64.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/types.h"
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP_INTEGER_UTILS_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP_INTEGER_UTILS_H
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+namespace static_rounding {
+
+// All constants below are generated via Sollya
+
+// > display = hexadecimal;
+// > print(2+round(1/log(2), 128, RN));
+// LSB(LOG2_E_F128) = 2^-127
+LIBC_INLINE_VAR constexpr Frac128 LOG2_E_F128 =
+    Frac128({0xbe87'fed0'691d'3e89, 0xb8aa'3b29'5c17'f0bb});
+
+// 2^x for x from 0 to (0b1111/2^4) = 15/16
+// > for i from 0 to 15 do {
+//   print(1+round(2^(i/16), 128, RN));
+// };
+// LSB(EXP_MID4[i]) = 2^-127
+LIBC_INLINE_VAR constexpr Frac128 EXP_MID[] = {
----------------
hmthien050209 wrote:

I've separated the upper bits into a separate LUT `EXP_MID_64` for non-accurate-pass usage.

https://github.com/llvm/llvm-project/pull/225803


More information about the libc-commits mailing list