[libc][math][c23] Add dadd{l,f128} and ddiv{l,f128} C23 math functions (#100456)

- fadd removed because I need to add for different input types
- finishing rest of basic operations
- noticed duplicates will remove

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
This commit is contained in:
aaryanshukla
2024-08-01 13:36:50 -07:00
committed by GitHub
parent 97f723bab0
commit 8f33f1d829
24 changed files with 282 additions and 2 deletions

View File

@@ -148,6 +148,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cospif
libc.src.math.dfmal
libc.src.math.dsqrtl
libc.src.math.daddl
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp

View File

@@ -119,6 +119,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.ceill
#libc.src.math.coshf
#libc.src.math.cosf
#libc.src.math.daddl
#libc.src.math.dfmal
#libc.src.math.dsqrtl
#libc.src.math.dsubl

View File

@@ -363,6 +363,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.cospif
libc.src.math.daddl
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl
@@ -618,6 +619,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
# math.h C23 _Float128 entrypoints
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
libc.src.math.ddivf128
libc.src.math.dfmaf128
libc.src.math.dsqrtf128
libc.src.math.dsubf128

View File

@@ -228,6 +228,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cos
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.daddl
libc.src.math.dfmal
libc.src.math.dsqrtl
libc.src.math.erff

View File

@@ -386,6 +386,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.cospif
libc.src.math.daddl
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl

View File

@@ -389,6 +389,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl
libc.src.math.daddl
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp
@@ -660,6 +661,8 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.canonicalizef128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
libc.src.math.ddivf128
libc.src.math.dfmaf128
libc.src.math.dmulf128
libc.src.math.dsqrtf128

View File

@@ -133,6 +133,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cos
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.daddl
libc.src.math.dfmal
libc.src.math.dsubl
libc.src.math.erff

View File

@@ -114,9 +114,9 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| copysign | |check| | |check| | |check| | |check| | |check| | 7.12.11.1 | F.10.8.1 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dadd | N/A | N/A | | N/A | | 7.12.14.1 | F.10.11 |
| dadd | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.1 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| ddiv | N/A | N/A | | N/A | | 7.12.14.4 | F.10.11 |
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

View File

@@ -57,6 +57,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
[], // Types
[], // Enumerations
[
GuardedFunctionSpec<"daddf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"ddivf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"dfmaf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"dsqrtf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"dsubf128", RetValSpec<DoubleType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

View File

@@ -396,6 +396,8 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"ceill", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"ceilf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"daddl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"dfmal", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"dsubl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

View File

@@ -86,6 +86,9 @@ add_math_entrypoint_object(cosh)
add_math_entrypoint_object(coshf)
add_math_entrypoint_object(cospif)
add_math_entrypoint_object(daddl)
add_math_entrypoint_object(daddf128)
add_math_entrypoint_object(ddivf128)
add_math_entrypoint_object(dmull)
add_math_entrypoint_object(dmulf128)

21
libc/src/math/daddf128.h Normal file
View File

@@ -0,0 +1,21 @@
//===-- Implementation header for daddf128 ----------------------*- 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_DADDF128_H
#define LLVM_LIBC_SRC_MATH_DADDF128_H
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
double daddf128(float128 x, float128 y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_DADDF128_H

20
libc/src/math/daddl.h Normal file
View File

@@ -0,0 +1,20 @@
//===-- Implementation header for daddl -------------------------*- 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_DADDL_H
#define LLVM_LIBC_SRC_MATH_DADDL_H
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
double daddl(long double x, long double y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_DADDL_H

21
libc/src/math/ddivf128.h Normal file
View File

@@ -0,0 +1,21 @@
//===-- Implementation header for ddivf128 ----------------------*- 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_DDIVF128_H
#define LLVM_LIBC_SRC_MATH_DDIVF128_H
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
double ddivf128(float128 x, float128 y);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_MATH_DDIVF128_H

View File

@@ -129,6 +129,44 @@ add_entrypoint_object(
libc.src.__support.FPUtil.nearest_integer_operations
)
add_entrypoint_object(
daddl
SRCS
daddl.cpp
HDRS
../daddl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
)
add_entrypoint_object(
daddf128
SRCS
daddf128.cpp
HDRS
../daddf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.add_sub
)
add_entrypoint_object(
ddivf128
SRCS
ddivf128.cpp
HDRS
../ddivf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.div
)
add_entrypoint_object(
dfmaf128
SRCS

View File

@@ -0,0 +1,20 @@
//===-- Implementation of daddf128 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/daddf128.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(double, daddf128, (float128 x, float128 y)) {
return fputil::generic::add<double>(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@@ -0,0 +1,20 @@
//===-- Implementation of daddl 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/daddl.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(double, daddl, (long double x, long double y)) {
return fputil::generic::add<double>(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@@ -0,0 +1,20 @@
//===-- Implementation of ddivf128 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/ddivf128.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, ddivf128, (float128 x, float128 y)) {
return fputil::generic::div<double>(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@@ -44,6 +44,20 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
daddl_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
daddl_test.cpp
HDRS
AddTest.h
DEPENDS
libc.src.math.daddl
)
add_fp_unittest(
sinf_test
NEED_MPFR

View File

@@ -0,0 +1,13 @@
//===-- Unittests for daddl -----------------------------------------------===//
//
// 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/daddl.h"
LIST_ADD_TESTS(double, long double, LIBC_NAMESPACE::daddl)

View File

@@ -4385,3 +4385,39 @@ add_fp_unittest(
libc.src.__support.FPUtil.basic_operations
libc.src.math.f16mulf128
)
add_fp_unittest(
daddl
SUITE
libc-math-smoke-tests
SRCS
daddl_test.cpp
HDRS
AddTest.h
DEPENDS
libc.src.math.daddl
)
add_fp_unittest(
daddf128
SUITE
libc-math-smoke-tests
SRCS
daddf128_test.cpp
HDRS
AddTest.h
DEPENDS
libc.src.math.daddf128
)
add_fp_unittest(
ddivf128
SUITE
libc-math-smoke-tests
SRCS
ddivf128_test.cpp
HDRS
DivTest.h
DEPENDS
libc.src.math.ddivf128
)

View File

@@ -0,0 +1,13 @@
//===-- Unittests for daddf128 --------------------------------------------===//
//
// 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/daddf128.h"
LIST_ADD_TESTS(double, float128, LIBC_NAMESPACE::daddf128)

View File

@@ -0,0 +1,13 @@
//===-- Unittests for daddl -----------------------------------------------===//
//
// 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/daddl.h"
LIST_ADD_TESTS(double, long double, LIBC_NAMESPACE::daddl)

View File

@@ -0,0 +1,13 @@
//===-- Unittests for ddivf128 --------------------------------------------===//
//
// 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 "DivTest.h"
#include "src/math/ddivf128.h"
LIST_DIV_TESTS(double, float128, LIBC_NAMESPACE::ddivf128)