[libc] [llvm] [libc][math][c23] Add rsqrtf() function (PR #159615)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 11:53:54 PDT 2025


================
@@ -0,0 +1,71 @@
+//===-- Implementation header for rsqrtf ----------------------*- C++ -*-===//
+//
+// 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_RSQRTF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RSQRTF_H
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE static constexpr float rsqrtf(float x) {
+  using FPBits = fputil::FPBits<float>;
+  FPBits xbits(x);
+
+  uint32_t x_u = xbits.uintval();
+  uint32_t x_abs = x_u & 0x7fff'ffffU;
+
+  constexpr uint32_t INF_BIT = FPBits::inf().uintval();
----------------
overmighty wrote:

Nit: should be `INF_BITS` or `INF_U`.

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


More information about the llvm-commits mailing list