[libc-commits] [libc] [libc][math] Adds rsqrtbf16 higher math function for bfloat16 type (PR #235422)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 21 09:43:57 PST 2026
================
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// This file contains the implementation of rsqrtbf16.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RSQRTBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RSQRTBF16_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE bfloat16 rsqrtbf16(bfloat16 x) {
+
+ float xf = fputil::cast<float>(x);
+ return fputil::cast<bfloat16>(1.0f / fputil::sqrt<float>(xf));
----------------
lntue wrote:
You'll need to deal with exceptional cases before performing computations, similar to `rsqrtf`: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/math/rsqrtf.h
https://github.com/llvm/llvm-project/pull/235422
More information about the libc-commits
mailing list