[libc-commits] [libc] 1048b59 - [libc][math] Add C23 math function fabsf128. (#77825)

via libc-commits libc-commits at lists.llvm.org
Fri Jan 12 12:00:19 PST 2024


Author: lntue
Date: 2024-01-12T15:00:16-05:00
New Revision: 1048b5999b4b1c970f3b454040d4352770e5cf5c

URL: https://github.com/llvm/llvm-project/commit/1048b5999b4b1c970f3b454040d4352770e5cf5c
DIFF: https://github.com/llvm/llvm-project/commit/1048b5999b4b1c970f3b454040d4352770e5cf5c.diff

LOG: [libc][math] Add C23 math function fabsf128. (#77825)

Added: 
    libc/src/math/fabsf128.h
    libc/src/math/generic/fabsf128.cpp
    libc/test/src/math/smoke/fabsf128_test.cpp

Modified: 
    libc/config/linux/aarch64/entrypoints.txt
    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

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index ce3f5eb40e38aa..0148e76d65380b 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -260,6 +260,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fabs
     libc.src.math.fabsf
     libc.src.math.fabsl
+    libc.src.math.fabs128
     libc.src.math.fdim
     libc.src.math.fdimf
     libc.src.math.fdiml
@@ -354,6 +355,13 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.truncl
 )
 
+if(LIBC_COMPILER_HAS_FLOAT128)
+  list(APPEND TARGET_LIBM_ENTRYPOINTS
+    # math.h C23 _Float128 entrypoints
+    libc.src.math.fabsf128
+  )
+endif()
+
 if(LLVM_LIBC_FULL_BUILD)
   list(APPEND TARGET_LIBC_ENTRYPOINTS
     # compiler entrypoints (no corresponding header)

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 30900de365bf95..094bdde2e1589c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -370,6 +370,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C23 _Float128 entrypoints
     libc.src.math.copysignf128
+    libc.src.math.fabsf128
   )
 endif()
 

diff  --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 3668524af03c27..724ad19dbe4426 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -128,6 +128,8 @@ Basic Operations
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fabsl        | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| |         |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| fabsf128     | |check| | |check| |         |         |         |         |         |         |         |         |         |         |
++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fdim         | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| |         |         |         |
 +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | fdimf        | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| |         |         |         |

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 78095eb23f0711..714dc21f95ba54 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -367,6 +367,7 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
           FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
           FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
+          FunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
 
           FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
           FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e2b1026fcad7e5..a8d3fbd475f07f 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -105,6 +105,7 @@ add_math_entrypoint_object(expm1f)
 add_math_entrypoint_object(fabs)
 add_math_entrypoint_object(fabsf)
 add_math_entrypoint_object(fabsl)
+add_math_entrypoint_object(fabsf128)
 
 add_math_entrypoint_object(fdim)
 add_math_entrypoint_object(fdimf)

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

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index eeb09652961fd5..887a8e6038a49d 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -196,6 +196,18 @@ add_entrypoint_object(
     -O2
 )
 
+add_entrypoint_object(
+  fabsf128
+  SRCS
+    fabsf128.cpp
+  HDRS
+    ../fabsf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+  COMPILE_OPTIONS
+    -O3
+)
+
 add_entrypoint_object(
   trunc
   SRCS

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

diff  --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 87b72e2a8eca2e..163fa924b243ac 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -87,6 +87,8 @@ add_fp_unittest(
 
 add_fp_unittest(
   fabsl_test
+  # FIXME: Currently fails on the GPU build.
+  UNIT_TEST_ONLY
   SUITE
     libc-math-smoke-tests
   SRCS
@@ -97,8 +99,22 @@ add_fp_unittest(
     libc.include.math
     libc.src.math.fabsl
     libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  fabsf128_test
   # FIXME: Currently fails on the GPU build.
   UNIT_TEST_ONLY
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    fabsf128_test.cpp
+  HDRS
+    FAbsTest.h
+  DEPENDS
+    libc.include.math
+    libc.src.math.fabsf128
+    libc.src.__support.FPUtil.fp_bits
 )
 
 add_fp_unittest(

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


        


More information about the libc-commits mailing list