[libc-commits] [libc] [libc][stdfix] Implement sqrtfx for unsigned long accum (PR #214741)
via libc-commits
libc-commits at lists.llvm.org
Fri Nov 20 03:07:30 PST 2026
https://github.com/sohail103 updated https://github.com/llvm/llvm-project/pull/214741
>From 7cf333c56261173aaf1a9138581d514f013bf82c Mon Sep 17 00:00:00 2001
From: sohail103 <sohailraj.satapathy at gmail.com>
Date: Fri, 7 Aug 2026 19:17:34 +0530
Subject: [PATCH 1/4] [libc][stdfix] Implement sqrtfx for remaining fixed point
types
---
libc/config/baremetal/arm/entrypoints.txt | 12 +-
libc/config/baremetal/riscv/entrypoints.txt | 12 +-
libc/config/linux/riscv/entrypoints.txt | 12 +-
libc/config/linux/x86_64/entrypoints.txt | 12 +-
libc/include/stdfix.yaml | 69 +++++++++--
libc/src/__support/fixed_point/CMakeLists.txt | 1 +
libc/src/__support/fixed_point/sqrt.h | 116 +++++++++++++-----
libc/src/stdfix/CMakeLists.txt | 2 +-
libc/src/stdfix/sqrthk.cpp | 20 +++
libc/src/stdfix/sqrthk.h | 21 ++++
libc/src/stdfix/sqrthr.cpp | 20 +++
libc/src/stdfix/sqrthr.h | 21 ++++
libc/src/stdfix/sqrtk.cpp | 20 +++
libc/src/stdfix/sqrtk.h | 21 ++++
libc/src/stdfix/sqrtlk.cpp | 20 +++
libc/src/stdfix/sqrtlk.h | 21 ++++
libc/src/stdfix/sqrtlr.cpp | 20 +++
libc/src/stdfix/sqrtlr.h | 21 ++++
libc/src/stdfix/sqrtr.cpp | 20 +++
libc/src/stdfix/sqrtr.h | 21 ++++
libc/src/stdfix/sqrtulk.cpp | 20 +++
libc/src/stdfix/sqrtulk.h | 21 ++++
libc/test/src/stdfix/CMakeLists.txt | 2 +-
libc/test/src/stdfix/SqrtTest.h | 74 +++++++----
libc/test/src/stdfix/sqrthk_test.cpp | 13 ++
libc/test/src/stdfix/sqrthr_test.cpp | 13 ++
libc/test/src/stdfix/sqrtk_test.cpp | 13 ++
libc/test/src/stdfix/sqrtlk_test.cpp | 13 ++
libc/test/src/stdfix/sqrtlr_test.cpp | 13 ++
libc/test/src/stdfix/sqrtr_test.cpp | 13 ++
libc/test/src/stdfix/sqrtuhk_test.cpp | 3 +-
libc/test/src/stdfix/sqrtuhr_test.cpp | 3 +-
libc/test/src/stdfix/sqrtuk_test.cpp | 2 +-
libc/test/src/stdfix/sqrtulk_test.cpp | 14 +++
libc/test/src/stdfix/sqrtulr_test.cpp | 3 +-
libc/test/src/stdfix/sqrtur_test.cpp | 2 +-
36 files changed, 619 insertions(+), 85 deletions(-)
create mode 100644 libc/src/stdfix/sqrthk.cpp
create mode 100644 libc/src/stdfix/sqrthk.h
create mode 100644 libc/src/stdfix/sqrthr.cpp
create mode 100644 libc/src/stdfix/sqrthr.h
create mode 100644 libc/src/stdfix/sqrtk.cpp
create mode 100644 libc/src/stdfix/sqrtk.h
create mode 100644 libc/src/stdfix/sqrtlk.cpp
create mode 100644 libc/src/stdfix/sqrtlk.h
create mode 100644 libc/src/stdfix/sqrtlr.cpp
create mode 100644 libc/src/stdfix/sqrtlr.h
create mode 100644 libc/src/stdfix/sqrtr.cpp
create mode 100644 libc/src/stdfix/sqrtr.h
create mode 100644 libc/src/stdfix/sqrtulk.cpp
create mode 100644 libc/src/stdfix/sqrtulk.h
create mode 100644 libc/test/src/stdfix/sqrthk_test.cpp
create mode 100644 libc/test/src/stdfix/sqrthr_test.cpp
create mode 100644 libc/test/src/stdfix/sqrtk_test.cpp
create mode 100644 libc/test/src/stdfix/sqrtlk_test.cpp
create mode 100644 libc/test/src/stdfix/sqrtlr_test.cpp
create mode 100644 libc/test/src/stdfix/sqrtr_test.cpp
create mode 100644 libc/test/src/stdfix/sqrtulk_test.cpp
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ed7b683676be19..e42041d19e95ee 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -960,12 +960,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.roundulk
libc.src.stdfix.roundulr
libc.src.stdfix.roundur
- libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuhr
- libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtur
- # libc.src.stdfix.sqrtulk
libc.src.stdfix.sqrtulr
+ libc.src.stdfix.sqrtuhk
+ libc.src.stdfix.sqrtuk
+ libc.src.stdfix.sqrtulk
+ libc.src.stdfix.sqrthr
+ libc.src.stdfix.sqrtr
+ libc.src.stdfix.sqrtlr
+ libc.src.stdfix.sqrthk
+ libc.src.stdfix.sqrtk
+ libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index e2de9fb04985b7..e622e0bc856c29 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -952,12 +952,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.roundulk
libc.src.stdfix.roundulr
libc.src.stdfix.roundur
- libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuhr
- libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtur
- # libc.src.stdfix.sqrtulk
libc.src.stdfix.sqrtulr
+ libc.src.stdfix.sqrtuhk
+ libc.src.stdfix.sqrtuk
+ libc.src.stdfix.sqrtulk
+ libc.src.stdfix.sqrthr
+ libc.src.stdfix.sqrtr
+ libc.src.stdfix.sqrtlr
+ libc.src.stdfix.sqrthk
+ libc.src.stdfix.sqrtk
+ libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index be15b84a24d7b3..c1c43649c64116 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1333,12 +1333,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.roundulk
libc.src.stdfix.roundulr
libc.src.stdfix.roundur
- libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuhr
- libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtur
- # libc.src.stdfix.sqrtulk
libc.src.stdfix.sqrtulr
+ libc.src.stdfix.sqrtuhk
+ libc.src.stdfix.sqrtuk
+ libc.src.stdfix.sqrtulk
+ libc.src.stdfix.sqrthr
+ libc.src.stdfix.sqrtr
+ libc.src.stdfix.sqrtlr
+ libc.src.stdfix.sqrthk
+ libc.src.stdfix.sqrtk
+ libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 4b7891ccb16911..1f2b7ae6b8b1be 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1333,12 +1333,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.roundulk
libc.src.stdfix.roundulr
libc.src.stdfix.roundur
- libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuhr
- libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtur
- # libc.src.stdfix.sqrtulk
libc.src.stdfix.sqrtulr
+ libc.src.stdfix.sqrtuhk
+ libc.src.stdfix.sqrtuk
+ libc.src.stdfix.sqrtulk
+ libc.src.stdfix.sqrthr
+ libc.src.stdfix.sqrtr
+ libc.src.stdfix.sqrtlr
+ libc.src.stdfix.sqrthk
+ libc.src.stdfix.sqrtk
+ libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index 985c6e25e90965..2be63d3ea22b6e 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -426,21 +426,37 @@ functions:
- type: unsigned fract
- type: int
guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtuhk
+ - name: sqrtuhr
standards:
- stdc_ext
- llvm_libc_stdfix_ext
- return_type: unsigned short accum
+ return_type: unsigned short fract
arguments:
- - type: unsigned short accum
+ - type: unsigned short fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtuhr
+ - name: sqrtur
standards:
- stdc_ext
- llvm_libc_stdfix_ext
- return_type: unsigned short fract
+ return_type: unsigned fract
arguments:
- - type: unsigned short fract
+ - type: unsigned fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: sqrtulr
+ standards:
+ - stdc_ext
+ - llvm_libc_stdfix_ext
+ return_type: unsigned long fract
+ arguments:
+ - type: unsigned long fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: sqrtuhk
+ standards:
+ - stdc_ext
+ - llvm_libc_stdfix_ext
+ return_type: unsigned short accum
+ arguments:
+ - type: unsigned short accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: sqrtuk
standards:
@@ -452,12 +468,29 @@ functions:
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: sqrtulk
standards:
+ - stdc_ext
- llvm_libc_stdfix_ext
return_type: unsigned long accum
arguments:
- type: unsigned long accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtulr
+ - name: sqrthr
+ standards:
+ - stdc_ext
+ - llvm_libc_stdfix_ext
+ return_type: unsigned short fract
+ arguments:
+ - type: short fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: sqrtr
+ standards:
+ - stdc_ext
+ - llvm_libc_stdfix_ext
+ return_type: unsigned fract
+ arguments:
+ - type: fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: sqrtlr
standards:
- stdc_ext
- llvm_libc_stdfix_ext
@@ -465,13 +498,29 @@ functions:
arguments:
- type: unsigned long fract
guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtur
+ - name: sqrthk
standards:
- stdc_ext
- llvm_libc_stdfix_ext
- return_type: unsigned fract
+ return_type: unsigned short accum
arguments:
- - type: unsigned fract
+ - type: short accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: sqrtk
+ standards:
+ - stdc_ext
+ - llvm_libc_stdfix_ext
+ return_type: unsigned accum
+ arguments:
+ - type: accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: sqrtlk
+ standards:
+ - stdc_ext
+ - llvm_libc_stdfix_ext
+ return_type: unsigned long accum
+ arguments:
+ - type: long accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: uhksqrtus
standards:
diff --git a/libc/src/__support/fixed_point/CMakeLists.txt b/libc/src/__support/fixed_point/CMakeLists.txt
index 195f2add7c670c..56e1ccc61a3c4c 100644
--- a/libc/src/__support/fixed_point/CMakeLists.txt
+++ b/libc/src/__support/fixed_point/CMakeLists.txt
@@ -42,4 +42,5 @@ add_header_library(
libc.src.__support.macros.attributes
libc.src.__support.macros.config
libc.src.__support.macros.optimization
+ libc.src.__support.uint128
)
diff --git a/libc/src/__support/fixed_point/sqrt.h b/libc/src/__support/fixed_point/sqrt.h
index f2476108241778..22c6f4ba22add7 100644
--- a/libc/src/__support/fixed_point/sqrt.h
+++ b/libc/src/__support/fixed_point/sqrt.h
@@ -13,11 +13,14 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/limits.h" // CHAR_BIT
#include "src/__support/CPP/type_traits.h"
-#include "src/__support/fixed_point/fx_rep.h"
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
+#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h" // LIBC_CRASH_ON_VALUE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "fx_rep.h"
+#include "src/__support/uint128.h"
+
#ifdef LIBC_COMPILER_HAS_FIXED_POINT
namespace LIBC_NAMESPACE_DECL {
@@ -130,8 +133,25 @@ template <> struct SqrtConfig<unsigned int> {
using HalfType = unsigned short;
};
-// TODO: unsigned long accum type is 64-bit, and will need 64-bit fract type.
-// Probably we will use DyadicFloat<64> for intermediate computations instead.
+template <typename T> struct FXUnsigned;
+template <> struct FXUnsigned<short fract> {
+ using Type = unsigned short fract;
+};
+template <> struct FXUnsigned<fract> {
+ using Type = unsigned fract;
+};
+template <> struct FXUnsigned<long fract> {
+ using Type = unsigned long fract;
+};
+template <> struct FXUnsigned<short accum> {
+ using Type = unsigned short accum;
+};
+template <> struct FXUnsigned<accum> {
+ using Type = unsigned accum;
+};
+template <> struct FXUnsigned<long accum> {
+ using Type = unsigned long accum;
+};
} // namespace internal
@@ -146,7 +166,7 @@ sqrt_core(typename Config::Type x_frac) {
if (x_frac == FXRep::ONE_FOURTH())
return FXRep::ONE_HALF();
- // Use use Newton method to approximate sqrt(a):
+ // Use Newton method to approximate sqrt(a):
// x_{n + 1} = 1/2 (x_n + a / x_n)
// For the initial values, we choose x_0
@@ -180,31 +200,67 @@ sqrt_core(typename Config::Type x_frac) {
template <typename T>
LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, T> sqrt(T x) {
- using BitType = typename FXRep<T>::StorageType;
- BitType x_bit = cpp::bit_cast<BitType>(x);
-
- if (LIBC_UNLIKELY(x_bit == 0))
- return FXRep<T>::ZERO();
-
- int leading_zeros = cpp::countl_zero(x_bit);
- constexpr int STORAGE_LENGTH = sizeof(BitType) * CHAR_BIT;
- constexpr int EXP_ADJUSTMENT = STORAGE_LENGTH - FXRep<T>::FRACTION_LEN - 1;
- // x_exp is the real exponent of the leading bit of x.
- int x_exp = EXP_ADJUSTMENT - leading_zeros;
- int shift = EXP_ADJUSTMENT - 1 - (x_exp & (~1));
- // Normalize.
- x_bit <<= shift;
- using FracType = typename internal::SqrtConfig<T>::Type;
- FracType x_frac = cpp::bit_cast<FracType>(x_bit);
-
- // Compute sqrt(x_frac) using Newton-method.
- FracType r = sqrt_core<internal::SqrtConfig<T>>(x_frac);
-
- // Re-scaling
- r >>= EXP_ADJUSTMENT - (x_exp >> 1);
-
- // Return result.
- return cpp::bit_cast<T>(r);
+ if constexpr (FXRep<T>::SIGN_LEN > 0) {
+ LIBC_CRASH_ON_VALUE(x < FXRep<T>::ZERO(), true);
+ return static_cast<T>(
+ sqrt(static_cast<typename internal::FXUnsigned<T>::Type>(x)));
+ } else {
+ using BitType = typename FXRep<T>::StorageType;
+ BitType x_bit = cpp::bit_cast<BitType>(x);
+
+ if (LIBC_UNLIKELY(x_bit == 0))
+ return FXRep<T>::ZERO();
+
+ int leading_zeros = cpp::countl_zero(x_bit);
+ constexpr int STORAGE_LENGTH = sizeof(BitType) * CHAR_BIT;
+ constexpr int EXP_ADJUSTMENT = STORAGE_LENGTH - FXRep<T>::FRACTION_LEN - 1;
+ // x_exp is the real exponent of the leading bit of x.
+ int x_exp = EXP_ADJUSTMENT - leading_zeros;
+ int shift = EXP_ADJUSTMENT - 1 - (x_exp & (~1));
+ // Normalize.
+ x_bit <<= shift;
+
+ if constexpr (STORAGE_LENGTH > 32) {
+ using SeedConfig = internal::SqrtConfig<unsigned long fract>;
+ using SeedType = SeedConfig::Type;
+ using SeedStorageType = typename FXRep<SeedType>::StorageType;
+ constexpr int SEED_LENGTH = sizeof(SeedStorageType) * CHAR_BIT;
+
+ static_assert(STORAGE_LENGTH <= 2 * SEED_LENGTH,
+ "Output storage type has to be lesser than or equal to "
+ "double the seed table's width for accurate results.");
+
+ // Seed from the widest available table using the top half of x, then
+ // widen to full precision. No native fract type exists at this storage
+ // width to build a table for directly.
+ SeedStorageType x_top_half =
+ static_cast<SeedStorageType>(x_bit >> SEED_LENGTH);
+ SeedType x_seed = cpp::bit_cast<SeedType>(x_top_half);
+ SeedType r_seed = sqrt_core<SeedConfig>(x_seed);
+
+ UInt128 r0 = static_cast<UInt128>(cpp::bit_cast<SeedStorageType>(r_seed))
+ << SEED_LENGTH;
+
+ UInt128 x_wide = static_cast<UInt128>(x_bit) << STORAGE_LENGTH;
+ UInt128 r1 = (r0 + x_wide / r0) >> 1;
+
+ r1 >>= EXP_ADJUSTMENT - (x_exp >> 1);
+ BitType r_bits = static_cast<BitType>(r1);
+ return cpp::bit_cast<T>(r_bits);
+ } else {
+ using FracType = typename internal::SqrtConfig<T>::Type;
+ FracType x_frac = cpp::bit_cast<FracType>(x_bit);
+
+ // Compute sqrt(x_frac) using Newton-method.
+ FracType r = sqrt_core<internal::SqrtConfig<T>>(x_frac);
+
+ // Re-scaling
+ r >>= EXP_ADJUSTMENT - (x_exp >> 1);
+
+ // Return result.
+ return cpp::bit_cast<T>(r);
+ }
+ }
}
// Integer square root - Accurate version:
diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index 0745599015f7f6..5a4606db899e57 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -14,7 +14,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
)
endforeach()
-foreach(suffix IN ITEMS uhr ur ulr uhk uk)
+foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
add_entrypoint_object(
sqrt${suffix}
HDRS
diff --git a/libc/src/stdfix/sqrthk.cpp b/libc/src/stdfix/sqrthk.cpp
new file mode 100644
index 00000000000000..200e2942131e2c
--- /dev/null
+++ b/libc/src/stdfix/sqrthk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrthk 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 "sqrthk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned short accum, sqrthk, (short accum x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrthk.h b/libc/src/stdfix/sqrthk.h
new file mode 100644
index 00000000000000..2924104c57e0ab
--- /dev/null
+++ b/libc/src/stdfix/sqrthk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrthk ------------------------*- 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_STDFIX_SQRTHK_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTHK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned short accum sqrthk(short accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTHK_H
diff --git a/libc/src/stdfix/sqrthr.cpp b/libc/src/stdfix/sqrthr.cpp
new file mode 100644
index 00000000000000..e3eb0904fb5f00
--- /dev/null
+++ b/libc/src/stdfix/sqrthr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrthr 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 "sqrthr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned short fract, sqrthr, (short fract x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrthr.h b/libc/src/stdfix/sqrthr.h
new file mode 100644
index 00000000000000..352ca1d405af39
--- /dev/null
+++ b/libc/src/stdfix/sqrthr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrthr ------------------------*- 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_STDFIX_SQRTHR_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTHR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned short fract sqrthr(short fract x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTHR_H
diff --git a/libc/src/stdfix/sqrtk.cpp b/libc/src/stdfix/sqrtk.cpp
new file mode 100644
index 00000000000000..66c17a37c264d1
--- /dev/null
+++ b/libc/src/stdfix/sqrtk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrtk 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 "sqrtk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned accum, sqrtk, (accum x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtk.h b/libc/src/stdfix/sqrtk.h
new file mode 100644
index 00000000000000..f01e4a5da9ad04
--- /dev/null
+++ b/libc/src/stdfix/sqrtk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrtk -------------------------*- 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_STDFIX_SQRTK_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned accum sqrtk(accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTK_H
diff --git a/libc/src/stdfix/sqrtlk.cpp b/libc/src/stdfix/sqrtlk.cpp
new file mode 100644
index 00000000000000..a4c6bf1419157d
--- /dev/null
+++ b/libc/src/stdfix/sqrtlk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrtlk 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 "sqrtlk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned long accum, sqrtlk, (long accum x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtlk.h b/libc/src/stdfix/sqrtlk.h
new file mode 100644
index 00000000000000..a93d4aa090879d
--- /dev/null
+++ b/libc/src/stdfix/sqrtlk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrtlk ------------------------*- 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_STDFIX_SQRTLK_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTLK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned long accum sqrtlk(long accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTLK_H
diff --git a/libc/src/stdfix/sqrtlr.cpp b/libc/src/stdfix/sqrtlr.cpp
new file mode 100644
index 00000000000000..e9b3317b9bea19
--- /dev/null
+++ b/libc/src/stdfix/sqrtlr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrtlr 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 "sqrtlr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned long fract, sqrtlr, (long fract x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtlr.h b/libc/src/stdfix/sqrtlr.h
new file mode 100644
index 00000000000000..09df5f34da5377
--- /dev/null
+++ b/libc/src/stdfix/sqrtlr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrtlr ------------------------*- 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_STDFIX_SQRTLR_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTLR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned long fract sqrtlr(long fract x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTLR_H
diff --git a/libc/src/stdfix/sqrtr.cpp b/libc/src/stdfix/sqrtr.cpp
new file mode 100644
index 00000000000000..3f2c316c9aae05
--- /dev/null
+++ b/libc/src/stdfix/sqrtr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrtr 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 "sqrtr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned fract, sqrtr, (fract x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtr.h b/libc/src/stdfix/sqrtr.h
new file mode 100644
index 00000000000000..fdc7f37a410afa
--- /dev/null
+++ b/libc/src/stdfix/sqrtr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrtr -------------------------*- 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_STDFIX_SQRTR_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned fract sqrtr(fract x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTR_H
diff --git a/libc/src/stdfix/sqrtulk.cpp b/libc/src/stdfix/sqrtulk.cpp
new file mode 100644
index 00000000000000..0572f2aafd5678
--- /dev/null
+++ b/libc/src/stdfix/sqrtulk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of sqrtulk 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 "sqrtulk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned long accum, sqrtulk, (unsigned long accum x)) {
+ return fixed_point::sqrt(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtulk.h b/libc/src/stdfix/sqrtulk.h
new file mode 100644
index 00000000000000..f5c15f8dc5555e
--- /dev/null
+++ b/libc/src/stdfix/sqrtulk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrtulk -----------------------*- 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_STDFIX_SQRTULK_H
+#define LLVM_LIBC_SRC_STDFIX_SQRTULK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned long accum sqrtulk(unsigned long accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_SQRTULK_H
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index 8f1f0e9ea0746a..88f8b1dc5011c9 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -19,7 +19,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
)
endforeach()
-foreach(suffix IN ITEMS uhr ur ulr uhk uk)
+foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
add_libc_test(
sqrt${suffix}_test
SUITE
diff --git a/libc/test/src/stdfix/SqrtTest.h b/libc/test/src/stdfix/SqrtTest.h
index 7b362d34354623..dcbdef7b117167 100644
--- a/libc/test/src/stdfix/SqrtTest.h
+++ b/libc/test/src/stdfix/SqrtTest.h
@@ -21,55 +21,77 @@
#include "src/__support/FPUtil/sqrt.h"
#include "src/__support/fixed_point/fx_rep.h"
-template <typename T> class SqrtTest : public LIBC_NAMESPACE::testing::Test {
+template <typename ReturnType, typename FXType>
+class SqrtTest : public LIBC_NAMESPACE::testing::Test {
- using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>;
- static constexpr T zero = FXRep::ZERO();
- static constexpr T min = FXRep::MIN();
- static constexpr T max = FXRep::MAX();
- static constexpr T half = static_cast<T>(0.5);
- static constexpr T quarter = static_cast<T>(0.25);
- static constexpr T one =
- (FXRep::INTEGRAL_LEN > 0) ? static_cast<T>(1) : FXRep::MAX();
- static constexpr T eps = FXRep::EPS();
+ using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<FXType>;
+ using OutRep = LIBC_NAMESPACE::fixed_point::FXRep<ReturnType>;
+
+ static constexpr ReturnType zero = OutRep::ZERO();
+ static constexpr ReturnType max = OutRep::MAX();
+ static constexpr ReturnType half = static_cast<ReturnType>(0.5);
+ static constexpr ReturnType quarter = static_cast<ReturnType>(0.25);
+ static constexpr ReturnType one =
+ (OutRep::INTEGRAL_LEN > 0) ? static_cast<ReturnType>(1) : OutRep::MAX();
+ static constexpr ReturnType eps = OutRep::EPS();
+ static constexpr FXType in_max = FXRep::MAX();
+ static constexpr FXType in_eps = FXRep::EPS();
public:
- typedef T (*SqrtFunc)(T);
+ typedef ReturnType (*SqrtFunc)(FXType);
void testSpecialNumbers(SqrtFunc func) {
- EXPECT_EQ(zero, func(zero));
- EXPECT_EQ(half, func(quarter));
+ EXPECT_EQ(zero, func(static_cast<FXType>(zero)));
+ EXPECT_EQ(half, func(static_cast<FXType>(quarter)));
- if constexpr (FXRep::INTEGRAL_LEN) {
- EXPECT_EQ(one, func(one));
- EXPECT_EQ(static_cast<T>(2.0), func(static_cast<T>(4.0)));
+ if constexpr (OutRep::INTEGRAL_LEN > 0) {
+ EXPECT_EQ(one, func(static_cast<FXType>(one)));
+ EXPECT_EQ(static_cast<ReturnType>(2.0), func(static_cast<FXType>(4.0)));
}
- using StorageType = typename FXRep::StorageType;
+ constexpr double ERR = 3.0 * static_cast<double>(eps);
+ double eps_v_d = static_cast<double>(in_eps);
+ double eps_error = LIBC_NAMESPACE::fputil::abs(
+ static_cast<double>(func(in_eps)) -
+ LIBC_NAMESPACE::fputil::sqrt<double>(eps_v_d));
+ ASSERT_TRUE(eps_error <= ERR);
+
+ using InputStorageType = typename FXRep::StorageType;
constexpr size_t COUNT = 255;
- constexpr StorageType STEP =
- StorageType(~StorageType(0)) / static_cast<StorageType>(COUNT);
- constexpr double ERR = 3.0 * static_cast<double>(eps);
- StorageType x = 0;
- for (size_t i = 0; i < COUNT; ++i, x += STEP) {
- T v = LIBC_NAMESPACE::cpp::bit_cast<T>(x);
+ constexpr InputStorageType MAX_MAGNITUDE =
+ (FXRep::SIGN_LEN > 0) ? static_cast<InputStorageType>(
+ InputStorageType(~InputStorageType(0)) >> 1)
+ : InputStorageType(~InputStorageType(0));
+ constexpr InputStorageType STEP =
+ (MAX_MAGNITUDE < COUNT)
+ ? 1
+ : MAX_MAGNITUDE / static_cast<InputStorageType>(COUNT);
+
+ InputStorageType x = 0;
+ for (size_t i = 0; i < COUNT && x <= MAX_MAGNITUDE; ++i, x += STEP) {
+ FXType v = LIBC_NAMESPACE::cpp::bit_cast<FXType>(x);
double v_d = static_cast<double>(v);
double errors = LIBC_NAMESPACE::fputil::abs(
static_cast<double>(func(v)) -
LIBC_NAMESPACE::fputil::sqrt<double>(v_d));
if (errors > ERR) {
// Print out the failure input and output.
- EXPECT_EQ(v, zero);
+ EXPECT_EQ(v, static_cast<FXType>(zero));
EXPECT_EQ(func(v), zero);
}
ASSERT_TRUE(errors <= ERR);
}
+ double v_d = static_cast<double>(in_max);
+ double error =
+ LIBC_NAMESPACE::fputil::abs(static_cast<double>(func(in_max)) -
+ LIBC_NAMESPACE::fputil::sqrt<double>(v_d));
+ ASSERT_TRUE(error <= ERR);
}
};
-#define LIST_SQRT_TESTS(T, func) \
- using LlvmLibcSqrtTest = SqrtTest<T>; \
+#define LIST_SQRT_TESTS(ReturnType, FXType, func) \
+ using LlvmLibcSqrtTest = SqrtTest<ReturnType, FXType>; \
TEST_F(LlvmLibcSqrtTest, SpecialNumbers) { testSpecialNumbers(&func); } \
static_assert(true, "Require semicolon.")
diff --git a/libc/test/src/stdfix/sqrthk_test.cpp b/libc/test/src/stdfix/sqrthk_test.cpp
new file mode 100644
index 00000000000000..31eda96c17aee7
--- /dev/null
+++ b/libc/test/src/stdfix/sqrthk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrthk ----------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrthk.h"
+
+LIST_SQRT_TESTS(unsigned short accum, short accum, LIBC_NAMESPACE::sqrthk);
diff --git a/libc/test/src/stdfix/sqrthr_test.cpp b/libc/test/src/stdfix/sqrthr_test.cpp
new file mode 100644
index 00000000000000..5c82a2183350a2
--- /dev/null
+++ b/libc/test/src/stdfix/sqrthr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrthr ----------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrthr.h"
+
+LIST_SQRT_TESTS(unsigned short fract, short fract, LIBC_NAMESPACE::sqrthr);
diff --git a/libc/test/src/stdfix/sqrtk_test.cpp b/libc/test/src/stdfix/sqrtk_test.cpp
new file mode 100644
index 00000000000000..dd4d0c2220eb6a
--- /dev/null
+++ b/libc/test/src/stdfix/sqrtk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrtk -----------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrtk.h"
+
+LIST_SQRT_TESTS(unsigned accum, accum, LIBC_NAMESPACE::sqrtk);
diff --git a/libc/test/src/stdfix/sqrtlk_test.cpp b/libc/test/src/stdfix/sqrtlk_test.cpp
new file mode 100644
index 00000000000000..ab3502d8a34461
--- /dev/null
+++ b/libc/test/src/stdfix/sqrtlk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrtlk ----------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrtlk.h"
+
+LIST_SQRT_TESTS(unsigned long accum, long accum, LIBC_NAMESPACE::sqrtlk);
diff --git a/libc/test/src/stdfix/sqrtlr_test.cpp b/libc/test/src/stdfix/sqrtlr_test.cpp
new file mode 100644
index 00000000000000..caa29c81efc77c
--- /dev/null
+++ b/libc/test/src/stdfix/sqrtlr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrtlr ----------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrtlr.h"
+
+LIST_SQRT_TESTS(unsigned long fract, long fract, LIBC_NAMESPACE::sqrtlr);
diff --git a/libc/test/src/stdfix/sqrtr_test.cpp b/libc/test/src/stdfix/sqrtr_test.cpp
new file mode 100644
index 00000000000000..7ad93f1d8769f1
--- /dev/null
+++ b/libc/test/src/stdfix/sqrtr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrtr -----------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrtr.h"
+
+LIST_SQRT_TESTS(unsigned fract, fract, LIBC_NAMESPACE::sqrtr);
diff --git a/libc/test/src/stdfix/sqrtuhk_test.cpp b/libc/test/src/stdfix/sqrtuhk_test.cpp
index 99b4f534b643e0..4a70cd46992d6d 100644
--- a/libc/test/src/stdfix/sqrtuhk_test.cpp
+++ b/libc/test/src/stdfix/sqrtuhk_test.cpp
@@ -10,4 +10,5 @@
#include "src/stdfix/sqrtuhk.h"
-LIST_SQRT_TESTS(unsigned short accum, LIBC_NAMESPACE::sqrtuhk);
+LIST_SQRT_TESTS(unsigned short accum, unsigned short accum,
+ LIBC_NAMESPACE::sqrtuhk);
diff --git a/libc/test/src/stdfix/sqrtuhr_test.cpp b/libc/test/src/stdfix/sqrtuhr_test.cpp
index cdd95020957444..732edc23044155 100644
--- a/libc/test/src/stdfix/sqrtuhr_test.cpp
+++ b/libc/test/src/stdfix/sqrtuhr_test.cpp
@@ -10,4 +10,5 @@
#include "src/stdfix/sqrtuhr.h"
-LIST_SQRT_TESTS(unsigned short fract, LIBC_NAMESPACE::sqrtuhr);
+LIST_SQRT_TESTS(unsigned short fract, unsigned short fract,
+ LIBC_NAMESPACE::sqrtuhr);
diff --git a/libc/test/src/stdfix/sqrtuk_test.cpp b/libc/test/src/stdfix/sqrtuk_test.cpp
index 5dc43b1313b0fb..3a54a990f097e0 100644
--- a/libc/test/src/stdfix/sqrtuk_test.cpp
+++ b/libc/test/src/stdfix/sqrtuk_test.cpp
@@ -10,4 +10,4 @@
#include "src/stdfix/sqrtuk.h"
-LIST_SQRT_TESTS(unsigned accum, LIBC_NAMESPACE::sqrtuk);
+LIST_SQRT_TESTS(unsigned accum, unsigned accum, LIBC_NAMESPACE::sqrtuk);
diff --git a/libc/test/src/stdfix/sqrtulk_test.cpp b/libc/test/src/stdfix/sqrtulk_test.cpp
new file mode 100644
index 00000000000000..90cfa0865eece7
--- /dev/null
+++ b/libc/test/src/stdfix/sqrtulk_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for sqrtulk ---------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/stdfix/sqrtulk.h"
+
+LIST_SQRT_TESTS(unsigned long accum, unsigned long accum,
+ LIBC_NAMESPACE::sqrtulk);
diff --git a/libc/test/src/stdfix/sqrtulr_test.cpp b/libc/test/src/stdfix/sqrtulr_test.cpp
index 5d9f7aa56211f3..ca05c7a6a7fbb4 100644
--- a/libc/test/src/stdfix/sqrtulr_test.cpp
+++ b/libc/test/src/stdfix/sqrtulr_test.cpp
@@ -10,4 +10,5 @@
#include "src/stdfix/sqrtulr.h"
-LIST_SQRT_TESTS(unsigned long fract, LIBC_NAMESPACE::sqrtulr);
+LIST_SQRT_TESTS(unsigned long fract, unsigned long fract,
+ LIBC_NAMESPACE::sqrtulr);
diff --git a/libc/test/src/stdfix/sqrtur_test.cpp b/libc/test/src/stdfix/sqrtur_test.cpp
index f7e1cdef7fc356..d0fc0f0a702637 100644
--- a/libc/test/src/stdfix/sqrtur_test.cpp
+++ b/libc/test/src/stdfix/sqrtur_test.cpp
@@ -10,4 +10,4 @@
#include "src/stdfix/sqrtur.h"
-LIST_SQRT_TESTS(unsigned fract, LIBC_NAMESPACE::sqrtur);
+LIST_SQRT_TESTS(unsigned fract, unsigned fract, LIBC_NAMESPACE::sqrtur);
>From e96612a2b037c80d3f924713881a7b60cb0dc233 Mon Sep 17 00:00:00 2001
From: sohail103 <sohailraj.satapathy at gmail.com>
Date: Tue, 25 Aug 2026 18:16:52 +0530
Subject: [PATCH 2/4] [libc][stdfix] remove redundant casts and use predefined
constants in sqrtfx tests
---
libc/src/__support/fixed_point/sqrt.h | 2 --
libc/test/src/stdfix/SqrtTest.h | 12 ++++++------
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/libc/src/__support/fixed_point/sqrt.h b/libc/src/__support/fixed_point/sqrt.h
index 22c6f4ba22add7..659884e2441cd3 100644
--- a/libc/src/__support/fixed_point/sqrt.h
+++ b/libc/src/__support/fixed_point/sqrt.h
@@ -15,7 +15,6 @@
#include "src/__support/CPP/type_traits.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h"
-#include "src/__support/macros/null_check.h" // LIBC_CRASH_ON_VALUE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "fx_rep.h"
@@ -201,7 +200,6 @@ sqrt_core(typename Config::Type x_frac) {
template <typename T>
LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, T> sqrt(T x) {
if constexpr (FXRep<T>::SIGN_LEN > 0) {
- LIBC_CRASH_ON_VALUE(x < FXRep<T>::ZERO(), true);
return static_cast<T>(
sqrt(static_cast<typename internal::FXUnsigned<T>::Type>(x)));
} else {
diff --git a/libc/test/src/stdfix/SqrtTest.h b/libc/test/src/stdfix/SqrtTest.h
index dcbdef7b117167..606ea016b998f6 100644
--- a/libc/test/src/stdfix/SqrtTest.h
+++ b/libc/test/src/stdfix/SqrtTest.h
@@ -29,8 +29,8 @@ class SqrtTest : public LIBC_NAMESPACE::testing::Test {
static constexpr ReturnType zero = OutRep::ZERO();
static constexpr ReturnType max = OutRep::MAX();
- static constexpr ReturnType half = static_cast<ReturnType>(0.5);
- static constexpr ReturnType quarter = static_cast<ReturnType>(0.25);
+ static constexpr ReturnType half = OutRep::ONE_HALF();
+ static constexpr ReturnType quarter = OutRep::ONE_FOURTH();
static constexpr ReturnType one =
(OutRep::INTEGRAL_LEN > 0) ? static_cast<ReturnType>(1) : OutRep::MAX();
static constexpr ReturnType eps = OutRep::EPS();
@@ -41,12 +41,12 @@ class SqrtTest : public LIBC_NAMESPACE::testing::Test {
typedef ReturnType (*SqrtFunc)(FXType);
void testSpecialNumbers(SqrtFunc func) {
- EXPECT_EQ(zero, func(static_cast<FXType>(zero)));
- EXPECT_EQ(half, func(static_cast<FXType>(quarter)));
+ EXPECT_EQ(zero, func(zero));
+ EXPECT_EQ(half, func(quarter));
if constexpr (OutRep::INTEGRAL_LEN > 0) {
- EXPECT_EQ(one, func(static_cast<FXType>(one)));
- EXPECT_EQ(static_cast<ReturnType>(2.0), func(static_cast<FXType>(4.0)));
+ EXPECT_EQ(one, func(one));
+ EXPECT_EQ(static_cast<ReturnType>(2), func(4));
}
constexpr double ERR = 3.0 * static_cast<double>(eps);
>From 15a258d540263f45133978a4ffe0f7e82bd76524 Mon Sep 17 00:00:00 2001
From: sohail103 <sohailraj.satapathy at gmail.com>
Date: Sun, 30 Aug 2026 22:23:19 +0530
Subject: [PATCH 3/4] [libc][stdfix] clean up duplicated sqrtfx test code
---
libc/test/src/stdfix/SqrtTest.h | 38 +++++++++++----------------------
1 file changed, 13 insertions(+), 25 deletions(-)
diff --git a/libc/test/src/stdfix/SqrtTest.h b/libc/test/src/stdfix/SqrtTest.h
index 606ea016b998f6..c58d6da673c406 100644
--- a/libc/test/src/stdfix/SqrtTest.h
+++ b/libc/test/src/stdfix/SqrtTest.h
@@ -28,11 +28,8 @@ class SqrtTest : public LIBC_NAMESPACE::testing::Test {
using OutRep = LIBC_NAMESPACE::fixed_point::FXRep<ReturnType>;
static constexpr ReturnType zero = OutRep::ZERO();
- static constexpr ReturnType max = OutRep::MAX();
static constexpr ReturnType half = OutRep::ONE_HALF();
static constexpr ReturnType quarter = OutRep::ONE_FOURTH();
- static constexpr ReturnType one =
- (OutRep::INTEGRAL_LEN > 0) ? static_cast<ReturnType>(1) : OutRep::MAX();
static constexpr ReturnType eps = OutRep::EPS();
static constexpr FXType in_max = FXRep::MAX();
static constexpr FXType in_eps = FXRep::EPS();
@@ -41,20 +38,24 @@ class SqrtTest : public LIBC_NAMESPACE::testing::Test {
typedef ReturnType (*SqrtFunc)(FXType);
void testSpecialNumbers(SqrtFunc func) {
+ constexpr double ERR = 3.0 * static_cast<double>(eps);
+ auto check_error = [&](FXType v) {
+ double v_d = static_cast<double>(v);
+ double errors = LIBC_NAMESPACE::fputil::abs(
+ static_cast<double>(func(v)) -
+ LIBC_NAMESPACE::fputil::sqrt<double>(v_d));
+ EXPECT_TRUE(errors <= ERR);
+ };
+
EXPECT_EQ(zero, func(zero));
EXPECT_EQ(half, func(quarter));
if constexpr (OutRep::INTEGRAL_LEN > 0) {
- EXPECT_EQ(one, func(one));
+ EXPECT_EQ(static_cast<ReturnType>(1), func(1));
EXPECT_EQ(static_cast<ReturnType>(2), func(4));
}
- constexpr double ERR = 3.0 * static_cast<double>(eps);
- double eps_v_d = static_cast<double>(in_eps);
- double eps_error = LIBC_NAMESPACE::fputil::abs(
- static_cast<double>(func(in_eps)) -
- LIBC_NAMESPACE::fputil::sqrt<double>(eps_v_d));
- ASSERT_TRUE(eps_error <= ERR);
+ check_error(in_eps);
using InputStorageType = typename FXRep::StorageType;
@@ -71,22 +72,9 @@ class SqrtTest : public LIBC_NAMESPACE::testing::Test {
InputStorageType x = 0;
for (size_t i = 0; i < COUNT && x <= MAX_MAGNITUDE; ++i, x += STEP) {
FXType v = LIBC_NAMESPACE::cpp::bit_cast<FXType>(x);
- double v_d = static_cast<double>(v);
- double errors = LIBC_NAMESPACE::fputil::abs(
- static_cast<double>(func(v)) -
- LIBC_NAMESPACE::fputil::sqrt<double>(v_d));
- if (errors > ERR) {
- // Print out the failure input and output.
- EXPECT_EQ(v, static_cast<FXType>(zero));
- EXPECT_EQ(func(v), zero);
- }
- ASSERT_TRUE(errors <= ERR);
+ check_error(v);
}
- double v_d = static_cast<double>(in_max);
- double error =
- LIBC_NAMESPACE::fputil::abs(static_cast<double>(func(in_max)) -
- LIBC_NAMESPACE::fputil::sqrt<double>(v_d));
- ASSERT_TRUE(error <= ERR);
+ check_error(in_max);
}
};
>From b1599f4cbe0e7f1fd1e0332d9203c5fcc0b1e2d5 Mon Sep 17 00:00:00 2001
From: sohail103 <sohailraj.satapathy at gmail.com>
Date: Tue, 1 Sep 2026 12:09:21 +0530
Subject: [PATCH 4/4] [libc][stdfix] remove signed fixed-point sqrtfx
entrypoints
---
libc/config/baremetal/arm/entrypoints.txt | 6 -
libc/config/baremetal/riscv/entrypoints.txt | 6 -
libc/config/linux/riscv/entrypoints.txt | 6 -
libc/config/linux/x86_64/entrypoints.txt | 6 -
libc/include/stdfix.yaml | 48 -------
libc/src/__support/fixed_point/sqrt.h | 136 ++++++++------------
libc/src/stdfix/CMakeLists.txt | 2 +-
libc/src/stdfix/sqrthk.cpp | 20 ---
libc/src/stdfix/sqrthk.h | 21 ---
libc/src/stdfix/sqrthr.cpp | 20 ---
libc/src/stdfix/sqrthr.h | 21 ---
libc/src/stdfix/sqrtk.cpp | 20 ---
libc/src/stdfix/sqrtk.h | 21 ---
libc/src/stdfix/sqrtlk.cpp | 20 ---
libc/src/stdfix/sqrtlk.h | 21 ---
libc/src/stdfix/sqrtlr.cpp | 20 ---
libc/src/stdfix/sqrtlr.h | 21 ---
libc/src/stdfix/sqrtr.cpp | 20 ---
libc/src/stdfix/sqrtr.h | 21 ---
libc/test/src/stdfix/CMakeLists.txt | 2 +-
libc/test/src/stdfix/SqrtTest.h | 4 +-
libc/test/src/stdfix/sqrthk_test.cpp | 13 --
libc/test/src/stdfix/sqrthr_test.cpp | 13 --
libc/test/src/stdfix/sqrtk_test.cpp | 13 --
libc/test/src/stdfix/sqrtlk_test.cpp | 13 --
libc/test/src/stdfix/sqrtlr_test.cpp | 13 --
libc/test/src/stdfix/sqrtr_test.cpp | 13 --
libc/utils/docgen/stdfix.yaml | 6 -
28 files changed, 58 insertions(+), 488 deletions(-)
delete mode 100644 libc/src/stdfix/sqrthk.cpp
delete mode 100644 libc/src/stdfix/sqrthk.h
delete mode 100644 libc/src/stdfix/sqrthr.cpp
delete mode 100644 libc/src/stdfix/sqrthr.h
delete mode 100644 libc/src/stdfix/sqrtk.cpp
delete mode 100644 libc/src/stdfix/sqrtk.h
delete mode 100644 libc/src/stdfix/sqrtlk.cpp
delete mode 100644 libc/src/stdfix/sqrtlk.h
delete mode 100644 libc/src/stdfix/sqrtlr.cpp
delete mode 100644 libc/src/stdfix/sqrtlr.h
delete mode 100644 libc/src/stdfix/sqrtr.cpp
delete mode 100644 libc/src/stdfix/sqrtr.h
delete mode 100644 libc/test/src/stdfix/sqrthk_test.cpp
delete mode 100644 libc/test/src/stdfix/sqrthr_test.cpp
delete mode 100644 libc/test/src/stdfix/sqrtk_test.cpp
delete mode 100644 libc/test/src/stdfix/sqrtlk_test.cpp
delete mode 100644 libc/test/src/stdfix/sqrtlr_test.cpp
delete mode 100644 libc/test/src/stdfix/sqrtr_test.cpp
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index e42041d19e95ee..fc937dcc7670c0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -966,12 +966,6 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtulk
- libc.src.stdfix.sqrthr
- libc.src.stdfix.sqrtr
- libc.src.stdfix.sqrtlr
- libc.src.stdfix.sqrthk
- libc.src.stdfix.sqrtk
- libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index e622e0bc856c29..ae01bdda48a8ed 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -958,12 +958,6 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtulk
- libc.src.stdfix.sqrthr
- libc.src.stdfix.sqrtr
- libc.src.stdfix.sqrtlr
- libc.src.stdfix.sqrthk
- libc.src.stdfix.sqrtk
- libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index c1c43649c64116..0b9dcb8065013a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1339,12 +1339,6 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtulk
- libc.src.stdfix.sqrthr
- libc.src.stdfix.sqrtr
- libc.src.stdfix.sqrtlr
- libc.src.stdfix.sqrthk
- libc.src.stdfix.sqrtk
- libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 1f2b7ae6b8b1be..3684dbd9a499d9 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1339,12 +1339,6 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.sqrtuhk
libc.src.stdfix.sqrtuk
libc.src.stdfix.sqrtulk
- libc.src.stdfix.sqrthr
- libc.src.stdfix.sqrtr
- libc.src.stdfix.sqrtlr
- libc.src.stdfix.sqrthk
- libc.src.stdfix.sqrtk
- libc.src.stdfix.sqrtlk
libc.src.stdfix.uhksqrtus
libc.src.stdfix.uksqrtui
libc.src.stdfix.hrbits
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index 2be63d3ea22b6e..0613f82c1d4950 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -474,54 +474,6 @@ functions:
arguments:
- type: unsigned long accum
guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrthr
- standards:
- - stdc_ext
- - llvm_libc_stdfix_ext
- return_type: unsigned short fract
- arguments:
- - type: short fract
- guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtr
- standards:
- - stdc_ext
- - llvm_libc_stdfix_ext
- return_type: unsigned fract
- arguments:
- - type: fract
- guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtlr
- standards:
- - stdc_ext
- - llvm_libc_stdfix_ext
- return_type: unsigned long fract
- arguments:
- - type: unsigned long fract
- guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrthk
- standards:
- - stdc_ext
- - llvm_libc_stdfix_ext
- return_type: unsigned short accum
- arguments:
- - type: short accum
- guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtk
- standards:
- - stdc_ext
- - llvm_libc_stdfix_ext
- return_type: unsigned accum
- arguments:
- - type: accum
- guard: LIBC_COMPILER_HAS_FIXED_POINT
- - name: sqrtlk
- standards:
- - stdc_ext
- - llvm_libc_stdfix_ext
- return_type: unsigned long accum
- arguments:
- - type: long accum
- guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: uhksqrtus
standards:
- stdc_ext
diff --git a/libc/src/__support/fixed_point/sqrt.h b/libc/src/__support/fixed_point/sqrt.h
index 659884e2441cd3..86b2bb6bf6a7bf 100644
--- a/libc/src/__support/fixed_point/sqrt.h
+++ b/libc/src/__support/fixed_point/sqrt.h
@@ -13,11 +13,10 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/limits.h" // CHAR_BIT
#include "src/__support/CPP/type_traits.h"
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
+#include "src/__support/fixed_point/fx_rep.h"
+#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-
-#include "fx_rep.h"
#include "src/__support/uint128.h"
#ifdef LIBC_COMPILER_HAS_FIXED_POINT
@@ -132,26 +131,6 @@ template <> struct SqrtConfig<unsigned int> {
using HalfType = unsigned short;
};
-template <typename T> struct FXUnsigned;
-template <> struct FXUnsigned<short fract> {
- using Type = unsigned short fract;
-};
-template <> struct FXUnsigned<fract> {
- using Type = unsigned fract;
-};
-template <> struct FXUnsigned<long fract> {
- using Type = unsigned long fract;
-};
-template <> struct FXUnsigned<short accum> {
- using Type = unsigned short accum;
-};
-template <> struct FXUnsigned<accum> {
- using Type = unsigned accum;
-};
-template <> struct FXUnsigned<long accum> {
- using Type = unsigned long accum;
-};
-
} // namespace internal
// Core computation for sqrt with normalized inputs (0.25 <= x < 1).
@@ -199,65 +178,60 @@ sqrt_core(typename Config::Type x_frac) {
template <typename T>
LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, T> sqrt(T x) {
- if constexpr (FXRep<T>::SIGN_LEN > 0) {
- return static_cast<T>(
- sqrt(static_cast<typename internal::FXUnsigned<T>::Type>(x)));
+ using BitType = typename FXRep<T>::StorageType;
+ BitType x_bit = cpp::bit_cast<BitType>(x);
+
+ if (LIBC_UNLIKELY(x_bit == 0))
+ return FXRep<T>::ZERO();
+
+ int leading_zeros = cpp::countl_zero(x_bit);
+ constexpr int STORAGE_LENGTH = sizeof(BitType) * CHAR_BIT;
+ constexpr int EXP_ADJUSTMENT = STORAGE_LENGTH - FXRep<T>::FRACTION_LEN - 1;
+ // x_exp is the real exponent of the leading bit of x.
+ int x_exp = EXP_ADJUSTMENT - leading_zeros;
+ int shift = EXP_ADJUSTMENT - 1 - (x_exp & (~1));
+ // Normalize.
+ x_bit <<= shift;
+
+ if constexpr (STORAGE_LENGTH > 32) {
+ using SeedConfig = internal::SqrtConfig<unsigned long fract>;
+ using SeedType = SeedConfig::Type;
+ using SeedStorageType = typename FXRep<SeedType>::StorageType;
+ constexpr int SEED_LENGTH = sizeof(SeedStorageType) * CHAR_BIT;
+
+ static_assert(STORAGE_LENGTH <= 2 * SEED_LENGTH,
+ "Output storage type has to be lesser than or equal to "
+ "double the seed table's width for accurate results.");
+
+ // Seed from the widest available table using the top half of x, then
+ // widen to full precision. No native fract type exists at this storage
+ // width to build a table for directly.
+ SeedStorageType x_top_half =
+ static_cast<SeedStorageType>(x_bit >> SEED_LENGTH);
+ SeedType x_seed = cpp::bit_cast<SeedType>(x_top_half);
+ SeedType r_seed = sqrt_core<SeedConfig>(x_seed);
+
+ UInt128 r0 = static_cast<UInt128>(cpp::bit_cast<SeedStorageType>(r_seed))
+ << SEED_LENGTH;
+
+ UInt128 x_wide = static_cast<UInt128>(x_bit) << STORAGE_LENGTH;
+ UInt128 r1 = (r0 + x_wide / r0) >> 1;
+
+ r1 >>= EXP_ADJUSTMENT - (x_exp >> 1);
+ BitType r_bits = static_cast<BitType>(r1);
+ return cpp::bit_cast<T>(r_bits);
} else {
- using BitType = typename FXRep<T>::StorageType;
- BitType x_bit = cpp::bit_cast<BitType>(x);
-
- if (LIBC_UNLIKELY(x_bit == 0))
- return FXRep<T>::ZERO();
-
- int leading_zeros = cpp::countl_zero(x_bit);
- constexpr int STORAGE_LENGTH = sizeof(BitType) * CHAR_BIT;
- constexpr int EXP_ADJUSTMENT = STORAGE_LENGTH - FXRep<T>::FRACTION_LEN - 1;
- // x_exp is the real exponent of the leading bit of x.
- int x_exp = EXP_ADJUSTMENT - leading_zeros;
- int shift = EXP_ADJUSTMENT - 1 - (x_exp & (~1));
- // Normalize.
- x_bit <<= shift;
-
- if constexpr (STORAGE_LENGTH > 32) {
- using SeedConfig = internal::SqrtConfig<unsigned long fract>;
- using SeedType = SeedConfig::Type;
- using SeedStorageType = typename FXRep<SeedType>::StorageType;
- constexpr int SEED_LENGTH = sizeof(SeedStorageType) * CHAR_BIT;
-
- static_assert(STORAGE_LENGTH <= 2 * SEED_LENGTH,
- "Output storage type has to be lesser than or equal to "
- "double the seed table's width for accurate results.");
-
- // Seed from the widest available table using the top half of x, then
- // widen to full precision. No native fract type exists at this storage
- // width to build a table for directly.
- SeedStorageType x_top_half =
- static_cast<SeedStorageType>(x_bit >> SEED_LENGTH);
- SeedType x_seed = cpp::bit_cast<SeedType>(x_top_half);
- SeedType r_seed = sqrt_core<SeedConfig>(x_seed);
-
- UInt128 r0 = static_cast<UInt128>(cpp::bit_cast<SeedStorageType>(r_seed))
- << SEED_LENGTH;
-
- UInt128 x_wide = static_cast<UInt128>(x_bit) << STORAGE_LENGTH;
- UInt128 r1 = (r0 + x_wide / r0) >> 1;
-
- r1 >>= EXP_ADJUSTMENT - (x_exp >> 1);
- BitType r_bits = static_cast<BitType>(r1);
- return cpp::bit_cast<T>(r_bits);
- } else {
- using FracType = typename internal::SqrtConfig<T>::Type;
- FracType x_frac = cpp::bit_cast<FracType>(x_bit);
-
- // Compute sqrt(x_frac) using Newton-method.
- FracType r = sqrt_core<internal::SqrtConfig<T>>(x_frac);
-
- // Re-scaling
- r >>= EXP_ADJUSTMENT - (x_exp >> 1);
-
- // Return result.
- return cpp::bit_cast<T>(r);
- }
+ using FracType = typename internal::SqrtConfig<T>::Type;
+ FracType x_frac = cpp::bit_cast<FracType>(x_bit);
+
+ // Compute sqrt(x_frac) using Newton-method.
+ FracType r = sqrt_core<internal::SqrtConfig<T>>(x_frac);
+
+ // Re-scaling
+ r >>= EXP_ADJUSTMENT - (x_exp >> 1);
+
+ // Return result.
+ return cpp::bit_cast<T>(r);
}
}
diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index 5a4606db899e57..679e623dd7b318 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -14,7 +14,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
)
endforeach()
-foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
+foreach(suffix IN ITEMS uhr ur ulr uhk uk ulk)
add_entrypoint_object(
sqrt${suffix}
HDRS
diff --git a/libc/src/stdfix/sqrthk.cpp b/libc/src/stdfix/sqrthk.cpp
deleted file mode 100644
index 200e2942131e2c..00000000000000
--- a/libc/src/stdfix/sqrthk.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of sqrthk 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 "sqrthk.h"
-#include "src/__support/common.h"
-#include "src/__support/fixed_point/sqrt.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(unsigned short accum, sqrthk, (short accum x)) {
- return fixed_point::sqrt(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrthk.h b/libc/src/stdfix/sqrthk.h
deleted file mode 100644
index 2924104c57e0ab..00000000000000
--- a/libc/src/stdfix/sqrthk.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for sqrthk ------------------------*- 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_STDFIX_SQRTHK_H
-#define LLVM_LIBC_SRC_STDFIX_SQRTHK_H
-
-#include "include/llvm-libc-macros/stdfix-macros.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-unsigned short accum sqrthk(short accum x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_STDFIX_SQRTHK_H
diff --git a/libc/src/stdfix/sqrthr.cpp b/libc/src/stdfix/sqrthr.cpp
deleted file mode 100644
index e3eb0904fb5f00..00000000000000
--- a/libc/src/stdfix/sqrthr.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of sqrthr 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 "sqrthr.h"
-#include "src/__support/common.h"
-#include "src/__support/fixed_point/sqrt.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(unsigned short fract, sqrthr, (short fract x)) {
- return fixed_point::sqrt(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrthr.h b/libc/src/stdfix/sqrthr.h
deleted file mode 100644
index 352ca1d405af39..00000000000000
--- a/libc/src/stdfix/sqrthr.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for sqrthr ------------------------*- 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_STDFIX_SQRTHR_H
-#define LLVM_LIBC_SRC_STDFIX_SQRTHR_H
-
-#include "include/llvm-libc-macros/stdfix-macros.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-unsigned short fract sqrthr(short fract x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_STDFIX_SQRTHR_H
diff --git a/libc/src/stdfix/sqrtk.cpp b/libc/src/stdfix/sqrtk.cpp
deleted file mode 100644
index 66c17a37c264d1..00000000000000
--- a/libc/src/stdfix/sqrtk.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of sqrtk 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 "sqrtk.h"
-#include "src/__support/common.h"
-#include "src/__support/fixed_point/sqrt.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(unsigned accum, sqrtk, (accum x)) {
- return fixed_point::sqrt(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtk.h b/libc/src/stdfix/sqrtk.h
deleted file mode 100644
index f01e4a5da9ad04..00000000000000
--- a/libc/src/stdfix/sqrtk.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for sqrtk -------------------------*- 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_STDFIX_SQRTK_H
-#define LLVM_LIBC_SRC_STDFIX_SQRTK_H
-
-#include "include/llvm-libc-macros/stdfix-macros.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-unsigned accum sqrtk(accum x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_STDFIX_SQRTK_H
diff --git a/libc/src/stdfix/sqrtlk.cpp b/libc/src/stdfix/sqrtlk.cpp
deleted file mode 100644
index a4c6bf1419157d..00000000000000
--- a/libc/src/stdfix/sqrtlk.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of sqrtlk 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 "sqrtlk.h"
-#include "src/__support/common.h"
-#include "src/__support/fixed_point/sqrt.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(unsigned long accum, sqrtlk, (long accum x)) {
- return fixed_point::sqrt(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtlk.h b/libc/src/stdfix/sqrtlk.h
deleted file mode 100644
index a93d4aa090879d..00000000000000
--- a/libc/src/stdfix/sqrtlk.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for sqrtlk ------------------------*- 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_STDFIX_SQRTLK_H
-#define LLVM_LIBC_SRC_STDFIX_SQRTLK_H
-
-#include "include/llvm-libc-macros/stdfix-macros.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-unsigned long accum sqrtlk(long accum x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_STDFIX_SQRTLK_H
diff --git a/libc/src/stdfix/sqrtlr.cpp b/libc/src/stdfix/sqrtlr.cpp
deleted file mode 100644
index e9b3317b9bea19..00000000000000
--- a/libc/src/stdfix/sqrtlr.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of sqrtlr 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 "sqrtlr.h"
-#include "src/__support/common.h"
-#include "src/__support/fixed_point/sqrt.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(unsigned long fract, sqrtlr, (long fract x)) {
- return fixed_point::sqrt(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtlr.h b/libc/src/stdfix/sqrtlr.h
deleted file mode 100644
index 09df5f34da5377..00000000000000
--- a/libc/src/stdfix/sqrtlr.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for sqrtlr ------------------------*- 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_STDFIX_SQRTLR_H
-#define LLVM_LIBC_SRC_STDFIX_SQRTLR_H
-
-#include "include/llvm-libc-macros/stdfix-macros.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-unsigned long fract sqrtlr(long fract x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_STDFIX_SQRTLR_H
diff --git a/libc/src/stdfix/sqrtr.cpp b/libc/src/stdfix/sqrtr.cpp
deleted file mode 100644
index 3f2c316c9aae05..00000000000000
--- a/libc/src/stdfix/sqrtr.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of sqrtr 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 "sqrtr.h"
-#include "src/__support/common.h"
-#include "src/__support/fixed_point/sqrt.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(unsigned fract, sqrtr, (fract x)) {
- return fixed_point::sqrt(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/sqrtr.h b/libc/src/stdfix/sqrtr.h
deleted file mode 100644
index fdc7f37a410afa..00000000000000
--- a/libc/src/stdfix/sqrtr.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Implementation header for sqrtr -------------------------*- 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_STDFIX_SQRTR_H
-#define LLVM_LIBC_SRC_STDFIX_SQRTR_H
-
-#include "include/llvm-libc-macros/stdfix-macros.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-unsigned fract sqrtr(fract x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_STDFIX_SQRTR_H
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index 88f8b1dc5011c9..21247960fbc87c 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -19,7 +19,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
)
endforeach()
-foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
+foreach(suffix IN ITEMS uhr ur ulr uhk uk ulk)
add_libc_test(
sqrt${suffix}_test
SUITE
diff --git a/libc/test/src/stdfix/SqrtTest.h b/libc/test/src/stdfix/SqrtTest.h
index c58d6da673c406..f9edbef32b86d7 100644
--- a/libc/test/src/stdfix/SqrtTest.h
+++ b/libc/test/src/stdfix/SqrtTest.h
@@ -61,9 +61,7 @@ class SqrtTest : public LIBC_NAMESPACE::testing::Test {
constexpr size_t COUNT = 255;
constexpr InputStorageType MAX_MAGNITUDE =
- (FXRep::SIGN_LEN > 0) ? static_cast<InputStorageType>(
- InputStorageType(~InputStorageType(0)) >> 1)
- : InputStorageType(~InputStorageType(0));
+ InputStorageType(~InputStorageType(0));
constexpr InputStorageType STEP =
(MAX_MAGNITUDE < COUNT)
? 1
diff --git a/libc/test/src/stdfix/sqrthk_test.cpp b/libc/test/src/stdfix/sqrthk_test.cpp
deleted file mode 100644
index 31eda96c17aee7..00000000000000
--- a/libc/test/src/stdfix/sqrthk_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for sqrthk ----------------------------------------------===//
-//
-// 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 "SqrtTest.h"
-
-#include "src/stdfix/sqrthk.h"
-
-LIST_SQRT_TESTS(unsigned short accum, short accum, LIBC_NAMESPACE::sqrthk);
diff --git a/libc/test/src/stdfix/sqrthr_test.cpp b/libc/test/src/stdfix/sqrthr_test.cpp
deleted file mode 100644
index 5c82a2183350a2..00000000000000
--- a/libc/test/src/stdfix/sqrthr_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for sqrthr ----------------------------------------------===//
-//
-// 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 "SqrtTest.h"
-
-#include "src/stdfix/sqrthr.h"
-
-LIST_SQRT_TESTS(unsigned short fract, short fract, LIBC_NAMESPACE::sqrthr);
diff --git a/libc/test/src/stdfix/sqrtk_test.cpp b/libc/test/src/stdfix/sqrtk_test.cpp
deleted file mode 100644
index dd4d0c2220eb6a..00000000000000
--- a/libc/test/src/stdfix/sqrtk_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for sqrtk -----------------------------------------------===//
-//
-// 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 "SqrtTest.h"
-
-#include "src/stdfix/sqrtk.h"
-
-LIST_SQRT_TESTS(unsigned accum, accum, LIBC_NAMESPACE::sqrtk);
diff --git a/libc/test/src/stdfix/sqrtlk_test.cpp b/libc/test/src/stdfix/sqrtlk_test.cpp
deleted file mode 100644
index ab3502d8a34461..00000000000000
--- a/libc/test/src/stdfix/sqrtlk_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for sqrtlk ----------------------------------------------===//
-//
-// 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 "SqrtTest.h"
-
-#include "src/stdfix/sqrtlk.h"
-
-LIST_SQRT_TESTS(unsigned long accum, long accum, LIBC_NAMESPACE::sqrtlk);
diff --git a/libc/test/src/stdfix/sqrtlr_test.cpp b/libc/test/src/stdfix/sqrtlr_test.cpp
deleted file mode 100644
index caa29c81efc77c..00000000000000
--- a/libc/test/src/stdfix/sqrtlr_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for sqrtlr ----------------------------------------------===//
-//
-// 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 "SqrtTest.h"
-
-#include "src/stdfix/sqrtlr.h"
-
-LIST_SQRT_TESTS(unsigned long fract, long fract, LIBC_NAMESPACE::sqrtlr);
diff --git a/libc/test/src/stdfix/sqrtr_test.cpp b/libc/test/src/stdfix/sqrtr_test.cpp
deleted file mode 100644
index 7ad93f1d8769f1..00000000000000
--- a/libc/test/src/stdfix/sqrtr_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for sqrtr -----------------------------------------------===//
-//
-// 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 "SqrtTest.h"
-
-#include "src/stdfix/sqrtr.h"
-
-LIST_SQRT_TESTS(unsigned fract, fract, LIBC_NAMESPACE::sqrtr);
diff --git a/libc/utils/docgen/stdfix.yaml b/libc/utils/docgen/stdfix.yaml
index 98e909fd67cc16..7c211b494bd03b 100644
--- a/libc/utils/docgen/stdfix.yaml
+++ b/libc/utils/docgen/stdfix.yaml
@@ -220,17 +220,11 @@ families:
group: Higher Math Functions
variants:
uhr: sqrtuhr
- hr: sqrthr
ur: sqrtur
- r: sqrtr
ulr: sqrtulr
- lr: sqrtlr
uhk: sqrtuhk
- hk: sqrthk
uk: sqrtuk
- k: sqrtk
ulk: sqrtulk
- lk: sqrtlk
extension: llvm-libc
tan:
group: Higher Math Functions
More information about the libc-commits
mailing list