Skip to content

[libc][math][c23] Add fadd{l,f128} C23 math functions #102531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 9, 2024
Merged
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/windows/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions libc/newhdrgen/yaml/math.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libc/spec/llvm_libc_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">,

Expand Down
2 changes: 2 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>]>,
Expand Down
3 changes: 3 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions libc/src/math/fadd.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//===-- 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.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#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);
Expand Down
21 changes: 21 additions & 0 deletions libc/src/math/faddf128.h
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/math/faddl.h
Original file line number Diff line number Diff line change
@@ -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
27 changes: 26 additions & 1 deletion libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/fadd.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/generic/faddf128.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/math/generic/faddl.cpp
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/faddl_test.cpp
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 35 additions & 5 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand Down Expand Up @@ -4623,6 +4649,8 @@ add_fp_unittest(
HDRS
AddTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.daddl
)

Expand All @@ -4635,6 +4663,8 @@ add_fp_unittest(
HDRS
AddTest.h
DEPENDS
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.math.daddf128
)

Expand Down
Loading