Skip to content

Commit

Permalink
[libc][math][c23] Add ddivl C23 math function. (llvm#102468)
Browse files Browse the repository at this point in the history
  • Loading branch information
lntue authored Aug 8, 2024
1 parent 722c066 commit eddfd50
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 9 deletions.
1 change: 1 addition & 0 deletions libc/config/darwin/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.dfmal
libc.src.math.dsqrtl
libc.src.math.daddl
libc.src.math.ddivl
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp
Expand Down
1 change: 1 addition & 0 deletions libc/config/darwin/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.coshf
#libc.src.math.cosf
#libc.src.math.daddl
#libc.src.math.ddivl
#libc.src.math.dfmal
#libc.src.math.dsqrtl
#libc.src.math.dsubl
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.coshf
libc.src.math.cospif
libc.src.math.daddl
libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.coshf
libc.src.math.cospif
libc.src.math.daddl
libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dmull
libc.src.math.dsqrtl
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.dmull
libc.src.math.dsqrtl
libc.src.math.daddl
libc.src.math.ddivl
libc.src.math.dsubl
libc.src.math.erff
libc.src.math.exp
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 @@ -137,6 +137,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.cosf
libc.src.math.coshf
libc.src.math.daddl
libc.src.math.ddivl
libc.src.math.dfmal
libc.src.math.dsubl
libc.src.math.erff
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| dadd | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.1 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
| ddiv | N/A | N/A | |check| | 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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
7 changes: 7 additions & 0 deletions libc/newhdrgen/yaml/math.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2352,3 +2352,10 @@ functions:
arguments:
- type: long double
- type: int *
- name: ddivl
standards:
- stdc
return_type: long double
arguments:
- type: long double
- type: long double
2 changes: 1 addition & 1 deletion libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"daddl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

FunctionSpec<"ddivl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"dfmal", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"dsubl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/div.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ div(InType x, InType y) {
using InFPBits = FPBits<InType>;
using InStorageType = typename InFPBits::StorageType;
using DyadicFloat =
DyadicFloat<cpp::bit_ceil(static_cast<size_t>(InFPBits::FRACTION_LEN))>;
DyadicFloat<cpp::bit_ceil(static_cast<size_t>(InFPBits::SIG_LEN + 1))>;

InFPBits x_bits(x);
InFPBits y_bits(y);
Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ add_math_entrypoint_object(cospif)

add_math_entrypoint_object(daddl)
add_math_entrypoint_object(daddf128)
add_math_entrypoint_object(ddivl)
add_math_entrypoint_object(ddivf128)
add_math_entrypoint_object(dmull)
add_math_entrypoint_object(dmulf128)
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/ddivl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for ddivl -------------------------*- 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_DDIVL_H
#define LLVM_LIBC_SRC_MATH_DDIVL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

double ddivl(long double x, long double y);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_DDIVL_H
12 changes: 12 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ add_entrypoint_object(
libc.src.__support.FPUtil.generic.add_sub
)

add_entrypoint_object(
ddivl
SRCS
ddivl.cpp
HDRS
../ddivl.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.FPUtil.generic.div
)

add_entrypoint_object(
ddivf128
SRCS
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/generic/ddivl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of ddivl 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/ddivl.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, ddivl, (long double x, long double y)) {
return fputil::generic::div<double>(x, y);
}

} // namespace LIBC_NAMESPACE_DECL
14 changes: 13 additions & 1 deletion libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,19 @@ add_fp_unittest(
libc.src.stdlib.srand
)

add_fp_unittest(
ddivl_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
ddivl_test.cpp
HDRS
DivTest.h
DEPENDS
libc.src.math.ddivl
)

add_fp_unittest(
dfmal_test
NEED_MPFR
Expand Down Expand Up @@ -2518,7 +2531,6 @@ add_fp_unittest(
libc.src.math.fdivl
)


add_fp_unittest(
ffma_test
NEED_MPFR
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/DivTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
InType x = InFPBits(v).get_val();
InType y = InFPBits(w).get_val();
mpfr::BinaryInput<InType> input{x, y};
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
0.5);
}
}
Expand All @@ -60,7 +60,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
InType x = InFPBits(v).get_val();
InType y = InFPBits(w).get_val();
mpfr::BinaryInput<InType> input{x, y};
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
0.5);
}
}
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/ddivl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ddivl -----------------------------------------------===//
//
// 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/ddivl.h"

LIST_DIV_TESTS(double, long double, LIBC_NAMESPACE::ddivl)
18 changes: 15 additions & 3 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4615,7 +4615,7 @@ add_fp_unittest(
)

add_fp_unittest(
daddl
daddl_test
SUITE
libc-math-smoke-tests
SRCS
Expand All @@ -4627,7 +4627,7 @@ add_fp_unittest(
)

add_fp_unittest(
daddf128
daddf128_test
SUITE
libc-math-smoke-tests
SRCS
Expand All @@ -4639,7 +4639,19 @@ add_fp_unittest(
)

add_fp_unittest(
ddivf128
ddivl_test
SUITE
libc-math-smoke-tests
SRCS
ddivl_test.cpp
HDRS
DivTest.h
DEPENDS
libc.src.math.ddivl
)

add_fp_unittest(
ddivf128_test
SUITE
libc-math-smoke-tests
SRCS
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/ddivl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ddivl -----------------------------------------------===//
//
// 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/ddivl.h"

LIST_DIV_TESTS(double, long double, LIBC_NAMESPACE::ddivl)

0 comments on commit eddfd50

Please sign in to comment.