Skip to content

Commit 13e6ffd

Browse files
authored
[libc][math] Refactor fadd family to header-only (llvm#182185)
Refactors the fadd math family to be header-only. Closes llvm#182184 Target Functions: - fadd - faddf128 - faddl
1 parent f6fb24d commit 13e6ffd

File tree

15 files changed

+246
-20
lines changed

15 files changed

+246
-20
lines changed

libc/shared/math.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
#include "math/f16sqrt.h"
9090
#include "math/f16sqrtf.h"
9191
#include "math/f16sqrtl.h"
92+
#include "math/fadd.h"
93+
#include "math/faddf128.h"
94+
#include "math/faddl.h"
9295
#include "math/ffma.h"
9396
#include "math/ffmal.h"
9497
#include "math/fmax.h"

libc/shared/math/fadd.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Shared fadd function ------------------------------------*- 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_SHARED_MATH_FADD_H
10+
#define LLVM_LIBC_SHARED_MATH_FADD_H
11+
12+
#include "src/__support/math/fadd.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
namespace shared {
16+
17+
using math::fadd;
18+
19+
} // namespace shared
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SHARED_MATH_FADD_H

libc/shared/math/faddf128.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Shared faddf128 function --------------------------------*- 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_SHARED_MATH_FADDF128_H
10+
#define LLVM_LIBC_SHARED_MATH_FADDF128_H
11+
12+
#include "include/llvm-libc-types/float128.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT128
15+
16+
#include "src/__support/math/faddf128.h"
17+
18+
namespace LIBC_NAMESPACE_DECL {
19+
namespace shared {
20+
21+
using math::faddf128;
22+
23+
} // namespace shared
24+
} // namespace LIBC_NAMESPACE_DECL
25+
26+
#endif // LIBC_TYPES_HAS_FLOAT128
27+
28+
#endif // LLVM_LIBC_SHARED_MATH_FADDF128_H

libc/shared/math/faddl.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Shared faddl function -----------------------------------*- 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_SHARED_MATH_FADDL_H
10+
#define LLVM_LIBC_SHARED_MATH_FADDL_H
11+
12+
#include "src/__support/math/faddl.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
namespace shared {
16+
17+
using math::faddl;
18+
19+
} // namespace shared
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SHARED_MATH_FADDL_H

libc/src/__support/math/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,34 @@ add_header_library(
818818
libc.src.__support.macros.config
819819
)
820820

821+
add_header_library(
822+
fadd
823+
HDRS
824+
fadd.h
825+
DEPENDS
826+
libc.src.__support.FPUtil.generic.add_sub
827+
libc.src.__support.macros.config
828+
)
829+
830+
add_header_library(
831+
faddf128
832+
HDRS
833+
faddf128.h
834+
DEPENDS
835+
libc.include.llvm-libc-types.float128
836+
libc.src.__support.FPUtil.generic.add_sub
837+
libc.src.__support.macros.config
838+
)
839+
840+
add_header_library(
841+
faddl
842+
HDRS
843+
faddl.h
844+
DEPENDS
845+
libc.src.__support.FPUtil.generic.add_sub
846+
libc.src.__support.macros.config
847+
)
848+
821849
add_header_library(
822850
ffmal
823851
HDRS

libc/src/__support/math/fadd.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation header for fadd --------------------------*- 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___SUPPORT_MATH_FADD_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_FADD_H
11+
12+
#include "src/__support/FPUtil/generic/add_sub.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
namespace math {
17+
18+
LIBC_INLINE float fadd(double x, double y) {
19+
return fputil::generic::add<float>(x, y);
20+
}
21+
22+
} // namespace math
23+
} // namespace LIBC_NAMESPACE_DECL
24+
25+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FADD_H

libc/src/__support/math/faddf128.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- Implementation header for faddf128 ----------------------*- 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___SUPPORT_MATH_FADDF128_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_FADDF128_H
11+
12+
#include "include/llvm-libc-types/float128.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT128
15+
16+
#include "src/__support/FPUtil/generic/add_sub.h"
17+
#include "src/__support/macros/config.h"
18+
19+
namespace LIBC_NAMESPACE_DECL {
20+
namespace math {
21+
22+
LIBC_INLINE float faddf128(float128 x, float128 y) {
23+
return fputil::generic::add<float>(x, y);
24+
}
25+
26+
} // namespace math
27+
} // namespace LIBC_NAMESPACE_DECL
28+
29+
#endif // LIBC_TYPES_HAS_FLOAT128
30+
31+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FADDF128_H

libc/src/__support/math/faddl.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation header for faddl -------------------------*- 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___SUPPORT_MATH_FADDL_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_FADDL_H
11+
12+
#include "src/__support/FPUtil/generic/add_sub.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
namespace math {
17+
18+
LIBC_INLINE float faddl(long double x, long double y) {
19+
return fputil::generic::add<float>(x, y);
20+
}
21+
22+
} // namespace math
23+
} // namespace LIBC_NAMESPACE_DECL
24+
25+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FADDL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ add_entrypoint_object(
548548
HDRS
549549
../fadd.h
550550
DEPENDS
551-
libc.src.__support.FPUtil.generic.add_sub
551+
libc.src.__support.math.fadd
552552
)
553553

554554
add_entrypoint_object(
@@ -558,7 +558,7 @@ add_entrypoint_object(
558558
HDRS
559559
../faddl.h
560560
DEPENDS
561-
libc.src.__support.FPUtil.generic.add_sub
561+
libc.src.__support.math.faddl
562562
)
563563

564564
add_entrypoint_object(
@@ -568,8 +568,7 @@ add_entrypoint_object(
568568
HDRS
569569
../faddf128.h
570570
DEPENDS
571-
libc.src.__support.FPUtil.generic.add_sub
572-
libc.src.__support.macros.properties.types
571+
libc.src.__support.math.faddf128
573572
)
574573

575574
add_entrypoint_object(

libc/src/math/generic/fadd.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#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"
10+
#include "src/__support/math/fadd.h"
1311

1412
namespace LIBC_NAMESPACE_DECL {
1513

1614
LLVM_LIBC_FUNCTION(float, fadd, (double x, double y)) {
17-
return fputil::generic::add<float>(x, y);
15+
return math::fadd(x, y);
1816
}
1917

2018
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)