[libc-commits] [libc] [llvm] [libc][math] Refactor tanhf16 implementation to header-only in src/__support/math folder. (PR #178645)

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Mon Feb 9 06:39:46 PST 2026


================
@@ -0,0 +1,163 @@
+//===-- Single-precision tanhf16 function --------------------------------===//
+//
+// 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_TANHF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TANHF16_H
+
+#include "hdr/fenv_macros.h"
+#include "src/__support/CPP/array.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/FPUtil/nearest_integer.h"
+#include "src/__support/FPUtil/rounding_mode.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/math/expxf16_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace tanhf16_internal {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+LIBC_INLINE_VAR constexpr fputil::ExceptValues<float16, 2> TANHF16_EXCEPTS = {{
+    // x = 0x1.f54p+0, tanhf16(x) = 0x1.ecp-1 (RZ)
+    {0x3fd5U, 0x3bb0U, 1U, 0U, 0U},
+    // x = -0x1.f54p+0, tanhf16(x) = -0x1.ecp-1 (RZ)
+    {0xbfd5U, 0xbbb0U, 0U, 1U, 0U},
+}};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+} // namespace tanhf16_internal
----------------
bassiounix wrote:

can be local variable instead of global variable inside `tanhf16`

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


More information about the libc-commits mailing list