diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 034db23932a39..f57ae6fcd2e06 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 @@ -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/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 9d3ab0c157aa8..9aebed5a880ed 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 e2d8e9e324967..bfdd87e6c7412 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 @@ -595,6 +597,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 817f4190399aa..6f6bee21257a5 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 @@ -684,6 +686,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 1f36bdf9b21ee..72a8931d9e624 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 1b474b3401ecb..9436fc9fcacae 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 5ae8d53326336..cd63e34a44ef0 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, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"f16subf", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"f16subl", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + + GuardedFunctionSpec<"faddf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, GuardedFunctionSpec<"fdivf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 082b1e499e0d0..449625b8cab3e 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -407,7 +407,9 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"fabsl", RetValSpec, [ArgSpec]>, GuardedFunctionSpec<"fabsf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"fabsf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + FunctionSpec<"fadd", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"faddl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fdim", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fdimf", RetValSpec, [ArgSpec, ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index a07065c93003f..0391e1e5c3845 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 ec3ce18bb676a..fe795687f9ac5 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 0000000000000..73e5ff11f7a81 --- /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 0000000000000..b1dc2069e3956 --- /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 a224bed8c3a14..ea62bc5380585 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 66e5188cbcfd4..60460f8708657 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 0000000000000..953b1a1ce092e --- /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(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 0000000000000..b5c6ab4031c38 --- /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(x, y); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index d0106972809cc..a8da72fb01be6 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 0000000000000..9c99b32ee7c42 --- /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 ef303228a9fe0..e3c96eac4ce10 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( @@ -4041,7 +4071,6 @@ add_fp_unittest( DEPENDS libc.hdr.errno_macros libc.hdr.fenv_macros - libc.src.__support.FPUtil.basic_operations libc.src.math.f16add ) @@ -4056,7 +4085,6 @@ add_fp_unittest( DEPENDS libc.hdr.errno_macros libc.hdr.fenv_macros - libc.src.__support.FPUtil.basic_operations libc.src.math.f16addf ) @@ -4071,7 +4099,6 @@ add_fp_unittest( DEPENDS libc.hdr.errno_macros libc.hdr.fenv_macros - libc.src.__support.FPUtil.basic_operations libc.src.math.f16addl ) @@ -4086,7 +4113,6 @@ add_fp_unittest( DEPENDS libc.hdr.errno_macros libc.hdr.fenv_macros - libc.src.__support.FPUtil.basic_operations libc.src.math.f16addf128 ) @@ -4623,6 +4649,8 @@ add_fp_unittest( HDRS AddTest.h DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros libc.src.math.daddl ) @@ -4635,6 +4663,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 0000000000000..5a11b5f419cad --- /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 0000000000000..9c99b32ee7c42 --- /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)