Skip to content

Commit 933cb75

Browse files
committed
Move EXP2_MID_BITS to a new header shared between exp2f16 and exp10f16
1 parent 2295725 commit 933cb75

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

libc/src/math/generic/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ add_entrypoint_object(
14021402
HDRS
14031403
../exp2f16.h
14041404
DEPENDS
1405+
.expxf16
14051406
libc.hdr.errno_macros
14061407
libc.hdr.fenv_macros
14071408
libc.src.__support.CPP.array
@@ -1504,6 +1505,7 @@ add_entrypoint_object(
15041505
HDRS
15051506
../exp10f16.h
15061507
DEPENDS
1508+
.expxf16
15071509
libc.hdr.errno_macros
15081510
libc.hdr.fenv_macros
15091511
libc.src.__support.CPP.array
@@ -4783,3 +4785,11 @@ add_entrypoint_object(
47834785
COMPILE_OPTIONS
47844786
-O3
47854787
)
4788+
4789+
add_header_library(
4790+
expxf16
4791+
HDRS
4792+
expxf16.h
4793+
DEPENDS
4794+
libc.src.__support.CPP.array
4795+
)

libc/src/math/generic/exp10f16.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/exp10f16.h"
10+
#include "expxf16.h"
1011
#include "hdr/errno_macros.h"
1112
#include "hdr/fenv_macros.h"
1213
#include "src/__support/CPP/array.h"
@@ -62,14 +63,6 @@ static constexpr float LOG2F_10 = 0x1.a934fp+1f;
6263
// > round(log10(2), SG, RN);
6364
static constexpr float LOG10F_2 = 0x1.344136p-2f;
6465

65-
// Generated by Sollya with the following commands:
66-
// > display = hexadecimal;
67-
// > for i from 0 to 7 do printsingle(round(2^(i * 2^-3), SG, RN));
68-
static constexpr cpp::array<uint32_t, 8> EXP2_MID_BITS = {
69-
0x3f80'0000U, 0x3f8b'95c2U, 0x3f98'37f0U, 0x3fa5'fed7U,
70-
0x3fb5'04f3U, 0x3fc5'672aU, 0x3fd7'44fdU, 0x3fea'c0c7U,
71-
};
72-
7366
LLVM_LIBC_FUNCTION(float16, exp10f16, (float16 x)) {
7467
using FPBits = fputil::FPBits<float16>;
7568
FPBits x_bits(x);

libc/src/math/generic/exp2f16.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/exp2f16.h"
10+
#include "expxf16.h"
1011
#include "hdr/errno_macros.h"
1112
#include "hdr/fenv_macros.h"
1213
#include "src/__support/CPP/array.h"
@@ -33,14 +34,6 @@ static constexpr fputil::ExceptValues<float16, 3> EXP2F16_EXCEPTS = {{
3334
{0xaf57U, 0x3b63U, 1U, 0U, 0U},
3435
}};
3536

36-
// Generated by Sollya with the following commands:
37-
// > display = hexadecimal;
38-
// > for i from 0 to 7 do printsingle(round(2^(i * 2^-3), SG, RN));
39-
static constexpr cpp::array<uint32_t, 8> EXP2_MID_BITS = {
40-
0x3f80'0000U, 0x3f8b'95c2U, 0x3f98'37f0U, 0x3fa5'fed7U,
41-
0x3fb5'04f3U, 0x3fc5'672aU, 0x3fd7'44fdU, 0x3fea'c0c7U,
42-
};
43-
4437
LLVM_LIBC_FUNCTION(float16, exp2f16, (float16 x)) {
4538
using FPBits = fputil::FPBits<float16>;
4639
FPBits x_bits(x);

libc/src/math/generic/expxf16.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Common utilities for half-precision exponential functions ---------===//
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_MATH_GENERIC_EXPXF16_H
10+
#define LLVM_LIBC_SRC_MATH_GENERIC_EXPXF16_H
11+
12+
#include "src/__support/CPP/array.h"
13+
#include "src/__support/macros/config.h"
14+
#include <stdint.h>
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
// Generated by Sollya with the following commands:
19+
// > display = hexadecimal;
20+
// > for i from 0 to 7 do printsingle(round(2^(i * 2^-3), SG, RN));
21+
constexpr cpp::array<uint32_t, 8> EXP2_MID_BITS = {
22+
0x3f80'0000U, 0x3f8b'95c2U, 0x3f98'37f0U, 0x3fa5'fed7U,
23+
0x3fb5'04f3U, 0x3fc5'672aU, 0x3fd7'44fdU, 0x3fea'c0c7U,
24+
};
25+
26+
} // namespace LIBC_NAMESPACE_DECL
27+
28+
#endif // LLVM_LIBC_SRC_MATH_GENERIC_EXPXF16_H

0 commit comments

Comments
 (0)