Skip to content

[libc][math] Refactor exp10f16 implementation to header-only in src/__support/math folder. #148408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions libc/shared/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

#include "libc_common.h"

#include "math/exp.h"
#include "math/exp10.h"
#include "math/exp10f.h"
#include "math/exp10f16.h"
#include "math/expf.h"
#include "math/expf16.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
#include "math/ldexpf.h"
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"

#endif // LLVM_LIBC_SHARED_MATH_H
23 changes: 23 additions & 0 deletions libc/shared/math/exp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared exp function -------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_EXP_H
#define LLVM_LIBC_SHARED_MATH_EXP_H

#include "shared/libc_common.h"
#include "src/__support/math/exp.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::exp;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_EXP_H
23 changes: 23 additions & 0 deletions libc/shared/math/exp10.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared exp10 function -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_EXP10_H
#define LLVM_LIBC_SHARED_MATH_EXP10_H

#include "shared/libc_common.h"
#include "src/__support/math/exp10.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::exp10;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_EXP10_H
24 changes: 24 additions & 0 deletions libc/shared/math/exp10f.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===-- Shared exp10f function -----------------------------------*- C++
//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_EXP10F_H
#define LLVM_LIBC_SHARED_MATH_EXP10F_H

#include "shared/libc_common.h"
#include "src/__support/math/exp10f.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::exp10f;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_EXP10F_H
29 changes: 29 additions & 0 deletions libc/shared/math/exp10f16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Shared exp10f16 function --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_EXP10F_H
#define LLVM_LIBC_SHARED_MATH_EXP10F_H

#include "include/llvm-libc-macros/float16-macros.h"

#ifdef LIBC_TYPES_HAS_FLOAT16

#include "shared/libc_common.h"
#include "src/__support/math/exp10f16.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::exp10f16;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT16

#endif // LLVM_LIBC_SHARED_MATH_EXP10F_H
23 changes: 23 additions & 0 deletions libc/shared/math/ldexpf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Shared ldexpf function ----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_LDEXPF_H
#define LLVM_LIBC_SHARED_MATH_LDEXPF_H

#include "shared/libc_common.h"
#include "src/__support/math/ldexpf.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::ldexpf;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_LDEXPF_H
29 changes: 29 additions & 0 deletions libc/shared/math/ldexpf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Shared ldexpf128 function -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_LDEXPF128_H
#define LLVM_LIBC_SHARED_MATH_LDEXPF128_H

#include "include/llvm-libc-types/float128.h"

#ifdef LIBC_TYPES_HAS_FLOAT128

#include "shared/libc_common.h"
#include "src/__support/math/ldexpf128.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::ldexpf128;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT128

#endif // LLVM_LIBC_SHARED_MATH_LDEXPF128_H
31 changes: 31 additions & 0 deletions libc/shared/math/ldexpf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===-- Shared ldexpf16 function --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_ldexpf16_H
#define LLVM_LIBC_SHARED_MATH_ldexpf16_H

#include "include/llvm-libc-macros/float16-macros.h"

#ifdef LIBC_TYPES_HAS_FLOAT16

#include "shared/libc_common.h"
#include "src/__support/math/ldexpf16.h"

namespace LIBC_NAMESPACE_DECL {

namespace shared {

using math::ldexpf16;

} // namespace shared

} // namespace LIBC_NAMESPACE_DECL

#endif // LIBC_TYPES_HAS_FLOAT16

#endif // LLVM_LIBC_SHARED_MATH_ldexpf16_H
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/double_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ LIBC_INLINE DoubleDouble quick_mult(double a, const DoubleDouble &b) {
}

template <size_t SPLIT_B = 27>
LIBC_INLINE DoubleDouble quick_mult(const DoubleDouble &a,
const DoubleDouble &b) {
LIBC_INLINE constexpr DoubleDouble quick_mult(const DoubleDouble &a,
const DoubleDouble &b) {
DoubleDouble r = exact_mult<double, SPLIT_B>(a.hi, b.hi);
double t1 = multiply_add(a.hi, b.lo, r.lo);
double t2 = multiply_add(a.lo, b.hi, t1);
Expand Down
150 changes: 150 additions & 0 deletions libc/src/__support/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,153 @@ add_header_library(
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
)

add_header_library(
ldexpf128
HDRS
ldexpf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.manipulation_functions
libc.include.llvm-libc-types.float128
)

add_header_library(
ldexpf16
HDRS
ldexpf16.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.manipulation_functions
libc.include.llvm-libc-macros.float16_macros
)

add_header_library(
ldexpf
HDRS
ldexpf.h
DEPENDS
libc.src.__support.FPUtil.manipulation_functions
)

add_header_library(
exp_constants
HDRS
exp_constants.h
DEPENDS
libc.src.__support.FPUtil.triple_double
)

add_header_library(
exp_utils
HDRS
exp_utils.h
DEPENDS
libc.src.__support.CPP.optional
libc.src.__support.CPP.bit
libc.src.__support.FPUtil.fp_bits
)

add_header_library(
exp
HDRS
exp.h
DEPENDS
.exp_constants
.exp_utils
libc.src.__support.CPP.bit
libc.src.__support.CPP.optional
libc.src.__support.FPUtil.dyadic_float
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.nearest_integer
libc.src.__support.FPUtil.polyeval
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.FPUtil.triple_double
libc.src.__support.integer_literals
libc.src.__support.macros.optimization
)

add_header_library(
exp10
HDRS
exp10.h
DEPENDS
.exp_constants
.exp_utils
libc.src.__support.CPP.bit
libc.src.__support.CPP.optional
libc.src.__support.FPUtil.dyadic_float
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.nearest_integer
libc.src.__support.FPUtil.polyeval
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.FPUtil.triple_double
libc.src.__support.integer_literals
libc.src.__support.macros.optimization
)

add_header_library(
exp10f_utils
HDRS
exp10f_utils.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.nearest_integer
libc.src.__support.FPUtil.polyeval
libc.src.__support.common
libc.src.__support.math.exp_utils
)

add_header_library(
exp10f
HDRS
exp10f.h
DEPENDS
.exp10f_utils
libc.src.__support.macros.config
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.macros.optimization
)

add_header_library(
exp10_float16_constants
HDRS
exp10_float16_constants.h
DEPENDS
libc.src.__support.CPP.array
)

add_header_library(
exp10f16_utils
HDRS
exp10f16_utils.h
DEPENDS
.expf16_utils
.exp10_float16_constants
libc.src.__support.FPUtil.fp_bits
)

add_header_library(
exp10f16
HDRS
exp10f16.h
DEPENDS
.exp10f16_utils
libc.src.__support.FPUtil.fp_bits
src.__support.FPUtil.FEnvImpl
src.__support.FPUtil.FPBits
src.__support.FPUtil.cast
src.__support.FPUtil.rounding_mode
src.__support.FPUtil.except_value_utils
src.__support.macros.optimization
src.__support.macros.properties.cpu_features
)
Loading
Loading