[libc-commits] [libc] [libc][stdfix] Implement sqrtfx for remaining fixed point types (PR #214741)

via libc-commits libc-commits at lists.llvm.org
Fri Aug 7 07:08:29 PDT 2026


https://github.com/sohail103 created https://github.com/llvm/llvm-project/pull/214741

This PR implements sqrtfx for the remaining fixed point types (unsigned long accum and all signed variants).

```c
unsigned short fract sqrthr(short fract x);
unsigned fract sqrtr(fract x);
unsigned long fract sqrtlr(long fract x);
unsigned short accum sqrthk(short accum x);
unsigned accum sqrtk(accum x);
unsigned long accum sqrtlk(long accum x);
unsigned long accum sqrtulk(unsigned long accum x);
```

>From d7c9d0c6cd933e002b0e5aba5c81e1e25703399b 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] [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/docs/headers/stdfix.rst                  |   2 +-
 libc/include/stdfix.yaml                      |  69 +++++++++--
 libc/src/__support/fixed_point/CMakeLists.txt |   1 +
 libc/src/__support/fixed_point/sqrt.h         | 113 +++++++++++++-----
 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 +-
 37 files changed, 618 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 71ecbe438bf7b..d6e30c8ee5e16 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -923,12 +923,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 b38f60ab9d5f5..3aab854f028e7 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -920,12 +920,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 c6a4b431f33de..7396b30274315 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1137,12 +1137,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 fb0886e2e650a..25dfa84483ec2 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1142,12 +1142,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/docs/headers/stdfix.rst b/libc/docs/headers/stdfix.rst
index 91dad81c595b0..049ed4846e28b 100644
--- a/libc/docs/headers/stdfix.rst
+++ b/libc/docs/headers/stdfix.rst
@@ -114,7 +114,7 @@ floating point types, but are not part of the ISO/IEC TR 18037:2008 spec.
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | sin           |                |             |               |            |                |             |                |             |               |            |                |             |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
-| sqrt          | |check|        |             | |check|       |            | |check|        |             | |check|        |             | |check|       |            |                |             |
+| sqrt          | |check|        | |check|     | |check|       | |check|    | |check|        | |check|     | |check|        | |check|     | |check|       | |check|    | |check|        | |check|     |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | tan           |                |             |               |            |                |             |                |             |               |            |                |             |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index f91e4ea620e3e..eecfa86262f96 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -410,21 +410,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:
@@ -436,12 +452,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
@@ -449,13 +482,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 c1b0ab30e0307..7e9d542683499 100644
--- a/libc/src/__support/fixed_point/CMakeLists.txt
+++ b/libc/src/__support/fixed_point/CMakeLists.txt
@@ -38,4 +38,5 @@ add_header_library(
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.limits
     libc.src.__support.CPP.type_traits
+    libc.src.__support.uint128
 )
diff --git a/libc/src/__support/fixed_point/sqrt.h b/libc/src/__support/fixed_point/sqrt.h
index b77319debeeaf..6ab520a00408a 100644
--- a/libc/src/__support/fixed_point/sqrt.h
+++ b/libc/src/__support/fixed_point/sqrt.h
@@ -13,11 +13,13 @@
 #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/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
 
@@ -131,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
 
@@ -147,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
 
@@ -181,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 b7121407e0307..627b56fe35de0 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 0000000000000..200e2942131e2
--- /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 0000000000000..2924104c57e0a
--- /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 0000000000000..e3eb0904fb5f0
--- /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 0000000000000..352ca1d405af3
--- /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 0000000000000..66c17a37c264d
--- /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 0000000000000..f01e4a5da9ad0
--- /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 0000000000000..a4c6bf1419157
--- /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 0000000000000..a93d4aa090879
--- /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 0000000000000..e9b3317b9bea1
--- /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 0000000000000..09df5f34da537
--- /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 0000000000000..3f2c316c9aae0
--- /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 0000000000000..fdc7f37a410af
--- /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 0000000000000..0572f2aafd567
--- /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 0000000000000..f5c15f8dc5555
--- /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 8ebf69c66d66c..3a31ca20cd593 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -21,7 +21,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 2a8a825abb460..4fdd46ded8d6f 100644
--- a/libc/test/src/stdfix/SqrtTest.h
+++ b/libc/test/src/stdfix/SqrtTest.h
@@ -14,54 +14,76 @@
 #include "src/__support/fixed_point/fx_rep.h"
 #include "src/__support/fixed_point/sqrt.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 0000000000000..31eda96c17aee
--- /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 0000000000000..5c82a2183350a
--- /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 0000000000000..dd4d0c2220eb6
--- /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 0000000000000..ab3502d8a3446
--- /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 0000000000000..caa29c81efc77
--- /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 0000000000000..7ad93f1d8769f
--- /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 d6ff5385cab86..9f9b6638cfe6e 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 22f00a4231b31..65276779c99ef 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 5a3105de1e0bf..e22edffeadd57 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 0000000000000..90cfa0865eece
--- /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 1be4e2b5e0a6f..33cc7558b4876 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 12b1c2211db05..e3254ec950cad 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);



More information about the libc-commits mailing list