Skip to content

Commit

Permalink
[libc] Add Int<> type and fix (U)Int<128> compatibility issues.
Browse files Browse the repository at this point in the history
Add Int<> and Int128 types to replace the usage of __int128_t in math
functions.  Clean up to make sure that (U)Int128 and __(u)int128_t are
interchangeable in the code base.

Reviewed By: sivachandra, mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D152459
  • Loading branch information
lntue committed Jun 13, 2023
1 parent 16daaf0 commit 1557256
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 172 deletions.
1 change: 1 addition & 0 deletions libc/src/__support/CMakeLists.txt
Expand Up @@ -134,6 +134,7 @@ add_header_library(
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.FPUtil.dyadic_float
libc.src.__support.builtin_wrappers
libc.src.__support.common
libc.src.errno.errno
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/sqrt.h
Expand Up @@ -137,7 +137,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> sqrt(T x) {
}

// We compute one more iteration in order to round correctly.
bool lsb = y & 1; // Least significant bit
bool lsb = static_cast<bool>(y & 1); // Least significant bit
bool rb = false; // Round bit
r <<= 2;
UIntType tmp = (y << 2) + 1;
Expand Down
Expand Up @@ -101,7 +101,7 @@ LIBC_INLINE long double sqrt(long double x) {
}

// We compute one more iteration in order to round correctly.
bool lsb = y & 1; // Least significant bit
bool lsb = static_cast<bool>(y & 1); // Least significant bit
bool rb = false; // Round bit
r <<= 2;
UIntType tmp = (y << 2) + 1;
Expand Down
4 changes: 4 additions & 0 deletions libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
Expand Up @@ -130,6 +130,10 @@ template <> struct FPBits<long double> {
return bits & MASK;
}

LIBC_INLINE long double get_val() const {
return cpp::bit_cast<long double>(bits);
}

LIBC_INLINE int get_exponent() const {
if (get_unbiased_exponent() == 0)
return int(1) - EXPONENT_BIAS;
Expand Down

0 comments on commit 1557256

Please sign in to comment.