[libc-commits] [libc] [libc][math][c23] Add exp10f16 C23 math function (PR #101588)

via libc-commits libc-commits at lists.llvm.org
Thu Aug 1 17:13:38 PDT 2024


================
@@ -0,0 +1,134 @@
+//===-- Half-precision 2^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/exp2f16.h"
+#include "hdr/errno_macros.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/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"
+
+namespace LIBC_NAMESPACE_DECL {
+
+static constexpr fputil::ExceptValues<float16, 3> EXP2F16_EXCEPTS = {{
+    // (input, RZ output, RU offset, RD offset, RN offset)
+    // x = 0x1.714p-11, exp2f16(x) = 0x1p+0 (RZ)
+    {0x11c5U, 0x3c00U, 1U, 0U, 1U},
+    // x = -0x1.558p-4, exp2f16(x) = 0x1.e34p-1 (RZ)
+    {0xad56U, 0x3b8dU, 1U, 0U, 0U},
+    // x = -0x1.d5cp-4, exp2f16(x) = 0x1.d8cp-1 (RZ)
+    {0xaf57U, 0x3b63U, 1U, 0U, 0U},
+}};
+
+// Generated by Sollya with the following commands:
+//   > display = hexadecimal;
+//   > for i from 0 to 7 do printsingle(round(2^(i * 2^-3), SG, RN));
+static constexpr cpp::array<uint32_t, 8> EXP2_MID_BITS = {
+    0x3f80'0000U, 0x3f8b'95c2U, 0x3f98'37f0U, 0x3fa5'fed7U,
+    0x3fb5'04f3U, 0x3fc5'672aU, 0x3fd7'44fdU, 0x3fea'c0c7U,
+};
----------------
overmighty wrote:

Copy-pasted from exp2f16.cpp. I guess I should create a shared expxf16.h header instead.

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


More information about the libc-commits mailing list