Skip to content

Commit b92ab89

Browse files
[libc][math] Refactor f16add Math Functions to Header Only (llvm#181777)
Resolves llvm#181630 Part of llvm#147386
1 parent b576429 commit b92ab89

18 files changed

Lines changed: 376 additions & 34 deletions

File tree

libc/shared/math.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
#include "math/expm1.h"
7171
#include "math/expm1f.h"
7272
#include "math/expm1f16.h"
73+
#include "math/f16add.h"
74+
#include "math/f16addf.h"
75+
#include "math/f16addf128.h"
76+
#include "math/f16addl.h"
7377
#include "math/f16fma.h"
7478
#include "math/f16fmaf.h"
7579
#include "math/f16fmaf128.h"

libc/shared/math/f16add.h

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

libc/shared/math/f16addf.h

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

libc/shared/math/f16addf128.h

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

libc/shared/math/f16addl.h

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

libc/src/__support/math/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,47 @@ add_header_library(
701701
libc.src.__support.math.exp10_float16_constants
702702
)
703703

704+
add_header_library(
705+
f16add
706+
HDRS
707+
f16add.h
708+
DEPENDS
709+
libc.include.llvm-libc-macros.float16_macros
710+
libc.src.__support.FPUtil.generic.add_sub
711+
libc.src.__support.macros.config
712+
)
713+
714+
add_header_library(
715+
f16addf
716+
HDRS
717+
f16addf.h
718+
DEPENDS
719+
libc.include.llvm-libc-macros.float16_macros
720+
libc.src.__support.FPUtil.generic.add_sub
721+
libc.src.__support.macros.config
722+
)
723+
724+
add_header_library(
725+
f16addf128
726+
HDRS
727+
f16addf128.h
728+
DEPENDS
729+
libc.include.llvm-libc-macros.float16_macros
730+
libc.include.llvm-libc-types.float128
731+
libc.src.__support.FPUtil.generic.add_sub
732+
libc.src.__support.macros.config
733+
)
734+
735+
add_header_library(
736+
f16addl
737+
HDRS
738+
f16addl.h
739+
DEPENDS
740+
libc.include.llvm-libc-macros.float16_macros
741+
libc.src.__support.FPUtil.generic.add_sub
742+
libc.src.__support.macros.config
743+
)
744+
704745
add_header_library(
705746
ffmal
706747
HDRS

libc/src/__support/math/f16add.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- Implementation header for f16add ------------------------*- 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_F16ADD_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_F16ADD_H
11+
12+
#include "include/llvm-libc-macros/float16-macros.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT16
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 float16 f16add(double x, double y) {
23+
return fputil::generic::add<float16>(x, y);
24+
}
25+
26+
} // namespace math
27+
} // namespace LIBC_NAMESPACE_DECL
28+
29+
#endif // LIBC_TYPES_HAS_FLOAT16
30+
31+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16ADD_H

libc/src/__support/math/f16addf.h

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

libc/src/__support/math/f16addl.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- Implementation header for f16addl -----------------------*- 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_F16ADDL_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDL_H
11+
12+
#include "include/llvm-libc-macros/float16-macros.h"
13+
14+
#ifdef LIBC_TYPES_HAS_FLOAT16
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 float16 f16addl(long double x, long double y) {
23+
return fputil::generic::add<float16>(x, y);
24+
}
25+
26+
} // namespace math
27+
} // namespace LIBC_NAMESPACE_DECL
28+
29+
#endif // LIBC_TYPES_HAS_FLOAT16
30+
31+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDL_H

0 commit comments

Comments
 (0)