Skip to content

Commit eddfd50

Browse files
authored
[libc][math][c23] Add ddivl C23 math function. (#102468)
1 parent 722c066 commit eddfd50

File tree

19 files changed

+125
-9
lines changed

19 files changed

+125
-9
lines changed

libc/config/darwin/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ set(TARGET_LIBM_ENTRYPOINTS
149149
libc.src.math.dfmal
150150
libc.src.math.dsqrtl
151151
libc.src.math.daddl
152+
libc.src.math.ddivl
152153
libc.src.math.dsubl
153154
libc.src.math.erff
154155
libc.src.math.exp

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ set(TARGET_LIBM_ENTRYPOINTS
120120
#libc.src.math.coshf
121121
#libc.src.math.cosf
122122
#libc.src.math.daddl
123+
#libc.src.math.ddivl
123124
#libc.src.math.dfmal
124125
#libc.src.math.dsqrtl
125126
#libc.src.math.dsubl

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ set(TARGET_LIBM_ENTRYPOINTS
389389
libc.src.math.coshf
390390
libc.src.math.cospif
391391
libc.src.math.daddl
392+
libc.src.math.ddivl
392393
libc.src.math.dfmal
393394
libc.src.math.dmull
394395
libc.src.math.dsqrtl

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ set(TARGET_LIBM_ENTRYPOINTS
388388
libc.src.math.coshf
389389
libc.src.math.cospif
390390
libc.src.math.daddl
391+
libc.src.math.ddivl
391392
libc.src.math.dfmal
392393
libc.src.math.dmull
393394
libc.src.math.dsqrtl

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ set(TARGET_LIBM_ENTRYPOINTS
391391
libc.src.math.dmull
392392
libc.src.math.dsqrtl
393393
libc.src.math.daddl
394+
libc.src.math.ddivl
394395
libc.src.math.dsubl
395396
libc.src.math.erff
396397
libc.src.math.exp

libc/config/windows/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ set(TARGET_LIBM_ENTRYPOINTS
137137
libc.src.math.cosf
138138
libc.src.math.coshf
139139
libc.src.math.daddl
140+
libc.src.math.ddivl
140141
libc.src.math.dfmal
141142
libc.src.math.dsubl
142143
libc.src.math.erff

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Basic Operations
116116
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
117117
| dadd | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.1 | F.10.11 |
118118
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
119-
| ddiv | N/A | N/A | | N/A | |check|\* | 7.12.14.4 | F.10.11 |
119+
| ddiv | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.4 | F.10.11 |
120120
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
121121
| dfma | N/A | N/A | |check| | N/A | |check|\* | 7.12.14.5 | F.10.11 |
122122
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/newhdrgen/yaml/math.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,3 +2352,10 @@ functions:
23522352
arguments:
23532353
- type: long double
23542354
- type: int *
2355+
- name: ddivl
2356+
standards:
2357+
- stdc
2358+
return_type: long double
2359+
arguments:
2360+
- type: long double
2361+
- type: long double

libc/spec/stdc.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def StdC : StandardSpec<"stdc"> {
398398
GuardedFunctionSpec<"ceilf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
399399

400400
FunctionSpec<"daddl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
401-
401+
FunctionSpec<"ddivl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
402402
FunctionSpec<"dfmal", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
403403
FunctionSpec<"dsubl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
404404

libc/src/__support/FPUtil/generic/div.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ div(InType x, InType y) {
3535
using InFPBits = FPBits<InType>;
3636
using InStorageType = typename InFPBits::StorageType;
3737
using DyadicFloat =
38-
DyadicFloat<cpp::bit_ceil(static_cast<size_t>(InFPBits::FRACTION_LEN))>;
38+
DyadicFloat<cpp::bit_ceil(static_cast<size_t>(InFPBits::SIG_LEN + 1))>;
3939

4040
InFPBits x_bits(x);
4141
InFPBits y_bits(y);

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ add_math_entrypoint_object(cospif)
8888

8989
add_math_entrypoint_object(daddl)
9090
add_math_entrypoint_object(daddf128)
91+
add_math_entrypoint_object(ddivl)
9192
add_math_entrypoint_object(ddivf128)
9293
add_math_entrypoint_object(dmull)
9394
add_math_entrypoint_object(dmulf128)

libc/src/math/ddivl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for ddivl -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_DDIVL_H
10+
#define LLVM_LIBC_SRC_MATH_DDIVL_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
double ddivl(long double x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_DDIVL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ add_entrypoint_object(
154154
libc.src.__support.FPUtil.generic.add_sub
155155
)
156156

157+
add_entrypoint_object(
158+
ddivl
159+
SRCS
160+
ddivl.cpp
161+
HDRS
162+
../ddivl.h
163+
COMPILE_OPTIONS
164+
-O3
165+
DEPENDS
166+
libc.src.__support.FPUtil.generic.div
167+
)
168+
157169
add_entrypoint_object(
158170
ddivf128
159171
SRCS

libc/src/math/generic/ddivl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of ddivl function ----------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/ddivl.h"
10+
#include "src/__support/FPUtil/generic/div.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(double, ddivl, (long double x, long double y)) {
17+
return fputil::generic::div<double>(x, y);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,19 @@ add_fp_unittest(
24642464
libc.src.stdlib.srand
24652465
)
24662466

2467+
add_fp_unittest(
2468+
ddivl_test
2469+
NEED_MPFR
2470+
SUITE
2471+
libc-math-unittests
2472+
SRCS
2473+
ddivl_test.cpp
2474+
HDRS
2475+
DivTest.h
2476+
DEPENDS
2477+
libc.src.math.ddivl
2478+
)
2479+
24672480
add_fp_unittest(
24682481
dfmal_test
24692482
NEED_MPFR
@@ -2518,7 +2531,6 @@ add_fp_unittest(
25182531
libc.src.math.fdivl
25192532
)
25202533

2521-
25222534
add_fp_unittest(
25232535
ffma_test
25242536
NEED_MPFR

libc/test/src/math/DivTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
4747
InType x = InFPBits(v).get_val();
4848
InType y = InFPBits(w).get_val();
4949
mpfr::BinaryInput<InType> input{x, y};
50-
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
50+
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
5151
0.5);
5252
}
5353
}
@@ -60,7 +60,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
6060
InType x = InFPBits(v).get_val();
6161
InType y = InFPBits(w).get_val();
6262
mpfr::BinaryInput<InType> input{x, y};
63-
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
63+
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Div, input, func(x, y),
6464
0.5);
6565
}
6666
}

libc/test/src/math/ddivl_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for ddivl -----------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "DivTest.h"
10+
11+
#include "src/math/ddivl.h"
12+
13+
LIST_DIV_TESTS(double, long double, LIBC_NAMESPACE::ddivl)

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,7 +4615,7 @@ add_fp_unittest(
46154615
)
46164616

46174617
add_fp_unittest(
4618-
daddl
4618+
daddl_test
46194619
SUITE
46204620
libc-math-smoke-tests
46214621
SRCS
@@ -4627,7 +4627,7 @@ add_fp_unittest(
46274627
)
46284628

46294629
add_fp_unittest(
4630-
daddf128
4630+
daddf128_test
46314631
SUITE
46324632
libc-math-smoke-tests
46334633
SRCS
@@ -4639,7 +4639,19 @@ add_fp_unittest(
46394639
)
46404640

46414641
add_fp_unittest(
4642-
ddivf128
4642+
ddivl_test
4643+
SUITE
4644+
libc-math-smoke-tests
4645+
SRCS
4646+
ddivl_test.cpp
4647+
HDRS
4648+
DivTest.h
4649+
DEPENDS
4650+
libc.src.math.ddivl
4651+
)
4652+
4653+
add_fp_unittest(
4654+
ddivf128_test
46434655
SUITE
46444656
libc-math-smoke-tests
46454657
SRCS
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for ddivl -----------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "DivTest.h"
10+
11+
#include "src/math/ddivl.h"
12+
13+
LIST_DIV_TESTS(double, long double, LIBC_NAMESPACE::ddivl)

0 commit comments

Comments
 (0)