Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[libc] move builtin_wrappers out of fputil
builtin_wrappers contains the wrappers for the clz builtins, which do
not depend on anything in fputil. This patch moves the file out of
FPUtil. The location is updated as appropriate.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D133035
  • Loading branch information
michaelrj-google committed Sep 1, 2022
1 parent 8d95fd7 commit fe41529
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 31 deletions.
8 changes: 7 additions & 1 deletion libc/src/__support/CMakeLists.txt
Expand Up @@ -6,6 +6,12 @@ add_header_library(
blockstore.h
)

add_header_library(
builtin_wrappers
HDRS
builtin_wrappers.h
)

add_header_library(
common
HDRS
Expand Down Expand Up @@ -62,7 +68,7 @@ add_header_library(
libc.include.errno
libc.src.__support.CPP.limits
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.builtin_wrappers
libc.src.__support.builtin_wrappers
libc.src.errno.errno
)

Expand Down
10 changes: 2 additions & 8 deletions libc/src/__support/FPUtil/CMakeLists.txt
@@ -1,9 +1,3 @@
add_header_library(
builtin_wrappers
HDRS
builtin_wrappers.h
)

add_header_library(
fenv_impl
HDRS
Expand Down Expand Up @@ -37,7 +31,7 @@ add_header_library(
DEPENDS
.platform_defs
.float_properties
.builtin_wrappers
libc.src.__support.builtin_wrappers
libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
libc.src.__support.common
Expand Down Expand Up @@ -119,7 +113,7 @@ add_header_library(
.basic_operations
.fenv_impl
.fp_bits
.builtin_wrappers
libc.src.__support.builtin_wrappers
libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
libc.src.__support.uint128
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/FPBits.h
Expand Up @@ -13,7 +13,7 @@

#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/builtin_wrappers.h"
#include "src/__support/common.h"

#include "FloatProperties.h"
Expand Down Expand Up @@ -183,7 +183,7 @@ template <typename T> struct FPBits {
inline static constexpr FPBits<T> make_value(UIntType number, int ep) {
FPBits<T> result;
// offset: +1 for sign, but -1 for implicit first bit
int lz = fputil::unsafe_clz(number) - FloatProp::EXPONENT_WIDTH;
int lz = unsafe_clz(number) - FloatProp::EXPONENT_WIDTH;
number <<= lz;
ep -= lz;

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/Hypot.h
Expand Up @@ -12,10 +12,10 @@
#include "BasicOperations.h"
#include "FEnvImpl.h"
#include "FPBits.h"
#include "builtin_wrappers.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/UInt128.h"
#include "src/__support/builtin_wrappers.h"

namespace __llvm_libc {
namespace fputil {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/FMA.h
Expand Up @@ -13,8 +13,8 @@
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/FloatProperties.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/UInt128.h"
#include "src/__support/builtin_wrappers.h"
#include "src/__support/common.h"

namespace __llvm_libc {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/FMod.h
Expand Up @@ -13,7 +13,7 @@
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/builtin_wrappers.h"
#include "src/__support/common.h"
#include "src/math/generic/math_utils.h"

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/sqrt.h
Expand Up @@ -15,8 +15,8 @@
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PlatformDefs.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/UInt128.h"
#include "src/__support/builtin_wrappers.h"

namespace __llvm_libc {
namespace fputil {
Expand Down
Expand Up @@ -12,8 +12,8 @@
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PlatformDefs.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/UInt128.h"
#include "src/__support/builtin_wrappers.h"

namespace __llvm_libc {
namespace fputil {
Expand Down
Expand Up @@ -7,11 +7,10 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_BUILTIN_WRAPPERS_H
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_BUILTIN_WRAPPERS_H
#ifndef LLVM_LIBC_SRC_SUPPORT_BUILTIN_WRAPPERS_H
#define LLVM_LIBC_SRC_SUPPORT_BUILTIN_WRAPPERS_H

namespace __llvm_libc {
namespace fputil {

// The following overloads are matched based on what is accepted by
// __builtin_clz/ctz* rather than using the exactly-sized aliases from stdint.h.
Expand Down Expand Up @@ -65,7 +64,6 @@ template <typename T> static inline int unsafe_clz(T val) {
return __internal::clz(val);
}

} // namespace fputil
} // namespace __llvm_libc

#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_BUILTIN_WRAPPERS_H
#endif // LLVM_LIBC_SRC_SUPPORT_BUILTIN_WRAPPERS_H
6 changes: 3 additions & 3 deletions libc/src/__support/str_to_float.h
Expand Up @@ -11,8 +11,8 @@

#include "src/__support/CPP/limits.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/UInt128.h"
#include "src/__support/builtin_wrappers.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/detailed_powers_of_ten.h"
#include "src/__support/high_precision_decimal.h"
Expand Down Expand Up @@ -52,11 +52,11 @@ template <class T> uint32_t inline leading_zeroes(T inputNumber) {
}

template <> uint32_t inline leading_zeroes<uint32_t>(uint32_t inputNumber) {
return fputil::safe_clz(inputNumber);
return safe_clz(inputNumber);
}

template <> uint32_t inline leading_zeroes<uint64_t>(uint64_t inputNumber) {
return fputil::safe_clz(inputNumber);
return safe_clz(inputNumber);
}

static inline uint64_t low64(const UInt128 &num) {
Expand Down
12 changes: 6 additions & 6 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Expand Up @@ -168,8 +168,8 @@ cc_library(
)

cc_library(
name = "__support_fputil_builtin_wrappers",
hdrs = ["src/__support/FPUtil/builtin_wrappers.h"],
name = "__support_builtin_wrappers",
hdrs = ["src/__support/builtin_wrappers.h"],
deps = [
":libc_root",
],
Expand Down Expand Up @@ -224,10 +224,10 @@ cc_library(
hdrs = ["src/__support/FPUtil/FPBits.h"],
textual_hdrs = ["src/__support/FPUtil/x86_64/LongDoubleBits.h"],
deps = [
":__support_builtin_wrappers",
":__support_common",
":__support_cpp_bit",
":__support_cpp_type_traits",
":__support_fputil_builtin_wrappers",
":__support_fputil_float_properties",
":__support_fputil_platform_defs",
":libc_root",
Expand All @@ -238,10 +238,10 @@ cc_library(
name = "__support_fputil_hypot",
hdrs = ["src/__support/FPUtil/Hypot.h"],
deps = [
":__support_builtin_wrappers",
":__support_cpp_bit",
":__support_cpp_type_traits",
":__support_fputil_basic_operations",
":__support_fputil_builtin_wrappers",
":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
":__support_uint128",
Expand Down Expand Up @@ -314,10 +314,10 @@ cc_library(
name = "__support_fputil_sqrt",
hdrs = sqrt_hdrs,
deps = [
":__support_builtin_wrappers",
":__support_common",
":__support_cpp_bit",
":__support_cpp_type_traits",
":__support_fputil_builtin_wrappers",
":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
":__support_fputil_platform_defs",
Expand All @@ -343,10 +343,10 @@ cc_library(
# doesn't support FMA, so they can't be compiled on their own.
textual_hdrs = fma_platform_hdrs,
deps = [
":__support_builtin_wrappers",
":__support_common",
":__support_cpp_bit",
":__support_cpp_type_traits",
":__support_fputil_builtin_wrappers",
":__support_fputil_fenv_impl",
":__support_fputil_float_properties",
":__support_fputil_fp_bits",
Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
Expand Up @@ -92,7 +92,7 @@ def libc_math_function(
":__support_fputil_nearest_integer_operations",
":__support_fputil_normal_float",
":__support_fputil_platform_defs",
":__support_fputil_builtin_wrappers",
":__support_builtin_wrappers",
":__support_fputil_except_value_utils",
]
libc_function(
Expand Down

0 comments on commit fe41529

Please sign in to comment.