Skip to content

Commit 6e911b8

Browse files
committed
[libc][math] Refactor frexpf128 implementation to header-only in src/__support/math folder.
1 parent c919221 commit 6e911b8

File tree

7 files changed

+90
-6
lines changed

7 files changed

+90
-6
lines changed

libc/shared/math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313

1414
#include "math/expf.h"
1515
#include "math/expf16.h"
16+
#include "math/frexpf128.h"
1617

1718
#endif // LLVM_LIBC_SHARED_MATH_H

libc/shared/math/frexpf128.h

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

libc/src/__support/math/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ add_header_library(
5555
libc.src.__support.macros.optimization
5656
libc.include.llvm-libc-macros.float16_macros
5757
)
58+
59+
add_header_library(
60+
frexpf128
61+
HDRS
62+
frexpf128.h
63+
DEPENDS
64+
libc.src.__support.macros.properties.types
65+
libc.src.__support.FPUtil.manipulation_functions
66+
)

libc/src/__support/math/frexpf128.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- Implementation header for expf --------------------------*- 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_FREXPF128_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H
11+
12+
#include "include/llvm-libc-types/float128.h"
13+
14+
#ifndef LIBC_TYPES_HAS_FLOAT128
15+
#error unsupported
16+
#else
17+
18+
#include "src/__support/FPUtil/ManipulationFunctions.h"
19+
#include "src/__support/common.h"
20+
#include "src/__support/macros/config.h"
21+
22+
namespace LIBC_NAMESPACE_DECL {
23+
24+
namespace math {
25+
26+
static constexpr float128 frexpf128(float128 x, int *exp) {
27+
return fputil::frexp(x, *exp);
28+
}
29+
30+
} // namespace math
31+
32+
} // namespace LIBC_NAMESPACE_DECL
33+
34+
#endif // LIBC_TYPES_HAS_FLOAT128
35+
36+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FREXPF128_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,7 @@ add_entrypoint_object(
17751775
HDRS
17761776
../frexpf128.h
17771777
DEPENDS
1778-
libc.src.__support.macros.properties.types
1779-
libc.src.__support.FPUtil.manipulation_functions
1778+
libc.src.__support.math.frexpf128
17801779
)
17811780

17821781
add_entrypoint_object(

libc/src/math/generic/frexpf128.cpp

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

99
#include "src/math/frexpf128.h"
10-
#include "src/__support/FPUtil/ManipulationFunctions.h"
11-
#include "src/__support/common.h"
12-
#include "src/__support/macros/config.h"
10+
11+
#include "src/__support/math/frexpf128.h"
1312

1413
namespace LIBC_NAMESPACE_DECL {
1514

1615
LLVM_LIBC_FUNCTION(float128, frexpf128, (float128 x, int *exp)) {
17-
return fputil::frexp(x, *exp);
16+
return math::frexpf128(x, exp);
1817
}
1918

2019
} // namespace LIBC_NAMESPACE_DECL

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,15 @@ libc_support_library(
21492149
],
21502150
)
21512151

2152+
libc_support_library(
2153+
name = "__support_math_frexpf128",
2154+
hdrs = ["src/__support/math/frexpf128.h"],
2155+
deps = [
2156+
":__support_macros_properties_types",
2157+
":__support_fputil_manipulation_functions",
2158+
],
2159+
)
2160+
21522161
############################### complex targets ################################
21532162

21542163
libc_function(
@@ -2747,6 +2756,7 @@ libc_math_function(
27472756
name = "expf",
27482757
additional_deps = [
27492758
":__support_math_expf",
2759+
":__support_math_frexpf128",
27502760
":errno",
27512761
],
27522762
)

0 commit comments

Comments
 (0)