[libc-commits] [libc] 8c81fb6 - [libc][math][c23] Add fadd{l, f128} C23 math functions (#102531)
via libc-commits
libc-commits at lists.llvm.org
Fri Aug 9 10:26:13 PDT 2024
Author: aaryanshukla
Date: 2024-08-09T10:26:09-07:00
New Revision: 8c81fb616747ebe2be0159696627e691ff186561
URL: https://github.com/llvm/llvm-project/commit/8c81fb616747ebe2be0159696627e691ff186561
DIFF: https://github.com/llvm/llvm-project/commit/8c81fb616747ebe2be0159696627e691ff186561.diff
LOG: [libc][math][c23] Add fadd{l,f128} C23 math functions (#102531)
Co-authored-by: OverMighty <its.overmighty at gmail.com>
Added:
libc/src/math/faddf128.h
libc/src/math/faddl.h
libc/src/math/generic/faddf128.cpp
libc/src/math/generic/faddl.cpp
libc/test/src/math/faddl_test.cpp
libc/test/src/math/smoke/faddf128_test.cpp
libc/test/src/math/smoke/faddl_test.cpp
Modified:
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/arm/entrypoints.txt
libc/config/linux/riscv/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/config/windows/entrypoints.txt
libc/newhdrgen/yaml/math.yaml
libc/spec/llvm_libc_ext.td
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/src/math/fadd.h
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/fadd.cpp
libc/test/src/math/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 75e010e63c92df..d22bd1153598eb 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -407,6 +407,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
+ libc.src.math.faddl
libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
@@ -692,6 +694,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.dsqrtf128
libc.src.math.dsubf128
libc.src.math.fabsf128
+ libc.src.math.faddf128
libc.src.math.fdimf128
libc.src.math.fdivf128
libc.src.math.ffmaf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 02265aef6fdfb4..1be9a872dd2f7f 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -242,6 +242,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
+ libc.src.math.faddl
libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index f80e741115e793..1a647737ec455a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -406,6 +406,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
+ libc.src.math.faddl
libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
@@ -599,6 +601,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.dsqrtf128
libc.src.math.dsubf128
libc.src.math.fabsf128
+ libc.src.math.faddf128
libc.src.math.fdimf128
libc.src.math.fdivf128
libc.src.math.ffmaf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 683ac8b1c71e37..748401e4cf8ee8 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -406,6 +406,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabs
libc.src.math.fabsf
libc.src.math.fabsl
+ libc.src.math.fadd
+ libc.src.math.faddl
libc.src.math.fadd
libc.src.math.fdim
libc.src.math.fdimf
@@ -688,6 +690,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.dsqrtf128
libc.src.math.dsubf128
libc.src.math.fabsf128
+ libc.src.math.faddf128
libc.src.math.fdimf128
libc.src.math.fdivf128
libc.src.math.ffmaf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 7fa7eb22772e29..8f0b50bcc83ea2 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -153,6 +153,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fabsf
libc.src.math.fabsl
libc.src.math.fadd
+ libc.src.math.faddl
libc.src.math.fdim
libc.src.math.fdimf
libc.src.math.fdiml
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index 025f5fa48bf60b..080f6ac0ee8884 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -76,6 +76,28 @@ functions:
return_type: long double
arguments:
- type: long double
+ - name: fadd
+ standards:
+ - stdc
+ return_type: float
+ arguments:
+ - type: double
+ - type: double
+ - name: faddl
+ standards:
+ - faddl
+ return_type: float
+ arguments:
+ - type: long double
+ - type: long double
+ - name: faddf128
+ standards:
+ - llvm_libc_ext
+ return_type: float
+ arguments:
+ - type: float128
+ - type: float128
+ guard: LIBC_TYPES_HAS_FLOAT128
- name: fdim
standards:
- stdc
diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td
index 5ae8d53326336e..cd63e34a44ef0a 100644
--- a/libc/spec/llvm_libc_ext.td
+++ b/libc/spec/llvm_libc_ext.td
@@ -71,6 +71,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16subf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16subl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
+
+ GuardedFunctionSpec<"faddf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"fdivf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index b3b087ab3b58ad..077f66e78c1167 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -407,7 +407,9 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"fabsf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
FunctionSpec<"fadd", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
+ FunctionSpec<"faddl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
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 7f1800ab3480d7..9f13205a60702e 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -161,7 +161,10 @@ add_math_entrypoint_object(fabsf)
add_math_entrypoint_object(fabsl)
add_math_entrypoint_object(fabsf16)
add_math_entrypoint_object(fabsf128)
+
add_math_entrypoint_object(fadd)
+add_math_entrypoint_object(faddl)
+add_math_entrypoint_object(faddf128)
add_math_entrypoint_object(fdim)
add_math_entrypoint_object(fdimf)
diff --git a/libc/src/math/fadd.h b/libc/src/math/fadd.h
index ec3ce18bb676a6..fe795687f9ac55 100644
--- a/libc/src/math/fadd.h
+++ b/libc/src/math/fadd.h
@@ -1,4 +1,4 @@
-//===-- Implementation of fadd function ----------------------------------===//
+//===-- Implementation of fadd function -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/macros/config.h"
-
#ifndef LLVM_LIBC_SRC_MATH_FADD_H
#define LLVM_LIBC_SRC_MATH_FADD_H
+#include "src/__support/macros/config.h"
+
namespace LIBC_NAMESPACE_DECL {
float fadd(double x, double y);
diff --git a/libc/src/math/faddf128.h b/libc/src/math/faddf128.h
new file mode 100644
index 00000000000000..73e5ff11f7a81a
--- /dev/null
+++ b/libc/src/math/faddf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation of faddf128 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_FADDF128_H
+#define LLVM_LIBC_SRC_MATH_FADDF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float faddf128(float128 x, float128 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FADDF128_H
diff --git a/libc/src/math/faddl.h b/libc/src/math/faddl.h
new file mode 100644
index 00000000000000..b1dc2069e3956a
--- /dev/null
+++ b/libc/src/math/faddl.h
@@ -0,0 +1,20 @@
+//===-- Implementation of faddl 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_FADDL_H
+#define LLVM_LIBC_SRC_MATH_FADDL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float faddl(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FADDL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 534036aa364560..79ba07616e507f 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -593,7 +593,32 @@ add_entrypoint_object(
HDRS
../fadd.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.generic.add_sub
+ COMPILE_OPTIONS
+ -O3
+)
+
+add_entrypoint_object(
+ faddl
+ SRCS
+ faddl.cpp
+ HDRS
+ ../faddl.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.add_sub
+ COMPILE_OPTIONS
+ -O3
+)
+
+add_entrypoint_object(
+ faddf128
+ SRCS
+ faddf128.cpp
+ HDRS
+ ../faddf128.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.macros.properties.types
COMPILE_OPTIONS
-O3
)
diff --git a/libc/src/math/generic/fadd.cpp b/libc/src/math/generic/fadd.cpp
index 66e5188cbcfd4c..60460f87086570 100644
--- a/libc/src/math/generic/fadd.cpp
+++ b/libc/src/math/generic/fadd.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation of fadd function ----------------------------------===//
+//===-- Implementation of fadd function -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/math/generic/faddf128.cpp b/libc/src/math/generic/faddf128.cpp
new file mode 100644
index 00000000000000..953b1a1ce092ee
--- /dev/null
+++ b/libc/src/math/generic/faddf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of faddf128 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/faddf128.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, faddf128, (float128 x, float128 y)) {
+ return fputil::generic::add<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/faddl.cpp b/libc/src/math/generic/faddl.cpp
new file mode 100644
index 00000000000000..b5c6ab4031c383
--- /dev/null
+++ b/libc/src/math/generic/faddl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of faddl 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/faddl.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, faddl, (long double x, long double y)) {
+ return fputil::generic::add<float>(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index d0106972809cc0..a8da72fb01be61 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -202,6 +202,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.basic_operations
)
+add_fp_unittest(
+ faddl_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ faddl_test.cpp
+ HDRS
+ AddTest.h
+ DEPENDS
+ libc.src.math.faddl
+)
+
add_fp_unittest(
trunc_test
NEED_MPFR
diff --git a/libc/test/src/math/faddl_test.cpp b/libc/test/src/math/faddl_test.cpp
new file mode 100644
index 00000000000000..9c99b32ee7c422
--- /dev/null
+++ b/libc/test/src/math/faddl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for faddl -----------------------------------------------===//
+//
+// 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 "AddTest.h"
+
+#include "src/math/faddl.h"
+
+LIST_ADD_TESTS(float, long double, LIBC_NAMESPACE::faddl)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9fe61672f7258d..460797b74a13e2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -150,9 +150,39 @@ add_fp_unittest(
HDRS
AddTest.h
DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
libc.src.math.fadd
- libc.src.__support.FPUtil.basic_operations
+)
+add_fp_unittest(
+ faddl_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ faddl_test.cpp
+ HDRS
+ AddTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.faddl
+)
+
+add_fp_unittest(
+ faddf128_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ faddf128_test.cpp
+ HDRS
+ AddTest.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.faddf128
)
add_fp_unittest(
@@ -4125,7 +4155,6 @@ add_fp_unittest(
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16add
)
@@ -4140,7 +4169,6 @@ add_fp_unittest(
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16addf
)
@@ -4155,7 +4183,6 @@ add_fp_unittest(
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16addl
)
@@ -4170,7 +4197,6 @@ add_fp_unittest(
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.__support.FPUtil.basic_operations
libc.src.math.f16addf128
)
@@ -4707,6 +4733,8 @@ add_fp_unittest(
HDRS
AddTest.h
DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
libc.src.math.daddl
)
@@ -4719,6 +4747,8 @@ add_fp_unittest(
HDRS
AddTest.h
DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
libc.src.math.daddf128
)
diff --git a/libc/test/src/math/smoke/faddf128_test.cpp b/libc/test/src/math/smoke/faddf128_test.cpp
new file mode 100644
index 00000000000000..5a11b5f419cad2
--- /dev/null
+++ b/libc/test/src/math/smoke/faddf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for faddf128 --------------------------------------------===//
+//
+// 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 "AddTest.h"
+
+#include "src/math/faddf128.h"
+
+LIST_ADD_TESTS(float, float128, LIBC_NAMESPACE::faddf128)
diff --git a/libc/test/src/math/smoke/faddl_test.cpp b/libc/test/src/math/smoke/faddl_test.cpp
new file mode 100644
index 00000000000000..9c99b32ee7c422
--- /dev/null
+++ b/libc/test/src/math/smoke/faddl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for faddl -----------------------------------------------===//
+//
+// 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 "AddTest.h"
+
+#include "src/math/faddl.h"
+
+LIST_ADD_TESTS(float, long double, LIBC_NAMESPACE::faddl)
More information about the libc-commits
mailing list