[libc-commits] [libc] [libc][math][c23] Add fsub{, l, f128} and remainderf128 C23 math functions (PR #101576)

via libc-commits libc-commits at lists.llvm.org
Wed Aug 7 10:52:13 PDT 2024


https://github.com/aaryanshukla updated https://github.com/llvm/llvm-project/pull/101576

>From 00592adf7ff01bf264cd59f6155ce351249986d7 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Thu, 1 Aug 2024 18:01:21 +0000
Subject: [PATCH 01/23] script

---
 libc/llvm_libc_add_math_function.py | 161 ++++++++++++++++++++++++++++
 1 file changed, 161 insertions(+)
 create mode 100755 libc/llvm_libc_add_math_function.py

diff --git a/libc/llvm_libc_add_math_function.py b/libc/llvm_libc_add_math_function.py
new file mode 100755
index 0000000000000..810543570ffc1
--- /dev/null
+++ b/libc/llvm_libc_add_math_function.py
@@ -0,0 +1,161 @@
+#!/usr/bin/python
+# Example usage:
+#   cd path/to/llvm-project
+#   ./path/to/llvm_libc_add_math_function.py '' 'TYPE' 'ceil' 'TYPE x' 'CeilTest' 'LIST_CEIL_TESTS'
+#   ./path/to/llvm_libc_add_math_function.py 'f16' 'TYPE' 'ceil' 'TYPE x' 'CeilTest' 'LIST_CEIL_TESTS'
+import sys
+import subprocess
+
+MAX_FILE_TITLE_LEN = 66
+
+EMACS_CXX_MODE = "-*- C++ -*-"
+
+FILE_HEADER_TEMPLATE = """//===-- {file_title}===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+"""
+
+HEADER_TEMPLATE = """{file_header}
+#ifndef LLVM_LIBC_SRC_MATH_{fn_identifier_uppercase}_H
+#define LLVM_LIBC_SRC_MATH_{fn_identifier_uppercase}_H
+
+#include "src/__support/macros/config.h"
+{includes}
+namespace LIBC_NAMESPACE_DECL {{
+
+{fn_return_type} {fn_identifier}({fn_param_list});
+
+}} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_{fn_identifier_uppercase}_H
+"""
+
+IMPL_TEMPLATE = """{file_header}
+#include "src/math/{fn_identifier}.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {{
+
+LLVM_LIBC_FUNCTION({fn_return_type}, {fn_identifier}, ({fn_param_list})) {{
+  // TODO: Implement function.
+}}
+
+}} // namespace LIBC_NAMESPACE_DECL
+"""
+
+TEST_TEMPLATE = """{file_header}
+#include "{test_class}.h"
+
+#include "src/math/{fn_identifier}.h"
+
+{test_macro}({fn_return_type}, LIBC_NAMESPACE::{fn_identifier})
+"""
+
+
+def get_type_from_suffix(suffix):
+    match suffix:
+        case "":
+            return "double"
+        case "f":
+            return "float"
+        case "l":
+            return "long double"
+        case "f16":
+            return "float16"
+        case "f128":
+            return "float128"
+        case _:
+            raise ValueError("Unknown suffix")
+
+
+def get_file_title(base_title, emacs_mode=""):
+    dashes = "-" * (MAX_FILE_TITLE_LEN - len(base_title) - len(emacs_mode))
+    return f"{base_title} {dashes}{emacs_mode}"
+
+
+def get_include_for_type(type_identifier):
+    match type_identifier:
+        case "float16" | "float128":
+            return '#include "src/__support/macros/properties/types.h"'
+
+
+if __name__ == "__main__":
+    (
+        _,
+        generic_type_suffix,
+        fn_return_type_tmpl,
+        fn_identifier_prefix,
+        fn_param_list_tmpl,
+        test_class,
+        test_macro,
+        *_,
+    ) = sys.argv
+
+    generic_type = get_type_from_suffix(generic_type_suffix)
+    fn_return_type = fn_return_type_tmpl.replace("TYPE", generic_type)
+    fn_identifier = fn_identifier_prefix + generic_type_suffix
+    fn_identifier_uppercase = fn_identifier.upper()
+    fn_param_list = fn_param_list_tmpl.replace("TYPE", generic_type)
+
+    with open(f"libc/src/math/{fn_identifier}.h", "w") as header:
+        header_title = get_file_title(
+            f"Implementation header for {fn_identifier}", EMACS_CXX_MODE
+        )
+        header_file_header = FILE_HEADER_TEMPLATE.format(file_title=header_title)
+
+        header_includes = ""
+
+        if (generic_type_include := get_include_for_type(generic_type)) is not None:
+            header_includes = f"{generic_type_include}\n"
+
+        header.write(
+            HEADER_TEMPLATE.format(
+                file_header=header_file_header,
+                fn_identifier_uppercase=fn_identifier_uppercase,
+                includes=header_includes,
+                fn_return_type=fn_return_type,
+                fn_identifier=fn_identifier,
+                fn_param_list=fn_param_list,
+            )
+        )
+
+    with open(f"libc/src/math/generic/{fn_identifier}.cpp", "w") as impl:
+        impl_title = get_file_title(f"Implementation of {fn_identifier} function")
+        impl_file_header = FILE_HEADER_TEMPLATE.format(file_title=impl_title)
+
+        impl.write(
+            IMPL_TEMPLATE.format(
+                file_header=impl_file_header,
+                fn_return_type=fn_return_type,
+                fn_identifier=fn_identifier,
+                fn_param_list=fn_param_list,
+            )
+        )
+
+    with open(f"libc/test/src/math/smoke/{fn_identifier}_test.cpp", "w") as test:
+        test_title = get_file_title(f"Unittests for {fn_identifier}")
+        test_file_header = FILE_HEADER_TEMPLATE.format(file_title=test_title)
+
+        test.write(
+            TEST_TEMPLATE.format(
+                file_header=test_file_header,
+                test_class=test_class,
+                test_macro=test_macro,
+                fn_return_type=fn_return_type,
+                fn_identifier=fn_identifier,
+            )
+        )
+
+    if generic_type == "float16":
+        subprocess.run(
+            r"sed -i 's/^\(| "
+            + fn_identifier_prefix
+            + r" \+\(| \(|check|\|N\/A\)\? \+\)\{3\}| \) \{7\}/\1|check|/' libc/docs/math/index.rst && git diff libc/docs/math/index.rst",
+            shell=True,
+            check=True,
+        )
\ No newline at end of file

>From 56f04976187833586978c5bb2a8b49dbe53d5677 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Thu, 1 Aug 2024 19:52:21 +0000
Subject: [PATCH 02/23] finished generic and headers

---
 libc/config/darwin/arm/entrypoints.txt     |   2 +
 libc/config/darwin/x86_64/entrypoints.txt  |   2 +
 libc/config/linux/aarch64/entrypoints.txt  |   3 +
 libc/config/linux/arm/entrypoints.txt      |   2 +
 libc/config/linux/riscv/entrypoints.txt    |   3 +
 libc/config/linux/x86_64/entrypoints.txt   |   3 +
 libc/config/windows/entrypoints.txt        |   2 +
 libc/llvm_libc_add_math_function.py        | 161 ---------------------
 libc/src/math/fsub.h                       |  20 +++
 libc/src/math/fsubf128.h                   |  21 +++
 libc/src/math/fsubl.h                      |  20 +++
 libc/src/math/generic/fsub.cpp             |  19 +++
 libc/src/math/generic/fsubf128.cpp         |  19 +++
 libc/src/math/generic/fsubl.cpp            |  19 +++
 libc/test/src/math/smoke/fsub_test.cpp     |  13 ++
 libc/test/src/math/smoke/fsubf128_test.cpp |  13 ++
 libc/test/src/math/smoke/fsubl_test.cpp    |  13 ++
 17 files changed, 174 insertions(+), 161 deletions(-)
 delete mode 100755 libc/llvm_libc_add_math_function.py
 create mode 100644 libc/src/math/fsub.h
 create mode 100644 libc/src/math/fsubf128.h
 create mode 100644 libc/src/math/fsubl.h
 create mode 100644 libc/src/math/generic/fsub.cpp
 create mode 100644 libc/src/math/generic/fsubf128.cpp
 create mode 100644 libc/src/math/generic/fsubl.cpp
 create mode 100644 libc/test/src/math/smoke/fsub_test.cpp
 create mode 100644 libc/test/src/math/smoke/fsubf128_test.cpp
 create mode 100644 libc/test/src/math/smoke/fsubl_test.cpp

diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index d09b4e34b951c..6aaf5d46678d0 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -180,6 +180,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.frexp
     libc.src.math.frexpf
     libc.src.math.frexpl
+    libc.src.math.fsub 
+    libc.src.math.fsubl 
     libc.src.math.hypot
     libc.src.math.hypotf
     libc.src.math.ilogb
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 1cff157c629df..e7a33761e5cbb 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -147,6 +147,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.frexp
     #libc.src.math.frexpf
     #libc.src.math.frexpl
+    #libc.src.math.fsub 
+    #libc.src.math.fsubl 
     #libc.src.math.hypot
     #libc.src.math.hypotf
     #libc.src.math.ilogb
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index ff0bf0ea345d3..d09d524e9bbcf 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -435,6 +435,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fromfpxl
     libc.src.math.fsqrt
     libc.src.math.fsqrtl
+    libc.src.math.fsub 
+    libc.src.math.fsubl 
     libc.src.math.getpayload
     libc.src.math.getpayloadf
     libc.src.math.hypot
@@ -638,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
     libc.src.math.fromfpxf128
+    libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 90aae962080cd..71d75960a03d8 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -293,6 +293,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fromfpx
     libc.src.math.fromfpxf
     libc.src.math.fromfpxl
+    libc.src.math.fsub 
+    libc.src.math.fsubl 
     libc.src.math.getpayload
     libc.src.math.getpayloadf
     libc.src.math.hypot
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 8443ef417b479..a3fbd7494b100 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -458,6 +458,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fromfpxl
     libc.src.math.fsqrt
     libc.src.math.fsqrtl
+    libc.src.math.fsub 
+    libc.src.math.fsubl 
     libc.src.math.getpayload
     libc.src.math.getpayloadf
     libc.src.math.hypot
@@ -594,6 +596,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.fromfpf128
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
+    libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index f737cca7f15b6..0ebda238d42dd 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -458,6 +458,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fromfpxl
     libc.src.math.fsqrt
     libc.src.math.fsqrtl
+    libc.src.math.fsub 
+    libc.src.math.fsubl 
     libc.src.math.getpayload
     libc.src.math.getpayloadf
     libc.src.math.hypot
@@ -683,6 +685,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.fromfpf128
     libc.src.math.fromfpxf128
     libc.src.math.fsqrtf128
+    libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index e45219a9070e3..c611e4ae7e11b 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -193,6 +193,8 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.frexp
     libc.src.math.frexpf
     libc.src.math.frexpl
+    libc.src.math.fsub 
+    libc.src.math.fsubl 
     libc.src.math.hypot
     libc.src.math.hypotf
     libc.src.math.ilogb
diff --git a/libc/llvm_libc_add_math_function.py b/libc/llvm_libc_add_math_function.py
deleted file mode 100755
index 810543570ffc1..0000000000000
--- a/libc/llvm_libc_add_math_function.py
+++ /dev/null
@@ -1,161 +0,0 @@
-#!/usr/bin/python
-# Example usage:
-#   cd path/to/llvm-project
-#   ./path/to/llvm_libc_add_math_function.py '' 'TYPE' 'ceil' 'TYPE x' 'CeilTest' 'LIST_CEIL_TESTS'
-#   ./path/to/llvm_libc_add_math_function.py 'f16' 'TYPE' 'ceil' 'TYPE x' 'CeilTest' 'LIST_CEIL_TESTS'
-import sys
-import subprocess
-
-MAX_FILE_TITLE_LEN = 66
-
-EMACS_CXX_MODE = "-*- C++ -*-"
-
-FILE_HEADER_TEMPLATE = """//===-- {file_title}===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-"""
-
-HEADER_TEMPLATE = """{file_header}
-#ifndef LLVM_LIBC_SRC_MATH_{fn_identifier_uppercase}_H
-#define LLVM_LIBC_SRC_MATH_{fn_identifier_uppercase}_H
-
-#include "src/__support/macros/config.h"
-{includes}
-namespace LIBC_NAMESPACE_DECL {{
-
-{fn_return_type} {fn_identifier}({fn_param_list});
-
-}} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_MATH_{fn_identifier_uppercase}_H
-"""
-
-IMPL_TEMPLATE = """{file_header}
-#include "src/math/{fn_identifier}.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {{
-
-LLVM_LIBC_FUNCTION({fn_return_type}, {fn_identifier}, ({fn_param_list})) {{
-  // TODO: Implement function.
-}}
-
-}} // namespace LIBC_NAMESPACE_DECL
-"""
-
-TEST_TEMPLATE = """{file_header}
-#include "{test_class}.h"
-
-#include "src/math/{fn_identifier}.h"
-
-{test_macro}({fn_return_type}, LIBC_NAMESPACE::{fn_identifier})
-"""
-
-
-def get_type_from_suffix(suffix):
-    match suffix:
-        case "":
-            return "double"
-        case "f":
-            return "float"
-        case "l":
-            return "long double"
-        case "f16":
-            return "float16"
-        case "f128":
-            return "float128"
-        case _:
-            raise ValueError("Unknown suffix")
-
-
-def get_file_title(base_title, emacs_mode=""):
-    dashes = "-" * (MAX_FILE_TITLE_LEN - len(base_title) - len(emacs_mode))
-    return f"{base_title} {dashes}{emacs_mode}"
-
-
-def get_include_for_type(type_identifier):
-    match type_identifier:
-        case "float16" | "float128":
-            return '#include "src/__support/macros/properties/types.h"'
-
-
-if __name__ == "__main__":
-    (
-        _,
-        generic_type_suffix,
-        fn_return_type_tmpl,
-        fn_identifier_prefix,
-        fn_param_list_tmpl,
-        test_class,
-        test_macro,
-        *_,
-    ) = sys.argv
-
-    generic_type = get_type_from_suffix(generic_type_suffix)
-    fn_return_type = fn_return_type_tmpl.replace("TYPE", generic_type)
-    fn_identifier = fn_identifier_prefix + generic_type_suffix
-    fn_identifier_uppercase = fn_identifier.upper()
-    fn_param_list = fn_param_list_tmpl.replace("TYPE", generic_type)
-
-    with open(f"libc/src/math/{fn_identifier}.h", "w") as header:
-        header_title = get_file_title(
-            f"Implementation header for {fn_identifier}", EMACS_CXX_MODE
-        )
-        header_file_header = FILE_HEADER_TEMPLATE.format(file_title=header_title)
-
-        header_includes = ""
-
-        if (generic_type_include := get_include_for_type(generic_type)) is not None:
-            header_includes = f"{generic_type_include}\n"
-
-        header.write(
-            HEADER_TEMPLATE.format(
-                file_header=header_file_header,
-                fn_identifier_uppercase=fn_identifier_uppercase,
-                includes=header_includes,
-                fn_return_type=fn_return_type,
-                fn_identifier=fn_identifier,
-                fn_param_list=fn_param_list,
-            )
-        )
-
-    with open(f"libc/src/math/generic/{fn_identifier}.cpp", "w") as impl:
-        impl_title = get_file_title(f"Implementation of {fn_identifier} function")
-        impl_file_header = FILE_HEADER_TEMPLATE.format(file_title=impl_title)
-
-        impl.write(
-            IMPL_TEMPLATE.format(
-                file_header=impl_file_header,
-                fn_return_type=fn_return_type,
-                fn_identifier=fn_identifier,
-                fn_param_list=fn_param_list,
-            )
-        )
-
-    with open(f"libc/test/src/math/smoke/{fn_identifier}_test.cpp", "w") as test:
-        test_title = get_file_title(f"Unittests for {fn_identifier}")
-        test_file_header = FILE_HEADER_TEMPLATE.format(file_title=test_title)
-
-        test.write(
-            TEST_TEMPLATE.format(
-                file_header=test_file_header,
-                test_class=test_class,
-                test_macro=test_macro,
-                fn_return_type=fn_return_type,
-                fn_identifier=fn_identifier,
-            )
-        )
-
-    if generic_type == "float16":
-        subprocess.run(
-            r"sed -i 's/^\(| "
-            + fn_identifier_prefix
-            + r" \+\(| \(|check|\|N\/A\)\? \+\)\{3\}| \) \{7\}/\1|check|/' libc/docs/math/index.rst && git diff libc/docs/math/index.rst",
-            shell=True,
-            check=True,
-        )
\ No newline at end of file
diff --git a/libc/src/math/fsub.h b/libc/src/math/fsub.h
new file mode 100644
index 0000000000000..f17f0fd3ec307
--- /dev/null
+++ b/libc/src/math/fsub.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fsub --------------------------*- 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_MATH_FSUB_H
+#define LLVM_LIBC_SRC_MATH_FSUB_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fsub(double x, double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FSUB_H
diff --git a/libc/src/math/fsubf128.h b/libc/src/math/fsubf128.h
new file mode 100644
index 0000000000000..4f41c7d8bb04d
--- /dev/null
+++ b/libc/src/math/fsubf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for fsubf128 ----------------------*- 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_MATH_FSUBF128_H
+#define LLVM_LIBC_SRC_MATH_FSUBF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fsubf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FSUBF128_H
diff --git a/libc/src/math/fsubl.h b/libc/src/math/fsubl.h
new file mode 100644
index 0000000000000..32570ca3dc0f7
--- /dev/null
+++ b/libc/src/math/fsubl.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fsubl -------------------------*- 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_MATH_FSUBL_H
+#define LLVM_LIBC_SRC_MATH_FSUBL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float fsubl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FSUBL_H
diff --git a/libc/src/math/generic/fsub.cpp b/libc/src/math/generic/fsub.cpp
new file mode 100644
index 0000000000000..d4e85a36d5285
--- /dev/null
+++ b/libc/src/math/generic/fsub.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of fsub function -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fsub.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fsub, (double x, double y)) {
+  // TODO: Implement function.
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fsubf128.cpp b/libc/src/math/generic/fsubf128.cpp
new file mode 100644
index 0000000000000..255fc88c059af
--- /dev/null
+++ b/libc/src/math/generic/fsubf128.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of fsubf128 function -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fsubf128.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fsubf128, (float128 x, float128 y)) {
+  // TODO: Implement function.
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fsubl.cpp b/libc/src/math/generic/fsubl.cpp
new file mode 100644
index 0000000000000..dda6d5db51e75
--- /dev/null
+++ b/libc/src/math/generic/fsubl.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of fsubl function ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fsubl.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, fsubl, (long double x, long double y)) {
+  // TODO: Implement function.
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/fsub_test.cpp b/libc/test/src/math/smoke/fsub_test.cpp
new file mode 100644
index 0000000000000..b6cb573334132
--- /dev/null
+++ b/libc/test/src/math/smoke/fsub_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsub ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SubTest.h"
+
+#include "src/math/fsub.h"
+
+LIST_SUB_TESTS(float, LIBC_NAMESPACE::fsub)
diff --git a/libc/test/src/math/smoke/fsubf128_test.cpp b/libc/test/src/math/smoke/fsubf128_test.cpp
new file mode 100644
index 0000000000000..0256aebdf2a75
--- /dev/null
+++ b/libc/test/src/math/smoke/fsubf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubf128 --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SubTest.h"
+
+#include "src/math/fsubf128.h"
+
+LIST_SUB_TESTS(float, LIBC_NAMESPACE::fsubf128)
diff --git a/libc/test/src/math/smoke/fsubl_test.cpp b/libc/test/src/math/smoke/fsubl_test.cpp
new file mode 100644
index 0000000000000..361a2bc461fb4
--- /dev/null
+++ b/libc/test/src/math/smoke/fsubl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubl -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SubTest.h"
+
+#include "src/math/fsubl.h"
+
+LIST_SUB_TESTS(float, LIBC_NAMESPACE::fsubl)

>From c999ff3c6575faef5d5e02aac5010126fb9551d5 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Thu, 1 Aug 2024 22:04:33 +0000
Subject: [PATCH 03/23] going to add to header spec

---
 libc/src/math/CMakeLists.txt               |  4 +++
 libc/src/math/generic/CMakeLists.txt       | 37 ++++++++++++++++++++
 libc/src/math/generic/fsub.cpp             |  3 +-
 libc/src/math/generic/fsubf128.cpp         |  3 +-
 libc/src/math/generic/fsubl.cpp            |  3 +-
 libc/test/src/math/CMakeLists.txt          | 39 ++++++++++++++++++++++
 libc/test/src/math/fsub_test.cpp           | 13 ++++++++
 libc/test/src/math/fsubf128_test.cpp       | 13 ++++++++
 libc/test/src/math/fsubl_test.cpp          | 13 ++++++++
 libc/test/src/math/smoke/CMakeLists.txt    | 36 ++++++++++++++++++++
 libc/test/src/math/smoke/fsub_test.cpp     |  2 +-
 libc/test/src/math/smoke/fsubf128_test.cpp |  2 +-
 libc/test/src/math/smoke/fsubl_test.cpp    |  2 +-
 13 files changed, 164 insertions(+), 6 deletions(-)
 create mode 100644 libc/test/src/math/fsub_test.cpp
 create mode 100644 libc/test/src/math/fsubf128_test.cpp
 create mode 100644 libc/test/src/math/fsubl_test.cpp

diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index bd022ad88d884..108d6b4d3fde4 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -260,6 +260,10 @@ add_math_entrypoint_object(fromfpxl)
 add_math_entrypoint_object(fromfpxf16)
 add_math_entrypoint_object(fromfpxf128)
 
+add_math_entrypoint_object(fsub)
+add_math_entrypoint_object(fsubl)
+add_math_entrypoint_object(fsubf128)
+
 add_math_entrypoint_object(getpayload)
 add_math_entrypoint_object(getpayloadf)
 add_math_entrypoint_object(getpayloadf16)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 927d97578316e..f3b6f09e88165 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2823,6 +2823,43 @@ add_entrypoint_object(
     -O3
 )
 
+add_entrypoint_object(
+  fsub
+  SRCS
+    fsub.cpp
+  HDRS
+    ../fsub.h
+  DEPENDS
+   libc.src.__support.FPUtil.generic.add_sub
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  fsubl
+  SRCS
+    fsubl.cpp
+  HDRS
+    ../fsubl.h
+  DEPENDS
+   libc.src.__support.FPUtil.generic.add_sub
+  COMPILE_OPTIONS
+    -O3
+)
+
+add_entrypoint_object(
+  fsubf128
+  SRCS
+    fsubf128.cpp
+  HDRS
+    ../fsubf128.h
+  DEPENDS
+   libc.src.__support.macros.properties.types
+   libc.src.__support.FPUtil.generic.add_sub
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   sqrt
   SRCS
diff --git a/libc/src/math/generic/fsub.cpp b/libc/src/math/generic/fsub.cpp
index d4e85a36d5285..97e28015c0487 100644
--- a/libc/src/math/generic/fsub.cpp
+++ b/libc/src/math/generic/fsub.cpp
@@ -7,13 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fsub.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fsub, (double x, double y)) {
-  // TODO: Implement function.
+  return fputil::generic::sub<float>(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fsubf128.cpp b/libc/src/math/generic/fsubf128.cpp
index 255fc88c059af..3efb34992b748 100644
--- a/libc/src/math/generic/fsubf128.cpp
+++ b/libc/src/math/generic/fsubf128.cpp
@@ -7,13 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fsubf128.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fsubf128, (float128 x, float128 y)) {
-  // TODO: Implement function.
+  return fputil::generic::sub<float>(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fsubl.cpp b/libc/src/math/generic/fsubl.cpp
index dda6d5db51e75..be74f85016671 100644
--- a/libc/src/math/generic/fsubl.cpp
+++ b/libc/src/math/generic/fsubl.cpp
@@ -7,13 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fsubl.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fsubl, (long double x, long double y)) {
-  // TODO: Implement function.
+  return fputil::generic::sub<float16>(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index cc5955903b20d..644b74a0ac0a9 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2294,6 +2294,45 @@ add_fp_unittest(
     libc.src.math.fsqrtl
 )
 
+add_fp_unittest(
+  fsub_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    fsub_test.cpp
+  HDRS
+  SubTest.h
+  DEPENDS
+    libc.src.math.fsub
+)
+
+add_fp_unittest(
+  fsubl_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    fsubl_test.cpp
+  HDRS
+  SubTest.h
+  DEPENDS
+    libc.src.math.fsubl
+)
+
+add_fp_unittest(
+  fsubf128_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    fsubf128_test.cpp
+  HDRS
+  SubTest.h
+  DEPENDS
+    libc.src.math.fsubf128
+)
+
 add_fp_unittest(
   dsqrtl_test
   NEED_MPFR
diff --git a/libc/test/src/math/fsub_test.cpp b/libc/test/src/math/fsub_test.cpp
new file mode 100644
index 0000000000000..3c825f7f28af4
--- /dev/null
+++ b/libc/test/src/math/fsub_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsub ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SubTest.h"
+
+#include "src/math/fsub.h"
+
+LIST_SUB_TESTS(float, double, LIBC_NAMESPACE::fsub)
diff --git a/libc/test/src/math/fsubf128_test.cpp b/libc/test/src/math/fsubf128_test.cpp
new file mode 100644
index 0000000000000..8f46d91116bde
--- /dev/null
+++ b/libc/test/src/math/fsubf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubf128 --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SubTest.h"
+
+#include "src/math/fsubf128.h"
+
+LIST_SUB_TESTS(float, float128, LIBC_NAMESPACE::fsubf128)
diff --git a/libc/test/src/math/fsubl_test.cpp b/libc/test/src/math/fsubl_test.cpp
new file mode 100644
index 0000000000000..8723432603b00
--- /dev/null
+++ b/libc/test/src/math/fsubl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fsubl -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SubTest.h"
+
+#include "src/math/fsubl.h"
+
+LIST_SUB_TESTS(float, long double, LIBC_NAMESPACE::fsubl)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index faca71b8b5bc4..17976305d090e 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4227,6 +4227,42 @@ add_fp_unittest(
     libc.src.math.fsqrtf128
 )
 
+add_fp_unittest(
+  fsub_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    fsub_test.cpp
+  HDRS
+    SubTest.h
+  DEPENDS
+    libc.src.math.fsub
+)
+
+add_fp_unittest(
+  fsubl_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    fsubl_test.cpp
+  HDRS
+    SubTest.h
+  DEPENDS
+    libc.src.math.fsubl
+)
+
+add_fp_unittest(
+  fsubf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    fsubl_test.cpp
+  HDRS
+    SubTest.h
+  DEPENDS
+    libc.src.math.fsubf128
+)
+
 add_fp_unittest(
   dsqrtl_test
   SUITE
diff --git a/libc/test/src/math/smoke/fsub_test.cpp b/libc/test/src/math/smoke/fsub_test.cpp
index b6cb573334132..3c825f7f28af4 100644
--- a/libc/test/src/math/smoke/fsub_test.cpp
+++ b/libc/test/src/math/smoke/fsub_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/math/fsub.h"
 
-LIST_SUB_TESTS(float, LIBC_NAMESPACE::fsub)
+LIST_SUB_TESTS(float, double, LIBC_NAMESPACE::fsub)
diff --git a/libc/test/src/math/smoke/fsubf128_test.cpp b/libc/test/src/math/smoke/fsubf128_test.cpp
index 0256aebdf2a75..8f46d91116bde 100644
--- a/libc/test/src/math/smoke/fsubf128_test.cpp
+++ b/libc/test/src/math/smoke/fsubf128_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/math/fsubf128.h"
 
-LIST_SUB_TESTS(float, LIBC_NAMESPACE::fsubf128)
+LIST_SUB_TESTS(float, float128, LIBC_NAMESPACE::fsubf128)
diff --git a/libc/test/src/math/smoke/fsubl_test.cpp b/libc/test/src/math/smoke/fsubl_test.cpp
index 361a2bc461fb4..8723432603b00 100644
--- a/libc/test/src/math/smoke/fsubl_test.cpp
+++ b/libc/test/src/math/smoke/fsubl_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/math/fsubl.h"
 
-LIST_SUB_TESTS(float, LIBC_NAMESPACE::fsubl)
+LIST_SUB_TESTS(float, long double, LIBC_NAMESPACE::fsubl)

>From 10f87726f9108b17b044690d7d0f780f4b86166f Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Thu, 1 Aug 2024 22:54:58 +0000
Subject: [PATCH 04/23] [libc][math][c23]:

---
 libc/config/linux/aarch64/entrypoints.txt |  1 +
 libc/config/linux/x86_64/entrypoints.txt  |  1 +
 libc/newhdrgen/yaml/math.yaml             | 30 +++++++++++++++++++++++
 libc/src/math/CMakeLists.txt              |  1 +
 libc/src/math/generic/CMakeLists.txt      | 13 ++++++++++
 libc/src/math/generic/fsubl.cpp           |  2 +-
 libc/src/math/generic/remainderf128.cpp   | 21 ++++++++++++++++
 libc/src/math/remainderf128.h             | 21 ++++++++++++++++
 libc/test/src/math/smoke/CMakeLists.txt   |  2 +-
 9 files changed, 90 insertions(+), 2 deletions(-)
 create mode 100644 libc/src/math/generic/remainderf128.cpp
 create mode 100644 libc/src/math/remainderf128.h

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index d09d524e9bbcf..57e92ecdbb014 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -656,6 +656,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
+    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.rintf128
     libc.src.math.roundf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0ebda238d42dd..eee6a0c756d89 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -701,6 +701,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
+    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.rintf128
     libc.src.math.roundevenf128
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index ce562c653a6d2..cdd90e994c94c 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -794,6 +794,14 @@ functions:
     arguments:
       - type: long double
       - type: long double
+  - name: remainderf128
+    standards:
+      - llvm_libc_ext
+    return_type: float128
+    arguments:
+      - type: float128
+      - type: float128
+    guard: LIBC_TYPES_HAS_FLOAT128
   - name: remquo
     standards: 
       - stdc
@@ -1540,6 +1548,28 @@ functions:
       - type: int
       - type: unsigned int
     guard: LIBC_TYPES_HAS_FLOAT16
+  - name: fsub
+    standards: 
+      - stdc
+    return_type: float
+    arguments: 
+      - type: double
+      - type: double
+  - name: fsubl
+    standards: 
+      - stdc
+    return_type: float
+    arguments: 
+      - type: long double
+      - type: long double
+  - name: fsubf128
+    standards: 
+      - llvm_libc_ext
+    return_type: float
+    arguments: 
+      - type: float128
+      - type: float128
+    guard: LIBC_TYPES_HAS_FLOAT128
   - name: getpayloadf16
     standards: 
       - stdc
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 108d6b4d3fde4..92eb20e5e61fe 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -386,6 +386,7 @@ add_math_entrypoint_object(remainder)
 add_math_entrypoint_object(remainderf)
 add_math_entrypoint_object(remainderl)
 add_math_entrypoint_object(remainderf16)
+add_math_entrypoint_object(remainderf128)
 
 add_math_entrypoint_object(remquo)
 add_math_entrypoint_object(remquof)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f3b6f09e88165..4c312b7360af7 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3020,6 +3020,19 @@ add_entrypoint_object(
     -O3
 )
 
+add_entrypoint_object(
+  remainderf128
+  SRCS
+    remainderf128.cpp
+  HDRS
+    ../remainderf128.h
+  DEPENDS
+    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.division_and_remainder_operations
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   hypotf
   SRCS
diff --git a/libc/src/math/generic/fsubl.cpp b/libc/src/math/generic/fsubl.cpp
index be74f85016671..cad5a2d5d452a 100644
--- a/libc/src/math/generic/fsubl.cpp
+++ b/libc/src/math/generic/fsubl.cpp
@@ -14,7 +14,7 @@
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fsubl, (long double x, long double y)) {
-  return fputil::generic::sub<float16>(x, y);
+  return fputil::generic::sub<float>(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/remainderf128.cpp b/libc/src/math/generic/remainderf128.cpp
new file mode 100644
index 0000000000000..52b6c5149fdcf
--- /dev/null
+++ b/libc/src/math/generic/remainderf128.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of remainderf128 function --------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/remainderf128.h"
+#include "src/__support/FPUtil/DivisionAndRemainderOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float128, remainderf128, (float128 x, float128 y)) {
+  int quotient;
+  return fputil::remquo(x, y, quotient);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/remainderf128.h b/libc/src/math/remainderf128.h
new file mode 100644
index 0000000000000..57f770a853d68
--- /dev/null
+++ b/libc/src/math/remainderf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for remainderf128 -----------------*- 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_MATH_REMAINDERF128_H
+#define LLVM_LIBC_SRC_MATH_REMAINDERF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float128 remainderf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_REMAINDERF128_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 17976305d090e..622dc1ee50d86 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4256,7 +4256,7 @@ add_fp_unittest(
   SUITE
     libc-math-smoke-tests
   SRCS
-    fsubl_test.cpp
+    fsubf128_test.cpp
   HDRS
     SubTest.h
   DEPENDS

>From ac942e0936fc661c873fbe75037d51b77f15ebee Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Fri, 2 Aug 2024 08:33:59 +0000
Subject: [PATCH 05/23] removed fsubf128 from unittests

- added <long double> to <float>
---
 libc/test/src/math/CMakeLists.txt    | 13 -------------
 libc/test/src/math/fsubf128_test.cpp | 13 -------------
 libc/utils/MPFRWrapper/MPFRUtils.cpp | 11 +++++++++++
 3 files changed, 11 insertions(+), 26 deletions(-)
 delete mode 100644 libc/test/src/math/fsubf128_test.cpp

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 644b74a0ac0a9..bec78f93b4062 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2320,19 +2320,6 @@ add_fp_unittest(
     libc.src.math.fsubl
 )
 
-add_fp_unittest(
-  fsubf128_test
-  NEED_MPFR
-  SUITE
-    libc-math-unittests
-  SRCS
-    fsubf128_test.cpp
-  HDRS
-  SubTest.h
-  DEPENDS
-    libc.src.math.fsubf128
-)
-
 add_fp_unittest(
   dsqrtl_test
   NEED_MPFR
diff --git a/libc/test/src/math/fsubf128_test.cpp b/libc/test/src/math/fsubf128_test.cpp
deleted file mode 100644
index 8f46d91116bde..0000000000000
--- a/libc/test/src/math/fsubf128_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-//===-- Unittests for fsubf128 --------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "SubTest.h"
-
-#include "src/math/fsubf128.h"
-
-LIST_SUB_TESTS(float, float128, LIBC_NAMESPACE::fsubf128)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 4263c9dccb6a5..1695354565f56 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -1086,9 +1086,14 @@ template void
 explain_ternary_operation_one_output_error(Operation,
                                            const TernaryInput<long double> &,
                                            long double, double, RoundingMode);
+template void explain_ternary_operation_one_output_error(
+    Operation, const TernaryInput<double> &, float, double, RoundingMode);
+template void explain_ternary_operation_one_output_error(
+    Operation, const TernaryInput<long double> &, float, double, RoundingMode);
 
 template void explain_ternary_operation_one_output_error(
     Operation, const TernaryInput<long double> &, double, double, RoundingMode);
+
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template void explain_ternary_operation_one_output_error(
     Operation, const TernaryInput<float> &, float16, double, RoundingMode);
@@ -1277,6 +1282,8 @@ compare_ternary_operation_one_output(Operation,
 
 template bool compare_ternary_operation_one_output(
     Operation, const TernaryInput<long double> &, double, double, RoundingMode);
+template bool compare_ternary_operation_one_output(
+    Operation, const TernaryInput<long double> &, float, double, RoundingMode);
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template bool compare_ternary_operation_one_output(Operation,
                                                    const TernaryInput<float> &,
@@ -1286,6 +1293,10 @@ template bool compare_ternary_operation_one_output(Operation,
                                                    const TernaryInput<double> &,
                                                    float16, double,
                                                    RoundingMode);
+template bool compare_ternary_operation_one_output(Operation,
+                                                   const TernaryInput<double> &,
+                                                   float, double, RoundingMode);
+
 template bool
 compare_ternary_operation_one_output(Operation,
                                      const TernaryInput<long double> &, float16,

>From 0537314c4ea068b759d143f84423ac15b2308cee Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Fri, 2 Aug 2024 22:33:46 +0000
Subject: [PATCH 06/23] updated index.rst

---
 libc/docs/math/index.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index bbe5b19a9da95..3fa60141ed5a6 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -118,7 +118,7 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | ddiv             | N/A              | N/A             |                        | N/A                  |                        | 7.12.14.4              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| dfma             | N/A              | N/A             | |check|                | N/A                  | |check|\*             | 7.12.14.5              | F.10.11                     |
+| dfma             | N/A              | N/A             | |check|                | N/A                  | |check|\*              | 7.12.14.5              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | dmul             | N/A              | N/A             | |check|                | N/A                  | |check|\*              | 7.12.14.3              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -176,7 +176,7 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | fromfpx          | |check|          | |check|         | |check|                | |check|              | |check|                | 7.12.9.11              | F.10.6.11                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| fsub             | N/A              |                 |                        | N/A                  |                        | 7.12.14.2              | F.10.11                    |
+| fsub             | N/A              | |check|         | |check|                | N/A                  | |check|                | 7.12.14.2              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | getpayload       | |check|          | |check|         |                        | |check|              | |check|                | F.10.13.1              | N/A                        |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -210,7 +210,7 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | nextup           | |check|          | |check|         | |check|                | |check|              | |check|                | 7.12.11.5              | F.10.8.5                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| remainder        | |check|          | |check|         | |check|                | |check|              |                        | 7.12.10.2              | F.10.7.2                   |
+| remainder        | |check|          | |check|         | |check|                | |check|              | |check|                | 7.12.10.2              | F.10.7.2                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | remquo           | |check|          | |check|         | |check|                | |check|              | |check|                | 7.12.10.3              | F.10.7.3                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

>From 7ea12c98c24954778e0dd15d2a1100a17dc4c9c1 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Sun, 4 Aug 2024 20:16:27 -0700
Subject: [PATCH 07/23] Update libc/test/src/math/smoke/CMakeLists.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/test/src/math/smoke/CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 622dc1ee50d86..a7c7f431294bd 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4260,6 +4260,8 @@ add_fp_unittest(
   HDRS
     SubTest.h
   DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.fsubf128
 )
 

>From 99ac8a190b32c9dd4f7d6e6ff3cb9e091a866c85 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Sun, 4 Aug 2024 20:16:36 -0700
Subject: [PATCH 08/23] Update libc/docs/math/index.rst

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/docs/math/index.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 3fa60141ed5a6..1f114c2f676ca 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -176,7 +176,7 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | fromfpx          | |check|          | |check|         | |check|                | |check|              | |check|                | 7.12.9.11              | F.10.6.11                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| fsub             | N/A              | |check|         | |check|                | N/A                  | |check|                | 7.12.14.2              | F.10.11                    |
+| fsub             | N/A              | |check|         | |check|                | N/A                  | |check|\*              | 7.12.14.2              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | getpayload       | |check|          | |check|         |                        | |check|              | |check|                | F.10.13.1              | N/A                        |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

>From 3c41447d5f0f053aee158764840511be310cdd0f Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Sun, 4 Aug 2024 20:16:45 -0700
Subject: [PATCH 09/23] Update libc/test/src/math/CMakeLists.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/test/src/math/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index bec78f93b4062..790ee5d74fc76 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2302,7 +2302,7 @@ add_fp_unittest(
   SRCS
     fsub_test.cpp
   HDRS
-  SubTest.h
+    SubTest.h
   DEPENDS
     libc.src.math.fsub
 )

>From d13eec92315638cd7e11fc2fab449509a70d4cd4 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Sun, 4 Aug 2024 20:16:51 -0700
Subject: [PATCH 10/23] Update libc/test/src/math/CMakeLists.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/test/src/math/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 790ee5d74fc76..4fecfcc3d88f4 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2315,7 +2315,7 @@ add_fp_unittest(
   SRCS
     fsubl_test.cpp
   HDRS
-  SubTest.h
+    SubTest.h
   DEPENDS
     libc.src.math.fsubl
 )

>From a48b6219baac7b9684220b67a6e0b873aead295a Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Sun, 4 Aug 2024 20:16:56 -0700
Subject: [PATCH 11/23] Update libc/test/src/math/smoke/CMakeLists.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/test/src/math/smoke/CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index a7c7f431294bd..748b85159baaf 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4248,6 +4248,8 @@ add_fp_unittest(
   HDRS
     SubTest.h
   DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.fsubl
 )
 

>From 921d587749246f08946ab35d9745507734b10f64 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Sun, 4 Aug 2024 20:18:19 -0700
Subject: [PATCH 12/23] Update libc/test/src/math/smoke/CMakeLists.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/test/src/math/smoke/CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 748b85159baaf..f3000c5f250e5 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4236,6 +4236,8 @@ add_fp_unittest(
   HDRS
     SubTest.h
   DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.fsub
 )
 

>From f84aabfdbb1424e87298b2234726cc28bfaca4d8 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Mon, 5 Aug 2024 19:06:00 +0000
Subject: [PATCH 13/23] added headers to oldheadergen

---
 libc/config/linux/riscv/entrypoints.txt | 1 +
 libc/spec/llvm_libc_ext.td              | 3 +++
 libc/spec/stdc.td                       | 9 +++++++++
 3 files changed, 13 insertions(+)

diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 9b0840b6b638e..8152adbcff068 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -595,6 +595,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.fminimumf128
     libc.src.math.fmodf128
     libc.src.math.fmulf128
+    libc.src.math.remainderf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
     libc.src.math.fromfpxf128
diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index f86a8c1c6c106..7c64f31e2899a 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -96,6 +96,9 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
 
           FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
           FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
+
+          GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+          
       ]
   >;
 
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 3f68eeb7853ad..20bfba539358a 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -414,6 +414,12 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"fdiml", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
           GuardedFunctionSpec<"fdimf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"fdimf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+          
+          FunctionSpec<"fdiv", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+          FunctionSpec<"fdivl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+
+          FunctionSpec<"ffma", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+          FunctionSpec<"ffmal", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
 
           FunctionSpec<"floor", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
           FunctionSpec<"floorf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
@@ -510,6 +516,9 @@ def StdC : StandardSpec<"stdc"> {
           GuardedFunctionSpec<"fromfpxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"fromfpxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>], "LIBC_TYPES_HAS_FLOAT128">,
 
+          FunctionSpec<"fsub", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+          FunctionSpec<"fsubl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+
           FunctionSpec<"ufromfp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
           FunctionSpec<"ufromfpf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,
           FunctionSpec<"ufromfpl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntType>, ArgSpec<UnsignedIntType>]>,

>From 694bd80b76a77e226723af901676d789557625ac Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Tue, 6 Aug 2024 10:20:34 -0700
Subject: [PATCH 14/23] Update libc/src/math/generic/CMakeLists.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/src/math/generic/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 815f3e4626ba0..0fd3d2c346267 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2891,7 +2891,7 @@ add_entrypoint_object(
   HDRS
     ../fsub.h
   DEPENDS
-   libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.FPUtil.generic.add_sub
   COMPILE_OPTIONS
     -O3
 )

>From 1e28c71ba506d1e492d03195b9f5ab3bcde62172 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Tue, 6 Aug 2024 10:20:43 -0700
Subject: [PATCH 15/23] Update libc/config/linux/aarch64/entrypoints.txt

Co-authored-by: OverMighty <its.overmighty at gmail.com>
---
 libc/config/linux/aarch64/entrypoints.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 05f988a0ab20a..3d065c143859d 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -695,8 +695,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
     libc.src.math.fromfpxf128
-    libc.src.math.fsubf128
     libc.src.math.fsqrtf128
+    libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
     libc.src.math.ldexpf128

>From f3a26d6f0d0b31a46a8a86b806fc569e94beaf03 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Tue, 6 Aug 2024 17:33:49 +0000
Subject: [PATCH 16/23] fixed whitespaces

---
 libc/config/linux/riscv/entrypoints.txt | 2 +-
 libc/src/math/generic/CMakeLists.txt    | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 8152adbcff068..b5c3cec7063da 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -595,7 +595,6 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.fminimumf128
     libc.src.math.fmodf128
     libc.src.math.fmulf128
-    libc.src.math.remainderf128
     libc.src.math.frexpf128
     libc.src.math.fromfpf128
     libc.src.math.fromfpxf128
@@ -616,6 +615,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
     libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
+    libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.rintf128
     libc.src.math.roundevenf128
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 0fd3d2c346267..ab3f9f232dca2 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2903,7 +2903,7 @@ add_entrypoint_object(
   HDRS
     ../fsubl.h
   DEPENDS
-   libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.FPUtil.generic.add_sub
   COMPILE_OPTIONS
     -O3
 )
@@ -2915,8 +2915,8 @@ add_entrypoint_object(
   HDRS
     ../fsubf128.h
   DEPENDS
-   libc.src.__support.macros.properties.types
-   libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.generic.add_sub
   COMPILE_OPTIONS
     -O3
 )

>From b53f728dd53581b94f94ee90407213411898abf1 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Tue, 6 Aug 2024 10:55:53 -0700
Subject: [PATCH 17/23] Update MPFRUtils.cpp

---
 libc/utils/MPFRWrapper/MPFRUtils.cpp | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index af5b1c0a0bd28..7ce6a70d09316 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -1092,12 +1092,7 @@ template void
 explain_ternary_operation_one_output_error(Operation,
                                            const TernaryInput<long double> &,
                                            long double, double, RoundingMode);
-template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<double> &, float, double, RoundingMode);
-template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, float, double, RoundingMode);
-template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, double, double, RoundingMode);
+
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template void explain_ternary_operation_one_output_error(
     Operation, const TernaryInput<float> &, float16, double, RoundingMode);
@@ -1290,10 +1285,7 @@ template bool
 compare_ternary_operation_one_output(Operation,
                                      const TernaryInput<long double> &,
                                      long double, double, RoundingMode);
-template bool compare_ternary_operation_one_output(
-    Operation, const TernaryInput<long double> &, double, double, RoundingMode);
-template bool compare_ternary_operation_one_output(
-    Operation, const TernaryInput<long double> &, float, double, RoundingMode);
+
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template bool compare_ternary_operation_one_output(Operation,
                                                    const TernaryInput<float> &,
@@ -1303,10 +1295,6 @@ template bool compare_ternary_operation_one_output(Operation,
                                                    const TernaryInput<double> &,
                                                    float16, double,
                                                    RoundingMode);
-template bool compare_ternary_operation_one_output(Operation,
-                                                   const TernaryInput<double> &,
-                                                   float, double, RoundingMode);
-
 template bool
 compare_ternary_operation_one_output(Operation,
                                      const TernaryInput<long double> &, float16,

>From 92367b3717c8efb6090e9b9dc704a1ca66476f7d Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Wed, 7 Aug 2024 16:34:19 +0000
Subject: [PATCH 18/23] fixed hdrgen

---
 libc/newhdrgen/tests/input/test_small.yaml | 14 +++++++-------
 libc/newhdrgen/yaml/math.yaml              |  2 +-
 libc/spec/llvm_libc_ext.td                 |  3 ++-
 libc/spec/stdc.td                          |  3 +++
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/libc/newhdrgen/tests/input/test_small.yaml b/libc/newhdrgen/tests/input/test_small.yaml
index 772552faf81dc..a2e96939b4be0 100644
--- a/libc/newhdrgen/tests/input/test_small.yaml
+++ b/libc/newhdrgen/tests/input/test_small.yaml
@@ -21,14 +21,14 @@ functions:
   - name: func_a
     return_type: void
     arguments: []
-    standards:
+    standards: 
       - stdc
-    attributes:
+    attributes: 
       - CONST_FUNC_A
   - name: func_b
     return_type: float128
     arguments: []
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT128
   - name: func_c
@@ -36,7 +36,7 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_d
@@ -44,14 +44,14 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_e
     return_type: _Float16
     arguments:
       - type: float128
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
   - name: func_f
@@ -60,7 +60,7 @@ functions:
       - type: int
       - type: double
       - type: float
-    standards:
+    standards: 
       - stdc
 
 
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index 7b79eb956e6b5..1a05cea9461c6 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -796,7 +796,7 @@ functions:
       - type: long double
   - name: remainderf128
     standards:
-      - llvm_libc_ext
+      - stdc
     return_type: float128
     arguments:
       - type: float128
diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index 6d367a5931ae9..ac561161a1773 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -98,10 +98,11 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
 
           GuardedFunctionSpec<"fsqrtf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
 
+          FunctionSpec<"fsubf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
           FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
           FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
 
-          GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
           
       ]
   >;
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 318d0291d5b97..0fd5beea00e63 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -752,6 +752,9 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"getpayloadf", RetValSpec<FloatType>, [ArgSpec<FloatPtr>]>,
           GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
+
+          GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
 	  
           FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
           FunctionSpec<"setpayloadf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,

>From b1ec79cb722209d63c1643e8f4c30f93c51d1b9a Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Wed, 7 Aug 2024 17:16:12 +0000
Subject: [PATCH 19/23] updated stdc.td

---
 libc/newhdrgen/tests/input/test_small.yaml | 14 +++++++-------
 libc/spec/stdc.td                          |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libc/newhdrgen/tests/input/test_small.yaml b/libc/newhdrgen/tests/input/test_small.yaml
index a2e96939b4be0..772552faf81dc 100644
--- a/libc/newhdrgen/tests/input/test_small.yaml
+++ b/libc/newhdrgen/tests/input/test_small.yaml
@@ -21,14 +21,14 @@ functions:
   - name: func_a
     return_type: void
     arguments: []
-    standards: 
+    standards:
       - stdc
-    attributes: 
+    attributes:
       - CONST_FUNC_A
   - name: func_b
     return_type: float128
     arguments: []
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT128
   - name: func_c
@@ -36,7 +36,7 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_d
@@ -44,14 +44,14 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_e
     return_type: _Float16
     arguments:
       - type: float128
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
   - name: func_f
@@ -60,7 +60,7 @@ functions:
       - type: int
       - type: double
       - type: float
-    standards: 
+    standards:
       - stdc
 
 
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 49c3d764af7ca..c21a4d0971400 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -606,6 +606,7 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"remainderf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
           FunctionSpec<"remainderl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
           GuardedFunctionSpec<"remainderf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
+          GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
 
           FunctionSpec<"remquo", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
           FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
@@ -755,7 +756,6 @@ def StdC : StandardSpec<"stdc"> {
           GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
 
-          GuardedFunctionSpec<"remainderf128", RetValSpec<Float128Type, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
 
 	  
           FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,

>From f62a56de523b32d7f6c4e9e4db2867e7c09695d1 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Wed, 7 Aug 2024 17:21:01 +0000
Subject: [PATCH 20/23] reverted changes to yaml testing

---
 libc/newhdrgen/tests/input/test_small.yaml | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libc/newhdrgen/tests/input/test_small.yaml b/libc/newhdrgen/tests/input/test_small.yaml
index 772552faf81dc..a2e96939b4be0 100644
--- a/libc/newhdrgen/tests/input/test_small.yaml
+++ b/libc/newhdrgen/tests/input/test_small.yaml
@@ -21,14 +21,14 @@ functions:
   - name: func_a
     return_type: void
     arguments: []
-    standards:
+    standards: 
       - stdc
-    attributes:
+    attributes: 
       - CONST_FUNC_A
   - name: func_b
     return_type: float128
     arguments: []
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT128
   - name: func_c
@@ -36,7 +36,7 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_d
@@ -44,14 +44,14 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_e
     return_type: _Float16
     arguments:
       - type: float128
-    standards:
+    standards: 
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
   - name: func_f
@@ -60,7 +60,7 @@ functions:
       - type: int
       - type: double
       - type: float
-    standards:
+    standards: 
       - stdc
 
 

>From a39816dccc76070962b300b0c2073f1abf10e69f Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Wed, 7 Aug 2024 10:22:50 -0700
Subject: [PATCH 21/23] Update test_small.yaml

---
 libc/newhdrgen/tests/input/test_small.yaml | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libc/newhdrgen/tests/input/test_small.yaml b/libc/newhdrgen/tests/input/test_small.yaml
index a2e96939b4be0..772552faf81dc 100644
--- a/libc/newhdrgen/tests/input/test_small.yaml
+++ b/libc/newhdrgen/tests/input/test_small.yaml
@@ -21,14 +21,14 @@ functions:
   - name: func_a
     return_type: void
     arguments: []
-    standards: 
+    standards:
       - stdc
-    attributes: 
+    attributes:
       - CONST_FUNC_A
   - name: func_b
     return_type: float128
     arguments: []
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT128
   - name: func_c
@@ -36,7 +36,7 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_d
@@ -44,14 +44,14 @@ functions:
     arguments:
       - type: int
       - type: float
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16
   - name: func_e
     return_type: _Float16
     arguments:
       - type: float128
-    standards: 
+    standards:
       - stdc
     guard: LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
   - name: func_f
@@ -60,7 +60,7 @@ functions:
       - type: int
       - type: double
       - type: float
-    standards: 
+    standards:
       - stdc
 
 

>From b22edadb683203d18c75ffae87aed85710eb4c84 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Wed, 7 Aug 2024 10:50:57 -0700
Subject: [PATCH 22/23] Update llvm_libc_ext.td

---
 libc/spec/llvm_libc_ext.td | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index ac561161a1773..c4cbca80072bf 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -101,9 +101,7 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
           FunctionSpec<"fsubf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
 
           FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
-          FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
-
-          
+          FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,          
       ]
   >;
 

>From 23da4b0a8883ce1e073251bbdd80a9edd91f89c2 Mon Sep 17 00:00:00 2001
From: aaryanshukla <53713108+aaryanshukla at users.noreply.github.com>
Date: Wed, 7 Aug 2024 10:51:53 -0700
Subject: [PATCH 23/23] Update stdc.td

---
 libc/spec/stdc.td | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index c21a4d0971400..d3e8938b197d5 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -756,8 +756,6 @@ def StdC : StandardSpec<"stdc"> {
           GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
           GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
 
-
-	  
           FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
           FunctionSpec<"setpayloadf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
           GuardedFunctionSpec<"setpayloadf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,



More information about the libc-commits mailing list