Skip to content

Commit 6ee0221

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

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
@@ -12,5 +12,6 @@
1212
#include "libc_common.h"
1313

1414
#include "math/expf.h"
15+
#include "math/frexpf128.h"
1516

1617
#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
@@ -22,3 +22,12 @@ add_header_library(
2222
libc.src.__support.macros.config
2323
libc.src.__support.macros.optimization
2424
)
25+
26+
add_header_library(
27+
frexpf128
28+
HDRS
29+
frexpf128.h
30+
DEPENDS
31+
libc.src.__support.macros.properties.types
32+
libc.src.__support.FPUtil.manipulation_functions
33+
)

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
@@ -1786,8 +1786,7 @@ add_entrypoint_object(
17861786
HDRS
17871787
../frexpf128.h
17881788
DEPENDS
1789-
libc.src.__support.macros.properties.types
1790-
libc.src.__support.FPUtil.manipulation_functions
1789+
libc.src.__support.math.frexpf128
17911790
)
17921791

17931792
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
@@ -2096,6 +2096,15 @@ libc_support_library(
20962096
],
20972097
)
20982098

2099+
libc_support_library(
2100+
name = "__support_math_frexpf128",
2101+
hdrs = ["src/__support/math/frexpf128.h"],
2102+
deps = [
2103+
":__support_macros_properties_types",
2104+
":__support_fputil_manipulation_functions",
2105+
],
2106+
)
2107+
20992108
############################### complex targets ################################
21002109

21012110
libc_function(
@@ -2694,6 +2703,7 @@ libc_math_function(
26942703
name = "expf",
26952704
additional_deps = [
26962705
":__support_math_expf",
2706+
":__support_math_frexpf128",
26972707
":errno",
26982708
],
26992709
)

0 commit comments

Comments
 (0)