[libc-commits] [libc] [llvm] [libc][math] Refactor totalorder family to header-only (PR #195399)

via libc-commits libc-commits at lists.llvm.org
Fri May 1 20:31:57 PDT 2026


https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/195399

>From 52e291fa086987879f0f7e82c535d391beaf3822 Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Sat, 2 May 2026 04:30:34 +0300
Subject: [PATCH] [libc][math] Refactor totalorder family to header-only

Refactored functions:
  - totalorder
  - totalorderbf16
  - totalorderf
  - totalorderf128
  - totalorderf16
  - totalorderl
  - totalordermag
  - totalordermagbf16
  - totalordermagf
  - totalordermagf128
  - totalordermagf16
  - totalordermagl
---
 libc/shared/math.h                            |  12 ++
 libc/shared/math/totalorder.h                 |  23 +++
 libc/shared/math/totalorderbf16.h             |  23 +++
 libc/shared/math/totalorderf.h                |  23 +++
 libc/shared/math/totalorderf128.h             |  29 +++
 libc/shared/math/totalorderf16.h              |  29 +++
 libc/shared/math/totalorderl.h                |  23 +++
 libc/shared/math/totalordermag.h              |  23 +++
 libc/shared/math/totalordermagbf16.h          |  23 +++
 libc/shared/math/totalordermagf.h             |  23 +++
 libc/shared/math/totalordermagf128.h          |  29 +++
 libc/shared/math/totalordermagf16.h           |  29 +++
 libc/shared/math/totalordermagl.h             |  23 +++
 libc/src/__support/math/CMakeLists.txt        | 114 +++++++++++
 libc/src/__support/math/totalorder.h          |  25 +++
 libc/src/__support/math/totalorderbf16.h      |  26 +++
 libc/src/__support/math/totalorderf.h         |  25 +++
 libc/src/__support/math/totalorderf128.h      |  31 +++
 libc/src/__support/math/totalorderf16.h       |  31 +++
 libc/src/__support/math/totalorderl.h         |  26 +++
 libc/src/__support/math/totalordermag.h       |  25 +++
 libc/src/__support/math/totalordermagbf16.h   |  27 +++
 libc/src/__support/math/totalordermagf.h      |  25 +++
 libc/src/__support/math/totalordermagf128.h   |  32 +++
 libc/src/__support/math/totalordermagf16.h    |  31 +++
 libc/src/__support/math/totalordermagl.h      |  26 +++
 libc/src/math/generic/CMakeLists.txt          |  34 ++--
 libc/src/math/generic/totalorder.cpp          |   6 +-
 libc/src/math/generic/totalorderbf16.cpp      |   7 +-
 libc/src/math/generic/totalorderf.cpp         |   6 +-
 libc/src/math/generic/totalorderf128.cpp      |   6 +-
 libc/src/math/generic/totalorderf16.cpp       |   6 +-
 libc/src/math/generic/totalorderl.cpp         |   6 +-
 libc/src/math/generic/totalordermag.cpp       |   6 +-
 libc/src/math/generic/totalordermagbf16.cpp   |   7 +-
 libc/src/math/generic/totalordermagf.cpp      |   6 +-
 libc/src/math/generic/totalordermagf128.cpp   |   6 +-
 libc/src/math/generic/totalordermagf16.cpp    |   6 +-
 libc/src/math/generic/totalordermagl.cpp      |   6 +-
 libc/test/shared/CMakeLists.txt               |  24 +++
 libc/test/shared/shared_math_test.cpp         |  48 +++++
 .../llvm-project-overlay/libc/BUILD.bazel     | 182 +++++++++++++++++-
 42 files changed, 1040 insertions(+), 78 deletions(-)
 create mode 100644 libc/shared/math/totalorder.h
 create mode 100644 libc/shared/math/totalorderbf16.h
 create mode 100644 libc/shared/math/totalorderf.h
 create mode 100644 libc/shared/math/totalorderf128.h
 create mode 100644 libc/shared/math/totalorderf16.h
 create mode 100644 libc/shared/math/totalorderl.h
 create mode 100644 libc/shared/math/totalordermag.h
 create mode 100644 libc/shared/math/totalordermagbf16.h
 create mode 100644 libc/shared/math/totalordermagf.h
 create mode 100644 libc/shared/math/totalordermagf128.h
 create mode 100644 libc/shared/math/totalordermagf16.h
 create mode 100644 libc/shared/math/totalordermagl.h
 create mode 100644 libc/src/__support/math/totalorder.h
 create mode 100644 libc/src/__support/math/totalorderbf16.h
 create mode 100644 libc/src/__support/math/totalorderf.h
 create mode 100644 libc/src/__support/math/totalorderf128.h
 create mode 100644 libc/src/__support/math/totalorderf16.h
 create mode 100644 libc/src/__support/math/totalorderl.h
 create mode 100644 libc/src/__support/math/totalordermag.h
 create mode 100644 libc/src/__support/math/totalordermagbf16.h
 create mode 100644 libc/src/__support/math/totalordermagf.h
 create mode 100644 libc/src/__support/math/totalordermagf128.h
 create mode 100644 libc/src/__support/math/totalordermagf16.h
 create mode 100644 libc/src/__support/math/totalordermagl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 5af95da3ef92f..ae4e473219868 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -347,5 +347,17 @@
 #include "math/ufromfpxf128.h"
 #include "math/ufromfpxf16.h"
 #include "math/ufromfpxl.h"
+#include "math/totalorder.h"
+#include "math/totalorderbf16.h"
+#include "math/totalorderf.h"
+#include "math/totalorderf128.h"
+#include "math/totalorderf16.h"
+#include "math/totalorderl.h"
+#include "math/totalordermag.h"
+#include "math/totalordermagbf16.h"
+#include "math/totalordermagf.h"
+#include "math/totalordermagf128.h"
+#include "math/totalordermagf16.h"
+#include "math/totalordermagl.h"
 
 #endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/totalorder.h b/libc/shared/math/totalorder.h
new file mode 100644
index 0000000000000..80981d223db5f
--- /dev/null
+++ b/libc/shared/math/totalorder.h
@@ -0,0 +1,23 @@
+//===-- Shared totalorder 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDER_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDER_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalorder.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalorder;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDER_H
diff --git a/libc/shared/math/totalorderbf16.h b/libc/shared/math/totalorderbf16.h
new file mode 100644
index 0000000000000..42557963e4999
--- /dev/null
+++ b/libc/shared/math/totalorderbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared totalorderbf16 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERBF16_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalorderbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalorderbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERBF16_H
diff --git a/libc/shared/math/totalorderf.h b/libc/shared/math/totalorderf.h
new file mode 100644
index 0000000000000..8f98050322ae3
--- /dev/null
+++ b/libc/shared/math/totalorderf.h
@@ -0,0 +1,23 @@
+//===-- Shared totalorderf 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERF_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalorderf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalorderf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERF_H
diff --git a/libc/shared/math/totalorderf128.h b/libc/shared/math/totalorderf128.h
new file mode 100644
index 0000000000000..fe1d1d4dcbc0e
--- /dev/null
+++ b/libc/shared/math/totalorderf128.h
@@ -0,0 +1,29 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+
+#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_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalorderf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalorderf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERF128_H
diff --git a/libc/shared/math/totalorderf16.h b/libc/shared/math/totalorderf16.h
new file mode 100644
index 0000000000000..6b0b0d929c288
--- /dev/null
+++ b/libc/shared/math/totalorderf16.h
@@ -0,0 +1,29 @@
+//===-- Shared totalorderf16 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERF16_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalorderf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalorderf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERF16_H
diff --git a/libc/shared/math/totalorderl.h b/libc/shared/math/totalorderl.h
new file mode 100644
index 0000000000000..96486278ced48
--- /dev/null
+++ b/libc/shared/math/totalorderl.h
@@ -0,0 +1,23 @@
+//===-- Shared totalorderl 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERL_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalorderl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalorderl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERL_H
diff --git a/libc/shared/math/totalordermag.h b/libc/shared/math/totalordermag.h
new file mode 100644
index 0000000000000..4111f03cc671b
--- /dev/null
+++ b/libc/shared/math/totalordermag.h
@@ -0,0 +1,23 @@
+//===-- Shared totalordermag 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERMAG_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERMAG_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalordermag.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalordermag;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAG_H
diff --git a/libc/shared/math/totalordermagbf16.h b/libc/shared/math/totalordermagbf16.h
new file mode 100644
index 0000000000000..4652055b1b454
--- /dev/null
+++ b/libc/shared/math/totalordermagbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared totalordermagbf16 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERMAGBF16_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERMAGBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalordermagbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalordermagbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAGBF16_H
diff --git a/libc/shared/math/totalordermagf.h b/libc/shared/math/totalordermagf.h
new file mode 100644
index 0000000000000..a2aa76c24040c
--- /dev/null
+++ b/libc/shared/math/totalordermagf.h
@@ -0,0 +1,23 @@
+//===-- Shared totalordermagf 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalordermagf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalordermagf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF_H
diff --git a/libc/shared/math/totalordermagf128.h b/libc/shared/math/totalordermagf128.h
new file mode 100644
index 0000000000000..c8f541d7c7269
--- /dev/null
+++ b/libc/shared/math/totalordermagf128.h
@@ -0,0 +1,29 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+
+#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_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalordermagf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalordermagf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF128_H
diff --git a/libc/shared/math/totalordermagf16.h b/libc/shared/math/totalordermagf16.h
new file mode 100644
index 0000000000000..a63380a700017
--- /dev/null
+++ b/libc/shared/math/totalordermagf16.h
@@ -0,0 +1,29 @@
+//===-- Shared totalordermagf16 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF16_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalordermagf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalordermagf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAGF16_H
diff --git a/libc/shared/math/totalordermagl.h b/libc/shared/math/totalordermagl.h
new file mode 100644
index 0000000000000..05f78c72f4e58
--- /dev/null
+++ b/libc/shared/math/totalordermagl.h
@@ -0,0 +1,23 @@
+//===-- Shared totalordermagl 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_TOTALORDERMAGL_H
+#define LLVM_LIBC_SHARED_MATH_TOTALORDERMAGL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/totalordermagl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::totalordermagl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TOTALORDERMAGL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 82f0706df6ee5..e930751e71f0b 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4084,6 +4084,120 @@ add_header_library(
     libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  totalorder
+  HDRS
+    totalorder.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalorderbf16
+  HDRS
+    totalorderbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalorderf
+  HDRS
+    totalorderf.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalorderf128
+  HDRS
+    totalorderf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalorderf16
+  HDRS
+    totalorderf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalorderl
+  HDRS
+    totalorderl.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalordermag
+  HDRS
+    totalordermag.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalordermagbf16
+  HDRS
+    totalordermagbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalordermagf
+  HDRS
+    totalordermagf.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalordermagf128
+  HDRS
+    totalordermagf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalordermagf16
+  HDRS
+    totalordermagf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  totalordermagl
+  HDRS
+    totalordermagl.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   ufromfp
   HDRS
diff --git a/libc/src/__support/math/totalorder.h b/libc/src/__support/math/totalorder.h
new file mode 100644
index 0000000000000..eb217842dfb97
--- /dev/null
+++ b/libc/src/__support/math/totalorder.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for totalorder --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDER_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDER_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalorder(const double *x, const double *y) {
+  return static_cast<int>(fputil::totalorder(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDER_H
diff --git a/libc/src/__support/math/totalorderbf16.h b/libc/src/__support/math/totalorderbf16.h
new file mode 100644
index 0000000000000..9d2cb9720569e
--- /dev/null
+++ b/libc/src/__support/math/totalorderbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for totalorderbf16 ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalorderbf16(const bfloat16 *x, const bfloat16 *y) {
+  return static_cast<int>(fputil::totalorder(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERBF16_H
diff --git a/libc/src/__support/math/totalorderf.h b/libc/src/__support/math/totalorderf.h
new file mode 100644
index 0000000000000..188d48219a368
--- /dev/null
+++ b/libc/src/__support/math/totalorderf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for totalorderf -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalorderf(const float *x, const float *y) {
+  return static_cast<int>(fputil::totalorder(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF_H
diff --git a/libc/src/__support/math/totalorderf128.h b/libc/src/__support/math/totalorderf128.h
new file mode 100644
index 0000000000000..e1f36af36d89e
--- /dev/null
+++ b/libc/src/__support/math/totalorderf128.h
@@ -0,0 +1,31 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+
+#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_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+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_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF128_H
diff --git a/libc/src/__support/math/totalorderf16.h b/libc/src/__support/math/totalorderf16.h
new file mode 100644
index 0000000000000..b22f57f78eb2f
--- /dev/null
+++ b/libc/src/__support/math/totalorderf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for totalorderf16 -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalorderf16(const float16 *x, const float16 *y) {
+  return static_cast<int>(fputil::totalorder(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERF16_H
diff --git a/libc/src/__support/math/totalorderl.h b/libc/src/__support/math/totalorderl.h
new file mode 100644
index 0000000000000..77b2441461f1f
--- /dev/null
+++ b/libc/src/__support/math/totalorderl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for totalorderl -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalorderl(const long double *x,
+                                      const long double *y) {
+  return static_cast<int>(fputil::totalorder(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERL_H
diff --git a/libc/src/__support/math/totalordermag.h b/libc/src/__support/math/totalordermag.h
new file mode 100644
index 0000000000000..c8bc57424ac5e
--- /dev/null
+++ b/libc/src/__support/math/totalordermag.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for totalordermag -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAG_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAG_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalordermag(const double *x, const double *y) {
+  return static_cast<int>(fputil::totalordermag(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAG_H
diff --git a/libc/src/__support/math/totalordermagbf16.h b/libc/src/__support/math/totalordermagbf16.h
new file mode 100644
index 0000000000000..cf5fe12095673
--- /dev/null
+++ b/libc/src/__support/math/totalordermagbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for totalordermagbf16 -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalordermagbf16(const bfloat16 *x,
+                                            const bfloat16 *y) {
+  return static_cast<int>(fputil::totalordermag(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGBF16_H
diff --git a/libc/src/__support/math/totalordermagf.h b/libc/src/__support/math/totalordermagf.h
new file mode 100644
index 0000000000000..523fee21494b1
--- /dev/null
+++ b/libc/src/__support/math/totalordermagf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for totalordermagf ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalordermagf(const float *x, const float *y) {
+  return static_cast<int>(fputil::totalordermag(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF_H
diff --git a/libc/src/__support/math/totalordermagf128.h b/libc/src/__support/math/totalordermagf128.h
new file mode 100644
index 0000000000000..2c59a8ba30ea2
--- /dev/null
+++ b/libc/src/__support/math/totalordermagf128.h
@@ -0,0 +1,32 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+
+#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_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+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_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF128_H
diff --git a/libc/src/__support/math/totalordermagf16.h b/libc/src/__support/math/totalordermagf16.h
new file mode 100644
index 0000000000000..e6713a0566805
--- /dev/null
+++ b/libc/src/__support/math/totalordermagf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for totalordermagf16 --------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalordermagf16(const float16 *x, const float16 *y) {
+  return static_cast<int>(fputil::totalordermag(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGF16_H
diff --git a/libc/src/__support/math/totalordermagl.h b/libc/src/__support/math/totalordermagl.h
new file mode 100644
index 0000000000000..db979441b22d2
--- /dev/null
+++ b/libc/src/__support/math/totalordermagl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for totalordermagl ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr int totalordermagl(const long double *x,
+                                         const long double *y) {
+  return static_cast<int>(fputil::totalordermag(*x, *y));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_TOTALORDERMAGL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index fdfe97e8e7225..54147d0a6ea22 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4323,7 +4323,7 @@ add_entrypoint_object(
   HDRS
     ../totalorder.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalorder
 )
 
 add_entrypoint_object(
@@ -4333,7 +4333,7 @@ add_entrypoint_object(
   HDRS
     ../totalorderf.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalorderf
 )
 
 add_entrypoint_object(
@@ -4343,7 +4343,7 @@ add_entrypoint_object(
   HDRS
     ../totalorderl.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalorderl
 )
 
 add_entrypoint_object(
@@ -4353,7 +4353,7 @@ add_entrypoint_object(
   HDRS
     ../totalorderf16.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalorderf16
 )
 
 add_entrypoint_object(
@@ -4363,8 +4363,7 @@ add_entrypoint_object(
   HDRS
     ../totalorderf128.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
-    libc.src.__support.macros.properties.types
+    libc.src.__support.math.totalorderf128
 )
 
 add_entrypoint_object(
@@ -4374,11 +4373,7 @@ add_entrypoint_object(
   HDRS
     ../totalorderbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.basic_operations
-    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.math.totalorderbf16
 )
 
 add_entrypoint_object(
@@ -4388,7 +4383,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermag.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalordermag
 )
 
 add_entrypoint_object(
@@ -4398,7 +4393,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermagf.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalordermagf
 )
 
 add_entrypoint_object(
@@ -4408,7 +4403,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermagl.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalordermagl
 )
 
 add_entrypoint_object(
@@ -4418,7 +4413,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermagf16.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.totalordermagf16
 )
 
 add_entrypoint_object(
@@ -4428,8 +4423,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermagf128.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
-    libc.src.__support.macros.properties.types
+    libc.src.__support.math.totalordermagf128
 )
 
 add_entrypoint_object(
@@ -4439,11 +4433,7 @@ add_entrypoint_object(
   HDRS
     ../totalordermagbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.basic_operations
-    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.math.totalordermagbf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/totalorder.cpp b/libc/src/math/generic/totalorder.cpp
index f052c81c98fa9..9aa349cb65ba1 100644
--- a/libc/src/math/generic/totalorder.cpp
+++ b/libc/src/math/generic/totalorder.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalorder.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalorder.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalorder, (const double *x, const double *y)) {
-  return static_cast<int>(fputil::totalorder(*x, *y));
+  return math::totalorder(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalorderbf16.cpp b/libc/src/math/generic/totalorderbf16.cpp
index bb9c86e281f6b..9aad282adb559 100644
--- a/libc/src/math/generic/totalorderbf16.cpp
+++ b/libc/src/math/generic/totalorderbf16.cpp
@@ -7,16 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalorderbf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalorderbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalorderbf16,
                    (const bfloat16 *x, const bfloat16 *y)) {
-  return static_cast<int>(fputil::totalorder(*x, *y));
+  return math::totalorderbf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalorderf.cpp b/libc/src/math/generic/totalorderf.cpp
index 17c1304072175..5bba048a99fed 100644
--- a/libc/src/math/generic/totalorderf.cpp
+++ b/libc/src/math/generic/totalorderf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalorderf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalorderf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalorderf, (const float *x, const float *y)) {
-  return static_cast<int>(fputil::totalorder(*x, *y));
+  return math::totalorderf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalorderf128.cpp b/libc/src/math/generic/totalorderf128.cpp
index 83d77686d212a..ca521291e4924 100644
--- a/libc/src/math/generic/totalorderf128.cpp
+++ b/libc/src/math/generic/totalorderf128.cpp
@@ -7,15 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalorderf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalorderf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalorderf128,
                    (const float128 *x, const float128 *y)) {
-  return static_cast<int>(fputil::totalorder(*x, *y));
+  return math::totalorderf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalorderf16.cpp b/libc/src/math/generic/totalorderf16.cpp
index 743aa5a55db55..f3b03b1f0829f 100644
--- a/libc/src/math/generic/totalorderf16.cpp
+++ b/libc/src/math/generic/totalorderf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalorderf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalorderf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalorderf16, (const float16 *x, const float16 *y)) {
-  return static_cast<int>(fputil::totalorder(*x, *y));
+  return math::totalorderf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalorderl.cpp b/libc/src/math/generic/totalorderl.cpp
index 1aae1c6cd025a..c0ec8bc925a69 100644
--- a/libc/src/math/generic/totalorderl.cpp
+++ b/libc/src/math/generic/totalorderl.cpp
@@ -7,15 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalorderl.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalorderl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalorderl,
                    (const long double *x, const long double *y)) {
-  return static_cast<int>(fputil::totalorder(*x, *y));
+  return math::totalorderl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermag.cpp b/libc/src/math/generic/totalordermag.cpp
index fb8215cad68fe..377fbbac7721e 100644
--- a/libc/src/math/generic/totalordermag.cpp
+++ b/libc/src/math/generic/totalordermag.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermag.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalordermag.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalordermag, (const double *x, const double *y)) {
-  return static_cast<int>(fputil::totalordermag(*x, *y));
+  return math::totalordermag(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagbf16.cpp b/libc/src/math/generic/totalordermagbf16.cpp
index 3fc61d9d8bcb4..b9badc61671f2 100644
--- a/libc/src/math/generic/totalordermagbf16.cpp
+++ b/libc/src/math/generic/totalordermagbf16.cpp
@@ -7,16 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermagbf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalordermagbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalordermagbf16,
                    (const bfloat16 *x, const bfloat16 *y)) {
-  return static_cast<int>(fputil::totalordermag(*x, *y));
+  return math::totalordermagbf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagf.cpp b/libc/src/math/generic/totalordermagf.cpp
index 6b93bac51d0fb..d2ea915beba3f 100644
--- a/libc/src/math/generic/totalordermagf.cpp
+++ b/libc/src/math/generic/totalordermagf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermagf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalordermagf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalordermagf, (const float *x, const float *y)) {
-  return static_cast<int>(fputil::totalordermag(*x, *y));
+  return math::totalordermagf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagf128.cpp b/libc/src/math/generic/totalordermagf128.cpp
index b32abfa8d09b1..dfb6c794b0f1d 100644
--- a/libc/src/math/generic/totalordermagf128.cpp
+++ b/libc/src/math/generic/totalordermagf128.cpp
@@ -7,15 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermagf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalordermagf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalordermagf128,
                    (const float128 *x, const float128 *y)) {
-  return static_cast<int>(fputil::totalordermag(*x, *y));
+  return math::totalordermagf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagf16.cpp b/libc/src/math/generic/totalordermagf16.cpp
index 0d2e9e174f522..b76cf296aea42 100644
--- a/libc/src/math/generic/totalordermagf16.cpp
+++ b/libc/src/math/generic/totalordermagf16.cpp
@@ -7,15 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermagf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalordermagf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalordermagf16,
                    (const float16 *x, const float16 *y)) {
-  return static_cast<int>(fputil::totalordermag(*x, *y));
+  return math::totalordermagf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagl.cpp b/libc/src/math/generic/totalordermagl.cpp
index 49eed62bf99eb..31114c293d1f0 100644
--- a/libc/src/math/generic/totalordermagl.cpp
+++ b/libc/src/math/generic/totalordermagl.cpp
@@ -7,15 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/totalordermagl.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/totalordermagl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, totalordermagl,
                    (const long double *x, const long double *y)) {
-  return static_cast<int>(fputil::totalordermag(*x, *y));
+  return math::totalordermagl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 40e5aed322401..8150b8c413071 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -345,6 +345,18 @@ add_fp_unittest(
     libc.src.__support.math.ufromfpxf128
     libc.src.__support.math.ufromfpxf16
     libc.src.__support.math.ufromfpxl
+    libc.src.__support.math.totalorder
+    libc.src.__support.math.totalorderbf16
+    libc.src.__support.math.totalorderf
+    libc.src.__support.math.totalorderf128
+    libc.src.__support.math.totalorderf16
+    libc.src.__support.math.totalorderl
+    libc.src.__support.math.totalordermag
+    libc.src.__support.math.totalordermagbf16
+    libc.src.__support.math.totalordermagf
+    libc.src.__support.math.totalordermagf128
+    libc.src.__support.math.totalordermagf16
+    libc.src.__support.math.totalordermagl
 )
 
 add_fp_unittest(
@@ -456,6 +468,18 @@ add_fp_unittest(
     libc.src.__support.math.ufromfpxf128
     libc.src.__support.math.ufromfpxf16
     libc.src.__support.math.ufromfpxl
+    libc.src.__support.math.totalorder
+    libc.src.__support.math.totalorderbf16
+    libc.src.__support.math.totalorderf
+    libc.src.__support.math.totalorderf128
+    libc.src.__support.math.totalorderf16
+    libc.src.__support.math.totalorderl
+    libc.src.__support.math.totalordermag
+    libc.src.__support.math.totalordermagbf16
+    libc.src.__support.math.totalordermagf
+    libc.src.__support.math.totalordermagf128
+    libc.src.__support.math.totalordermagf16
+    libc.src.__support.math.totalordermagl
 )
 
 add_fp_unittest(
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index ca8934f2b07d0..59015ff494134 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -116,6 +116,14 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
                LIBC_NAMESPACE::shared::fmaximum_magf16(0.0f16, 0.0f16));
   EXPECT_FP_EQ(0x0p+0f16,
                LIBC_NAMESPACE::shared::fminimum_magf16(0.0f16, 0.0f16));
+  float16 totalorderf16_x = 0.0f16;
+  float16 totalorderf16_y = 0.0f16;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalorderf16(&totalorderf16_x,
+                                                     &totalorderf16_y));
+  float16 totalordermagf16_x = 0.0f16;
+  float16 totalordermagf16_y = 0.0f16;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf16(&totalordermagf16_x,
+                                                        &totalordermagf16_y));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -236,6 +244,14 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::ufromfpxf(0.0f, 0, 32));
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmaximum_magf(0.0f, 0.0f));
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fminimum_magf(0.0f, 0.0f));
+  float totalorderf_x = 0.0f;
+  float totalorderf_y = 0.0f;
+  EXPECT_EQ(
+      1, LIBC_NAMESPACE::shared::totalorderf(&totalorderf_x, &totalorderf_y));
+  float totalordermagf_x = 0.0f;
+  float totalordermagf_y = 0.0f;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagf(&totalordermagf_x,
+                                                      &totalordermagf_y));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -332,6 +348,14 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::ufromfpx(0.0, 0, 32));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmaximum_mag(0.0, 0.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fminimum_mag(0.0, 0.0));
+  double totalorder_x = 0.0;
+  double totalorder_y = 0.0;
+  EXPECT_EQ(1,
+            LIBC_NAMESPACE::shared::totalorder(&totalorder_x, &totalorder_y));
+  double totalordermag_x = 0.0;
+  double totalordermag_y = 0.0;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermag(&totalordermag_x,
+                                                     &totalordermag_y));
 }
 
 // TODO: Enable the tests when double-double type is supported.
@@ -409,6 +433,14 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::ufromfpxl(0.0L, 0, 32));
   EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmaximum_magl(0.0L, 0.0L));
   EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fminimum_magl(0.0L, 0.0L));
+  long double totalorderl_x = 0.0L;
+  long double totalorderl_y = 0.0L;
+  EXPECT_EQ(
+      1, LIBC_NAMESPACE::shared::totalorderl(&totalorderl_x, &totalorderl_y));
+  long double totalordermagl_x = 0.0L;
+  long double totalordermagl_y = 0.0L;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagl(&totalordermagl_x,
+                                                      &totalordermagl_y));
 }
 
 #endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
@@ -535,6 +567,14 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                                   float128(0.0), float128(0.0)));
   EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::fminimum_magf128(
                                   float128(0.0), float128(0.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));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -624,4 +664,12 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
                                   bfloat16(0.0), bfloat16(0.0)));
   EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::fminimum_magbf16(
                                   bfloat16(0.0), bfloat16(0.0)));
+  bfloat16 totalorderbf16_x = bfloat16(0.0);
+  bfloat16 totalorderbf16_y = bfloat16(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalorderbf16(&totalorderbf16_x,
+                                                      &totalorderbf16_y));
+  bfloat16 totalordermagbf16_x = bfloat16(0.0);
+  bfloat16 totalordermagbf16_y = bfloat16(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::totalordermagbf16(&totalordermagbf16_x,
+                                                         &totalordermagbf16_y));
 }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 031286d5119fe..238cfae172ad4 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -7149,6 +7149,120 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_totalorder",
+    hdrs = ["src/__support/math/totalorder.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalorderbf16",
+    hdrs = ["src/__support/math/totalorderbf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_fputil_bfloat16",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalorderf",
+    hdrs = ["src/__support/math/totalorderf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalorderf128",
+    hdrs = ["src/__support/math/totalorderf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalorderf16",
+    hdrs = ["src/__support/math/totalorderf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalorderl",
+    hdrs = ["src/__support/math/totalorderl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalordermag",
+    hdrs = ["src/__support/math/totalordermag.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalordermagbf16",
+    hdrs = ["src/__support/math/totalordermagbf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_fputil_bfloat16",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalordermagf",
+    hdrs = ["src/__support/math/totalordermagf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalordermagf128",
+    hdrs = ["src/__support/math/totalordermagf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalordermagf16",
+    hdrs = ["src/__support/math/totalordermagf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_totalordermagl",
+    hdrs = ["src/__support/math/totalordermagl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ufromfp",
     hdrs = ["src/__support/math/ufromfp.h"],
@@ -10093,32 +10207,88 @@ libc_math_function(
     additional_deps = [":__support_math_tanpif16"],
 )
 
-libc_math_function(name = "totalorder")
+libc_math_function(
+    name = "totalorder",
+    additional_deps = [
+        ":__support_math_totalorder",
+    ],
+)
+
+libc_math_function(
+    name = "totalorderbf16",
+    additional_deps = [
+        ":__support_math_totalorderbf16",
+    ],
+)
 
-libc_math_function(name = "totalorderf")
+libc_math_function(
+    name = "totalorderf",
+    additional_deps = [
+        ":__support_math_totalorderf",
+    ],
+)
 
-libc_math_function(name = "totalorderl")
+libc_math_function(
+    name = "totalorderl",
+    additional_deps = [
+        ":__support_math_totalorderl",
+    ],
+)
 
 libc_math_function(
     name = "totalorderf128",
+    additional_deps = [
+        ":__support_math_totalorderf128",
+    ],
 )
 
 libc_math_function(
     name = "totalorderf16",
+    additional_deps = [
+        ":__support_math_totalorderf16",
+    ],
 )
 
-libc_math_function(name = "totalordermag")
+libc_math_function(
+    name = "totalordermag",
+    additional_deps = [
+        ":__support_math_totalordermag",
+    ],
+)
 
-libc_math_function(name = "totalordermagf")
+libc_math_function(
+    name = "totalordermagbf16",
+    additional_deps = [
+        ":__support_math_totalordermagbf16",
+    ],
+)
+
+libc_math_function(
+    name = "totalordermagf",
+    additional_deps = [
+        ":__support_math_totalordermagf",
+    ],
+)
 
-libc_math_function(name = "totalordermagl")
+libc_math_function(
+    name = "totalordermagl",
+    additional_deps = [
+        ":__support_math_totalordermagl",
+    ],
+)
 
 libc_math_function(
     name = "totalordermagf128",
+    additional_deps = [
+        ":__support_math_totalordermagf128",
+    ],
 )
 
 libc_math_function(
     name = "totalordermagf16",
+    additional_deps = [
+        ":__support_math_totalordermagf16",
+    ],
 )
 
 libc_math_function(name = "trunc")



More information about the libc-commits mailing list