[libc-commits] [libc] [libc][math][c23] Add asinhf16() function (PR #131351)

via libc-commits libc-commits at lists.llvm.org
Sun Mar 16 14:33:33 PDT 2025


================
@@ -0,0 +1,84 @@
+//===-- Half-precision asinhf16(x) 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.
+//
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/asinhf16.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/generic/sqrt.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/math/generic/explogxf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+static constexpr size_t N_EXCEPTS = 8;
+
+static constexpr fputil::ExceptValues<float16, N_EXCEPTS> ASINHF16_EXCEPTS{
+    {// (input, RZ output, RU offset, RD offset, RN offset)
+     {0x3769, 0x372A, 1, 0, 1},
+     {0x3B5B, 0x3A96, 1, 0, 0},
+     {0x4B1F, 0x42B3, 1, 0, 0},
+     {0x4C9B, 0x4336, 1, 0, 1},
+     {0xB769, 0xB72A, 0, 1, 1},
+     {0xBB5B, 0xBA96, 0, 1, 0},
+     {0xCB1F, 0xC2B3, 0, 1, 0},
+     {0xCC9B, 0xC336, 0, 1, 1}}};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+LLVM_LIBC_FUNCTION(float16, asinhf16, (float16 x)) {
+  using FPBits = fputil::FPBits<float16>;
+  FPBits xbits(x);
+
+  float x_d = x;
+  uint16_t x_u = xbits.uintval();
+  uint16_t x_abs = x_u & 0x7fff;
+
+  if (LIBC_UNLIKELY(xbits.is_inf_or_nan())) {
+    if (xbits.is_signaling_nan()) {
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
+    }
+
+    return x;
+  }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
----------------
overmighty wrote:

That's not what this macro is for, as far as I know.

```suggestion
```

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


More information about the libc-commits mailing list