[libc-commits] [libc] [llvm] [libc] Make totalorder functions use the emulated float128 type (PR #221085)

Muhammad Haris Awan via libc-commits libc-commits at lists.llvm.org
Sun Sep 27 07:30:09 PDT 2026


https://github.com/harisawan-bit updated https://github.com/llvm/llvm-project/pull/221085

>From ad214e8d8e9f7d2a07911d8ea73603598ca0df92 Mon Sep 17 00:00:00 2001
From: Muhammad Haris Awan <an25mbbs026.student at fui.edu.pk>
Date: Sun, 27 Sep 2026 14:29:55 +0000
Subject: [PATCH] [libc] Make totalorder functions use the emulated float128
 type

Part of #216576.

Modify `totalorderf128` and `totalordermagf128` to work with emulated
Float128 by removing native float128 guards, updating the implementation
headers, generic wrappers, CMake dependencies, Bazel overlays, and
smoke/shared tests.
---
 libc/config/baremetal/aarch64/entrypoints.txt |  4 +--
 libc/config/baremetal/arm/entrypoints.txt     |  4 +--
 libc/config/baremetal/riscv/entrypoints.txt   |  4 +--
 libc/config/darwin/aarch64/entrypoints.txt    |  4 +--
 libc/config/darwin/x86_64/entrypoints.txt     |  2 ++
 libc/config/freebsd/x86_64/entrypoints.txt    |  4 +--
 libc/config/gpu/amdgpu/entrypoints.txt        |  2 ++
 libc/config/gpu/nvptx/entrypoints.txt         |  2 ++
 libc/config/linux/aarch64/entrypoints.txt     |  4 +--
 libc/config/linux/arm/entrypoints.txt         |  2 ++
 libc/config/linux/riscv/entrypoints.txt       |  4 +--
 libc/config/linux/x86_64/entrypoints.txt      |  4 +--
 libc/config/windows/entrypoints.txt           |  2 ++
 libc/shared/math/totalorderf128.h             | 13 +++++-----
 libc/shared/math/totalordermagf128.h          | 13 +++++-----
 libc/src/__support/math/CMakeLists.txt        |  4 +--
 libc/src/__support/math/totalorderf128.h      | 18 +++++++------
 libc/src/__support/math/totalordermagf128.h   | 20 ++++++++-------
 libc/src/math/generic/CMakeLists.txt          |  2 ++
 libc/src/math/generic/totalorderf128.cpp      | 14 +++++++++--
 libc/src/math/generic/totalordermagf128.cpp   | 14 +++++++++--
 libc/src/math/totalorderf128.h                | 12 ++++++++-
 libc/src/math/totalordermagf128.h             | 12 ++++++++-
 .../shared/shared_math_constexpr_test.cpp     | 25 +++++++++++--------
 libc/test/shared/shared_math_test.cpp         | 23 ++++++++++-------
 libc/test/src/math/smoke/CMakeLists.txt       |  2 ++
 .../src/math/smoke/totalorderf128_test.cpp    | 12 ++++++++-
 .../src/math/smoke/totalordermagf128_test.cpp | 12 ++++++++-
 .../llvm-project-overlay/libc/BUILD.bazel     |  8 ++++--
 .../libc/test/src/math/smoke/BUILD.bazel      |  6 +++++
 30 files changed, 174 insertions(+), 78 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 114534ce61ae6..28f3cfbfbe174 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -607,9 +607,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanhf
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -798,8 +800,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index c8148815c34e3..1b80147b6aae2 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -619,9 +619,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanhf
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -809,8 +811,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 622d6156cff11..415332a464521 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -610,9 +610,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanhf
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -801,8 +803,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index d702b2c5a6549..8dce7c5893591 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -429,9 +429,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanpif
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -620,8 +622,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 716ab572f8d3c..ee34771831885 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -253,8 +253,10 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.sqrtl
     #libc.src.math.tanf
     #libc.src.math.tanhf
+    #libc.src.math.totalorderf128
     #libc.src.math.totalordermag
     #libc.src.math.totalordermagf
+    #libc.src.math.totalordermagf128
     #libc.src.math.totalordermagl
     #libc.src.math.trunc
     #libc.src.math.truncf
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 8f6c178301c2f..2fdf99c530a42 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -380,9 +380,11 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanpif
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.ufromfp
     libc.src.math.ufromfpf
@@ -553,8 +555,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 5c5e5891da822..182adb81a7a6c 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -548,9 +548,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tgammaf
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index afae725484a89..76c98deb60e14 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -545,9 +545,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tgammaf
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 15a5367f5fc95..0f84c90f55485 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -827,9 +827,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanpif
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -1011,8 +1013,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 1441146393c5f..d9becabd1001e 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -608,9 +608,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanpif
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 8f4dded27de68..cf598b5d5f81a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -883,9 +883,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanpif
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -1084,8 +1086,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 8ca73cc82cc2d..a7fd24b8cff09 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -905,9 +905,11 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanpif
     libc.src.math.totalorder
     libc.src.math.totalorderf
+    libc.src.math.totalorderf128
     libc.src.math.totalorderl
     libc.src.math.totalordermag
     libc.src.math.totalordermagf
+    libc.src.math.totalordermagf128
     libc.src.math.totalordermagl
     libc.src.math.trunc
     libc.src.math.truncf
@@ -1106,8 +1108,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
-    libc.src.math.totalorderf128
-    libc.src.math.totalordermagf128
     libc.src.math.ufromfpf128
     libc.src.math.ufromfpxf128
   )
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 3a48b49e169b3..bfe582ac25264 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -347,6 +347,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.tanf
     libc.src.math.tanhf
     libc.src.math.tanpif
+    libc.src.math.totalorderf128
+    libc.src.math.totalordermagf128
     libc.src.math.trunc
     libc.src.math.truncf
     libc.src.math.truncf128
diff --git a/libc/shared/math/totalorderf128.h b/libc/shared/math/totalorderf128.h
index 8427aa0df9889..35a0309b949eb 100644
--- a/libc/shared/math/totalorderf128.h
+++ b/libc/shared/math/totalorderf128.h
@@ -1,18 +1,19 @@
-//===-- Shared totalorderf128 function --------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the shared totalorderf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERF128_H
 #define LLVM_LIBC_SHARED_MATH_TOTALORDERF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/totalorderf128.h"
 
@@ -24,6 +25,4 @@ using math::totalorderf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_TOTALORDERF128_H
diff --git a/libc/shared/math/totalordermagf128.h b/libc/shared/math/totalordermagf128.h
index 663a3c4dc9fb2..344944293705f 100644
--- a/libc/shared/math/totalordermagf128.h
+++ b/libc/shared/math/totalordermagf128.h
@@ -1,18 +1,19 @@
-//===-- Shared totalordermagf128 function -----------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the shared totalordermagf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF128_H
 #define LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/totalordermagf128.h"
 
@@ -24,6 +25,4 @@ using math::totalordermagf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 8d6a1495e1c11..2865e06b0fd7b 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5756,8 +5756,8 @@ add_header_library(
   HDRS
     totalorderf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
     libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
 )
 
@@ -5813,8 +5813,8 @@ add_header_library(
   HDRS
     totalordermagf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
     libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.float128
     libc.src.__support.macros.config
 )
 
diff --git a/libc/src/__support/math/totalorderf128.h b/libc/src/__support/math/totalorderf128.h
index 3af00e711fab9..0128b5ab73fad 100644
--- a/libc/src/__support/math/totalorderf128.h
+++ b/libc/src/__support/math/totalorderf128.h
@@ -1,31 +1,33 @@
-//===-- Implementation header for totalorderf128 ----------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation header for totalorderf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr int totalorderf128(const float128 *x, const float128 *y) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr int totalorderf128(const Float128 *x, const Float128 *y) {
   return static_cast<int>(fputil::totalorder(*x, *y));
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF128_H
diff --git a/libc/src/__support/math/totalordermagf128.h b/libc/src/__support/math/totalordermagf128.h
index ea79011f8b047..675277e4af006 100644
--- a/libc/src/__support/math/totalordermagf128.h
+++ b/libc/src/__support/math/totalordermagf128.h
@@ -1,32 +1,34 @@
-//===-- Implementation header for totalordermagf128 -------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation header for totalordermagf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr int totalordermagf128(const float128 *x,
-                                            const float128 *y) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr int totalordermagf128(const Float128 *x,
+                                            const Float128 *y) {
   return static_cast<int>(fputil::totalordermag(*x, *y));
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 28b8e954530dd..d58f4282e6b23 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4289,6 +4289,7 @@ add_entrypoint_object(
   HDRS
     ../totalorderf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.totalorderf128
 )
 
@@ -4349,6 +4350,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermagf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.totalordermagf128
 )
 
diff --git a/libc/src/math/generic/totalorderf128.cpp b/libc/src/math/generic/totalorderf128.cpp
index ca521291e4924..16424372b8416 100644
--- a/libc/src/math/generic/totalorderf128.cpp
+++ b/libc/src/math/generic/totalorderf128.cpp
@@ -1,19 +1,29 @@
-//===-- Implementation of totalorderf128 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation of totalorderf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/math/totalorderf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/totalorderf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(int, totalorderf128,
                    (const float128 *x, const float128 *y)) {
-  return math::totalorderf128(x, y);
+  Float128 x_f128 = cpp::bit_cast<Float128>(*x);
+  Float128 y_f128 = cpp::bit_cast<Float128>(*y);
+  return math::totalorderf128(&x_f128, &y_f128);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagf128.cpp b/libc/src/math/generic/totalordermagf128.cpp
index dfb6c794b0f1d..a938c87f70135 100644
--- a/libc/src/math/generic/totalordermagf128.cpp
+++ b/libc/src/math/generic/totalordermagf128.cpp
@@ -1,19 +1,29 @@
-//===-- Implementation of totalordermagf128 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation of totalordermagf128 function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermagf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/totalordermagf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(int, totalordermagf128,
                    (const float128 *x, const float128 *y)) {
-  return math::totalordermagf128(x, y);
+  Float128 x_f128 = cpp::bit_cast<Float128>(*x);
+  Float128 y_f128 = cpp::bit_cast<Float128>(*y);
+  return math::totalordermagf128(&x_f128, &y_f128);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/totalorderf128.h b/libc/src/math/totalorderf128.h
index 958714849da67..baa711bf69e86 100644
--- a/libc/src/math/totalorderf128.h
+++ b/libc/src/math/totalorderf128.h
@@ -1,19 +1,29 @@
-//===-- Implementation header for totalorderf128 ----------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation header for totalorderf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_MATH_TOTALORDERF128_H
 #define LLVM_LIBC_SRC_MATH_TOTALORDERF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 int totalorderf128(const float128 *x, const float128 *y);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/totalordermagf128.h b/libc/src/math/totalordermagf128.h
index 389d0596b9d4b..bdf99c7404e42 100644
--- a/libc/src/math/totalordermagf128.h
+++ b/libc/src/math/totalordermagf128.h
@@ -1,19 +1,29 @@
-//===-- Implementation header for totalordermagf128 -------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation header for totalordermagf128.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_MATH_TOTALORDERMAGF128_H
 #define LLVM_LIBC_SRC_MATH_TOTALORDERMAGF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 int totalordermagf128(const float128 *x, const float128 *y);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index ec7f99a9ff40c..4528f86359c07 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for shared math functions in constexpr context ----------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains unittests for shared math functions in constexpr context.
+///
+//===----------------------------------------------------------------------===//
 
 #define LIBC_ENABLE_CONSTEXPR 1
 
@@ -451,6 +456,15 @@ static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
+constexpr Float128 TOTALORDERF128_X = Float128(0.0);
+constexpr Float128 TOTALORDERF128_Y = Float128(0.0);
+static_assert(1 == LIBC_NAMESPACE::shared::totalorderf128(&TOTALORDERF128_X,
+                                                          &TOTALORDERF128_Y));
+constexpr Float128 TOTALORDERMAGF128_X = Float128(0.0);
+constexpr Float128 TOTALORDERMAGF128_Y = Float128(0.0);
+static_assert(1 ==
+              LIBC_NAMESPACE::shared::totalordermagf128(&TOTALORDERMAGF128_X,
+                                                        &TOTALORDERMAGF128_Y));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::truncf128(Float128(0.0)));
 
@@ -490,15 +504,6 @@ static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::ufromfpf128(float128(0.0), 0, 32));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::ufromfpxf128(float128(0.0), 0, 32));
-constexpr float128 TOTALORDERF128_X = float128(0.0);
-constexpr float128 TOTALORDERF128_Y = float128(0.0);
-static_assert(1 == LIBC_NAMESPACE::shared::totalorderf128(&TOTALORDERF128_X,
-                                                          &TOTALORDERF128_Y));
-constexpr float128 TOTALORDERMAGF128_X = float128(0.0);
-constexpr float128 TOTALORDERMAGF128_Y = float128(0.0);
-static_assert(1 ==
-              LIBC_NAMESPACE::shared::totalordermagf128(&TOTALORDERMAGF128_X,
-                                                        &TOTALORDERMAGF128_Y));
 static_assert(0 ==
               LIBC_NAMESPACE::shared::fmodf128(float128(4.0), float128(2.0)));
 static_assert(float128(0.0) == [] {
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7b785331f36c6..40723ccb7e8a3 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for shared math functions -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains unittests for shared math functions.
+///
+//===----------------------------------------------------------------------===//
 
 #include "shared/math.h"
 #include "src/__support/FPUtil/float128.h"
@@ -624,6 +629,14 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
                LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(1.0), LIBC_NAMESPACE::shared::sqrtf128(Float128(1.0)));
+  Float128 totalorderf128_x = Float128(0.0);
+  Float128 totalorderf128_y = Float128(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalorderf128(&totalorderf128_x,
+                                                      &totalorderf128_y));
+  Float128 totalordermagf128_x = Float128(0.0);
+  Float128 totalordermagf128_y = Float128(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf128(&totalordermagf128_x,
+                                                         &totalordermagf128_y));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::truncf128(Float128(0.0)));
 }
 
@@ -726,14 +739,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                LIBC_NAMESPACE::shared::ufromfpf128(float128(0.0), 0, 32));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::ufromfpxf128(float128(0.0), 0, 32));
-  float128 totalorderf128_x = float128(0.0);
-  float128 totalorderf128_y = float128(0.0);
-  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalorderf128(&totalorderf128_x,
-                                                      &totalorderf128_y));
-  float128 totalordermagf128_x = float128(0.0);
-  float128 totalordermagf128_y = float128(0.0);
-  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf128(&totalordermagf128_x,
-                                                         &totalordermagf128_y));
   LIBC_NAMESPACE::shared::fmodf128(float128(1.0), float128(1.0));
   float128 modff128_iptr = float128(0.0);
   EXPECT_FP_EQ(float128(0.0),
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 0bfe73a2e643a..92e4f3e02d636 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5424,6 +5424,7 @@ add_fp_unittest(
     TotalOrderTest.h
   DEPENDS
     libc.src.math.totalorderf128
+    libc.src.__support.FPUtil.float128
 )
 
 add_fp_unittest(
@@ -5497,6 +5498,7 @@ add_fp_unittest(
     TotalOrderMagTest.h
   DEPENDS
     libc.src.math.totalordermagf128
+    libc.src.__support.FPUtil.float128
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/smoke/totalorderf128_test.cpp b/libc/test/src/math/smoke/totalorderf128_test.cpp
index 3696b54114c5c..311c4b5caa29d 100644
--- a/libc/test/src/math/smoke/totalorderf128_test.cpp
+++ b/libc/test/src/math/smoke/totalorderf128_test.cpp
@@ -1,13 +1,23 @@
-//===-- Unittests for totalorderf128 --------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for totalorderf128.
+///
+//===----------------------------------------------------------------------===//
 
 #include "TotalOrderTest.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/totalorderf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_TOTALORDER_TESTS(Totalorderf128, float128, LIBC_NAMESPACE::totalorderf128)
diff --git a/libc/test/src/math/smoke/totalordermagf128_test.cpp b/libc/test/src/math/smoke/totalordermagf128_test.cpp
index 613ed57fc2223..92d84232c4448 100644
--- a/libc/test/src/math/smoke/totalordermagf128_test.cpp
+++ b/libc/test/src/math/smoke/totalordermagf128_test.cpp
@@ -1,14 +1,24 @@
-//===-- Unittests for totalordermagf128 -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for totalordermagf128.
+///
+//===----------------------------------------------------------------------===//
 
 #include "TotalOrderMagTest.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/totalordermagf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_TOTALORDERMAG_TESTS(Totalordermagf128, float128,
                          LIBC_NAMESPACE::totalordermagf128)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 33fc35455fef3..62d9d504170b5 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11124,8 +11124,8 @@ libc_support_library(
     hdrs = ["src/__support/math/totalorderf128.h"],
     deps = [
         ":__support_fputil_basic_operations",
+        ":__support_fputil_float128",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -11181,8 +11181,8 @@ libc_support_library(
     hdrs = ["src/__support/math/totalordermagf128.h"],
     deps = [
         ":__support_fputil_basic_operations",
+        ":__support_fputil_float128",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -14959,6 +14959,8 @@ libc_math_function(
 libc_math_function(
     name = "totalorderf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_totalorderf128",
     ],
 )
@@ -15001,6 +15003,8 @@ libc_math_function(
 libc_math_function(
     name = "totalordermagf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_totalordermagf128",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 0a79dcd33a587..56417eed0cb28 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -2161,6 +2161,9 @@ math_test(
 math_test(
     name = "totalorderf128",
     hdrs = ["TotalOrderTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(
@@ -2194,6 +2197,9 @@ math_test(
 math_test(
     name = "totalordermagf128",
     hdrs = ["TotalOrderMagTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(



More information about the libc-commits mailing list