Skip to content

Commit 57b31d7

Browse files
aaryanshuklayuxuanchen1997
authored andcommitted
[libc][math]fadd implementation (#99694)
Summary: - **[libc] math fadd** - **[libc][math] implemented fadd** Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251269
1 parent edda35d commit 57b31d7

File tree

16 files changed

+115
-1
lines changed

16 files changed

+115
-1
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ set(TARGET_LIBM_ENTRYPOINTS
266266
libc.src.math.expm1f
267267
libc.src.math.fabs
268268
libc.src.math.fabsf
269+
libc.src.math.fadd
269270
libc.src.math.fdim
270271
libc.src.math.fdimf
271272
libc.src.math.floor

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ set(TARGET_LIBM_ENTRYPOINTS
370370
libc.src.math.fabs
371371
libc.src.math.fabsf
372372
libc.src.math.fabsl
373+
libc.src.math.fadd
373374
libc.src.math.fdim
374375
libc.src.math.fdimf
375376
libc.src.math.fdiml

libc/config/linux/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ set(TARGET_LIBM_ENTRYPOINTS
239239
libc.src.math.fabs
240240
libc.src.math.fabsf
241241
libc.src.math.fabsl
242+
libc.src.math.fadd
242243
libc.src.math.fdim
243244
libc.src.math.fdimf
244245
libc.src.math.fdiml

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ set(TARGET_LIBM_ENTRYPOINTS
371371
libc.src.math.fabs
372372
libc.src.math.fabsf
373373
libc.src.math.fabsl
374+
libc.src.math.fadd
374375
libc.src.math.fdim
375376
libc.src.math.fdimf
376377
libc.src.math.fdiml

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ set(TARGET_LIBM_ENTRYPOINTS
396396
libc.src.math.fabs
397397
libc.src.math.fabsf
398398
libc.src.math.fabsl
399+
libc.src.math.fadd
399400
libc.src.math.fdim
400401
libc.src.math.fdimf
401402
libc.src.math.fdiml

libc/config/windows/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ set(TARGET_LIBM_ENTRYPOINTS
144144
libc.src.math.fabs
145145
libc.src.math.fabsf
146146
libc.src.math.fabsl
147+
libc.src.math.fadd
147148
libc.src.math.fdim
148149
libc.src.math.fdimf
149150
libc.src.math.fdiml

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Basic Operations
136136
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
137137
| fabs | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 |
138138
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
139-
| fadd | N/A | | | N/A | | 7.12.14.1 | F.10.11 |
139+
| fadd | N/A | |check| | |check| | N/A | |check| | 7.12.14.1 | F.10.11 |
140140
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
141141
| fdim | |check| | |check| | |check| | |check| | |check| | 7.12.12.1 | F.10.9.1 |
142142
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def StdC : StandardSpec<"stdc"> {
402402
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
403403
GuardedFunctionSpec<"fabsf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
404404
GuardedFunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
405+
FunctionSpec<"fadd", RetValSpec<FloatType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
405406

406407
FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
407408
FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ add_math_entrypoint_object(fabsf)
141141
add_math_entrypoint_object(fabsl)
142142
add_math_entrypoint_object(fabsf16)
143143
add_math_entrypoint_object(fabsf128)
144+
add_math_entrypoint_object(fadd)
144145

145146
add_math_entrypoint_object(fdim)
146147
add_math_entrypoint_object(fdimf)

libc/src/math/fadd.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of fadd 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/__support/macros/config.h"
10+
11+
#ifndef LLVM_LIBC_SRC_MATH_FADD_H
12+
#define LLVM_LIBC_SRC_MATH_FADD_H
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
float fadd(double x, double y);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_FADD_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ add_entrypoint_object(
452452
-O3
453453
)
454454

455+
add_entrypoint_object(
456+
fadd
457+
SRCS
458+
fadd.cpp
459+
HDRS
460+
../fadd.h
461+
DEPENDS
462+
libc.src.__support.FPUtil.basic_operations
463+
COMPILE_OPTIONS
464+
-O3
465+
)
466+
455467
add_entrypoint_object(
456468
trunc
457469
SRCS

libc/src/math/generic/fadd.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of fadd 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/fadd.h"
10+
#include "src/__support/FPUtil/generic/add_sub.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(float, fadd, (double x, double y)) {
17+
return fputil::generic::add<float>(x, y);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ add_fp_unittest(
174174
libc.src.__support.FPUtil.fp_bits
175175
)
176176

177+
add_fp_unittest(
178+
fadd_test
179+
NEED_MPFR
180+
SUITE
181+
libc-math-unittests
182+
SRCS
183+
fadd_test.cpp
184+
HDRS
185+
AddTest.h
186+
DEPENDS
187+
libc.src.math.fadd
188+
libc.src.__support.FPUtil.basic_operations
189+
)
190+
177191
add_fp_unittest(
178192
trunc_test
179193
NEED_MPFR

libc/test/src/math/fadd_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fadd ----------------------------------------------===//
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 "AddTest.h"
10+
11+
#include "src/math/fadd.h"
12+
13+
LIST_ADD_TESTS(float, double, LIBC_NAMESPACE::fadd)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ add_fp_unittest(
141141
libc.src.__support.FPUtil.fp_bits
142142
)
143143

144+
add_fp_unittest(
145+
fadd_test
146+
SUITE
147+
libc-math-smoke-tests
148+
SRCS
149+
fadd_test.cpp
150+
HDRS
151+
AddTest.h
152+
DEPENDS
153+
libc.src.math.fadd
154+
libc.src.__support.FPUtil.basic_operations
155+
156+
)
157+
144158
add_fp_unittest(
145159
trunc_test
146160
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fadd ----------------------------------------------===//
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 "AddTest.h"
10+
11+
#include "src/math/fadd.h"
12+
13+
LIST_ADD_TESTS(float, double, LIBC_NAMESPACE::fadd)

0 commit comments

Comments
 (0)