[libc-commits] [libc] [libc][math][c++23] Add log2bf16 math function (PR #177275)

via libc-commits libc-commits at lists.llvm.org
Fri Jul 3 08:35:41 PDT 2026


================
@@ -0,0 +1,127 @@
+//===-- BFloat16 log2(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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG2BF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG2BF16_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+// Generated by Sollya with the following commands:
+//   > display = hexadecimal;
+//   > for i from 0 to 127 do print(round(log2(1 + i * 2^-7), SG, RN));
+LIBC_INLINE constexpr float LOG2F_1_PLUS_M[128] = {
----------------
lntue wrote:

put inside `log2bf16_internal` namespace and use `LIBC_INLINE_VAR` instead.

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


More information about the libc-commits mailing list