[libc-commits] [libc] 0b0cce8 - [libc] Add fminf128 and fmaxf128 implementations for Linux x86_64. (#79307)

via libc-commits libc-commits at lists.llvm.org
Thu Jan 25 12:04:22 PST 2024


Author: felixh5678
Date: 2024-01-25T15:04:18-05:00
New Revision: 0b0cce8978eefce4b9b4eb1727f1f210a6b2a2d9

URL: https://github.com/llvm/llvm-project/commit/0b0cce8978eefce4b9b4eb1727f1f210a6b2a2d9
DIFF: https://github.com/llvm/llvm-project/commit/0b0cce8978eefce4b9b4eb1727f1f210a6b2a2d9.diff

LOG: [libc] Add fminf128 and fmaxf128 implementations for Linux x86_64. (#79307)

Co-authored-by: Felix <felix at Dirks-MacBook-Pro.local>

Added: 
    libc/src/math/fmaxf128.h
    libc/src/math/fminf128.h
    libc/src/math/generic/fmaxf128.cpp
    libc/src/math/generic/fminf128.cpp
    libc/test/src/math/smoke/fmaxf128_test.cpp
    libc/test/src/math/smoke/fminf128_test.cpp

Modified: 
    libc/config/linux/x86_64/entrypoints.txt
    libc/docs/math/index.rst
    libc/spec/stdc.td
    libc/src/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/test/src/math/smoke/CMakeLists.txt
    libc/test/src/math/smoke/FMaxTest.h
    libc/test/src/math/smoke/FMinTest.h

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 5b43188e75cd74..3812d9586121e7 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -376,6 +376,8 @@ if(LIBC_COMPILER_HAS_FLOAT128)
     libc.src.math.copysignf128
     libc.src.math.fabsf128
     libc.src.math.sqrtf128
+    libc.src.math.fmaxf128
+    libc.src.math.fminf128
   )
 endif()
 

diff  --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index e28b8e87988441..748247bb85d79c 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -146,12 +146,16 @@ Basic Operations
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fmaxf        | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| fmaxf128     | |check| |         |         |         |         |         |         |         |         |         |         |         |
++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fmaxl        | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fmin         | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fminf        | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| fminf128     | |check| |         |         |         |         |         |         |         |         |         |         |         |
++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fminl        | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fmod         | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 96bedf2f47f1b8..43b81c4abaa0e6 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -380,10 +380,12 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"fmin", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
           FunctionSpec<"fminl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+          FunctionSpec<"fminf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>]>,
 
           FunctionSpec<"fmax", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
           FunctionSpec<"fmaxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
+          FunctionSpec<"fmaxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>]>,
 
           FunctionSpec<"fma", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"fmaf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<FloatType>]>,

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3097c4b3a82cc4..2b7eb3a05396b5 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -121,10 +121,12 @@ add_math_entrypoint_object(fmaf)
 add_math_entrypoint_object(fmax)
 add_math_entrypoint_object(fmaxf)
 add_math_entrypoint_object(fmaxl)
+add_math_entrypoint_object(fmaxf128)
 
 add_math_entrypoint_object(fmin)
 add_math_entrypoint_object(fminf)
 add_math_entrypoint_object(fminl)
+add_math_entrypoint_object(fminf128)
 
 add_math_entrypoint_object(fmod)
 add_math_entrypoint_object(fmodf)

diff  --git a/libc/src/math/fmaxf128.h b/libc/src/math/fmaxf128.h
new file mode 100644
index 00000000000000..39eaaf616dd5d8
--- /dev/null
+++ b/libc/src/math/fmaxf128.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fmaxf128 ----------------------*- 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_FMAXF128_H
+#define LLVM_LIBC_SRC_MATH_FMAXF128_H
+
+#include "src/__support/macros/properties/float.h"
+
+namespace LIBC_NAMESPACE {
+
+float128 fmaxf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_FMAXF128_H

diff  --git a/libc/src/math/fminf128.h b/libc/src/math/fminf128.h
new file mode 100644
index 00000000000000..b3d1bec8e2ad92
--- /dev/null
+++ b/libc/src/math/fminf128.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fminf128 ----------------------*- 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_FMINF128_H
+#define LLVM_LIBC_SRC_MATH_FMINF128_H
+
+#include "src/__support/macros/properties/float.h"
+
+namespace LIBC_NAMESPACE {
+
+float128 fminf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_FMINF128_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 8b32a3296bb87f..2521435bffb4e9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1243,6 +1243,18 @@ add_entrypoint_object(
     -O2
 )
 
+add_entrypoint_object(
+  fminf128
+  SRCS
+    fminf128.cpp
+  HDRS
+    ../fminf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   fmax
   SRCS
@@ -1279,6 +1291,18 @@ add_entrypoint_object(
     -O2
 )
 
+add_entrypoint_object(
+  fmaxf128
+  SRCS
+    fmaxf128.cpp
+  HDRS
+    ../fmaxf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   sqrt
   SRCS

diff  --git a/libc/src/math/generic/fmaxf128.cpp b/libc/src/math/generic/fmaxf128.cpp
new file mode 100644
index 00000000000000..096e4befeb79a4
--- /dev/null
+++ b/libc/src/math/generic/fmaxf128.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of fmaxf128 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/fmaxf128.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float128, fmaxf128, (float128 x, float128 y)) {
+  return fputil::fmax(x, y);
+}
+
+} // namespace LIBC_NAMESPACE

diff  --git a/libc/src/math/generic/fminf128.cpp b/libc/src/math/generic/fminf128.cpp
new file mode 100644
index 00000000000000..084ed4c9931bc2
--- /dev/null
+++ b/libc/src/math/generic/fminf128.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of fminf128 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/fminf128.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float128, fminf128, (float128 x, float128 y)) {
+  return fputil::fmin(x, y);
+}
+
+} // namespace LIBC_NAMESPACE

diff  --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index a03342e428c301..eff97e9f1a34b4 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -990,7 +990,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
     HDRS
       FMinTest.h
     DEPENDS
-      libc.include.math
       libc.src.math.fminf
       libc.src.__support.FPUtil.fp_bits
   )
@@ -1004,7 +1003,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
     HDRS
       FMinTest.h
     DEPENDS
-      libc.include.math
       libc.src.math.fmin
       libc.src.__support.FPUtil.fp_bits
   )
@@ -1018,11 +1016,23 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
     HDRS
       FMinTest.h
     DEPENDS
-      libc.include.math
       libc.src.math.fminl
       libc.src.__support.FPUtil.fp_bits
   )
 
+  add_fp_unittest(
+    fminf128_test
+    SUITE
+      libc-math-smoke-tests
+    SRCS
+      fminf128_test.cpp
+    HDRS
+      FMinTest.h
+    DEPENDS
+      libc.src.math.fminf128
+      libc.src.__support.FPUtil.fp_bits
+  )
+
   add_fp_unittest(
     fmaxf_test
     SUITE
@@ -1032,7 +1042,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
     HDRS
       FMaxTest.h
     DEPENDS
-      libc.include.math
       libc.src.math.fmaxf
       libc.src.__support.FPUtil.fp_bits
   )
@@ -1046,7 +1055,6 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
     HDRS
       FMaxTest.h
     DEPENDS
-      libc.include.math
       libc.src.math.fmax
       libc.src.__support.FPUtil.fp_bits
   )
@@ -1060,10 +1068,22 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
     HDRS
       FMaxTest.h
     DEPENDS
-      libc.include.math
       libc.src.math.fmaxl
       libc.src.__support.FPUtil.fp_bits
   )
+  
+  add_fp_unittest(
+    fmaxf128_test
+    SUITE
+      libc-math-smoke-tests
+    SRCS
+      fmaxf128_test.cpp
+    HDRS
+      FMaxTest.h
+    DEPENDS
+      libc.src.math.fmaxf128
+      libc.src.__support.FPUtil.fp_bits
+  )
 endif()
 
 add_fp_unittest(

diff  --git a/libc/test/src/math/smoke/FMaxTest.h b/libc/test/src/math/smoke/FMaxTest.h
index 98edc8e971e816..1a376af2e0b7b4 100644
--- a/libc/test/src/math/smoke/FMaxTest.h
+++ b/libc/test/src/math/smoke/FMaxTest.h
@@ -9,8 +9,6 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <math.h>
-
 template <typename T> class FMaxTest : public LIBC_NAMESPACE::testing::Test {
 
   DECLARE_SPECIAL_CONSTANTS(T)
@@ -56,11 +54,13 @@ template <typename T> class FMaxTest : public LIBC_NAMESPACE::testing::Test {
     constexpr StorageType STEP = STORAGE_MAX / COUNT;
     for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
          ++i, v += STEP, w -= STEP) {
-      T x = FPBits(v).get_val(), y = FPBits(w).get_val();
-      if (isnan(x) || isinf(x))
+      FPBits xbits(v), ybits(w);
+      if (xbits.is_inf_or_nan())
         continue;
-      if (isnan(y) || isinf(y))
+      if (ybits.is_inf_or_nan())
         continue;
+      T x = xbits.get_val();
+      T y = ybits.get_val();
       if ((x == 0) && (y == 0))
         continue;
 

diff  --git a/libc/test/src/math/smoke/FMinTest.h b/libc/test/src/math/smoke/FMinTest.h
index 834d757c85d047..add2544424a016 100644
--- a/libc/test/src/math/smoke/FMinTest.h
+++ b/libc/test/src/math/smoke/FMinTest.h
@@ -9,8 +9,6 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <math.h>
-
 template <typename T> class FMinTest : public LIBC_NAMESPACE::testing::Test {
 
   DECLARE_SPECIAL_CONSTANTS(T)
@@ -56,11 +54,13 @@ template <typename T> class FMinTest : public LIBC_NAMESPACE::testing::Test {
     constexpr StorageType STEP = STORAGE_MAX / COUNT;
     for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
          ++i, v += STEP, w -= STEP) {
-      T x = FPBits(v).get_val(), y = FPBits(w).get_val();
-      if (isnan(x) || isinf(x))
+      FPBits xbits(v), ybits(w);
+      if (xbits.is_inf_or_nan())
         continue;
-      if (isnan(y) || isinf(y))
+      if (ybits.is_inf_or_nan())
         continue;
+      T x = xbits.get_val();
+      T y = ybits.get_val();
       if ((x == 0) && (y == 0))
         continue;
 

diff  --git a/libc/test/src/math/smoke/fmaxf128_test.cpp b/libc/test/src/math/smoke/fmaxf128_test.cpp
new file mode 100644
index 00000000000000..497cd05c623911
--- /dev/null
+++ b/libc/test/src/math/smoke/fmaxf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fmaxf128 --------------------------------------------===//
+//
+// 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 "FMaxTest.h"
+
+#include "src/math/fmaxf128.h"
+
+LIST_FMAX_TESTS(float128, LIBC_NAMESPACE::fmaxf128)

diff  --git a/libc/test/src/math/smoke/fminf128_test.cpp b/libc/test/src/math/smoke/fminf128_test.cpp
new file mode 100644
index 00000000000000..f1e9ed4e6ac8ee
--- /dev/null
+++ b/libc/test/src/math/smoke/fminf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fminf128 --------------------------------------------===//
+//
+// 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 "FMinTest.h"
+
+#include "src/math/fminf128.h"
+
+LIST_FMIN_TESTS(float128, LIBC_NAMESPACE::fminf128)


        


More information about the libc-commits mailing list