Skip to content

[libc][NFC] fix uint128 init in float properties #75084

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

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libc/src/__support/FPUtil/FloatProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ template <typename T, size_t count> static constexpr T mask_trailing_ones() {
static_assert(cpp::is_unsigned_v<T>);
constexpr unsigned t_bits = CHAR_BIT * sizeof(T);
static_assert(count <= t_bits && "Invalid bit index");
return count == 0 ? 0 : (T(-1) >> (t_bits - count));
// It's important not to initialize T with -1, since T may be BigInt which
// will take -1 as a uint64_t and only initialize the low 64 bits.
return count == 0 ? 0 : ((~T(0)) >> (t_bits - count));
}

// Derives more properties from 'FPBaseProperties' above.
Expand Down Expand Up @@ -131,7 +133,7 @@ struct FPCommonProperties : private FPBaseProperties<fp_type> {
LIBC_INLINE_VAR static constexpr UIntType FP_MASK =
mask_trailing_ones<UIntType, TOTAL_BITS>();
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK_) == 0, "masks disjoint");
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK_) == FP_MASK, "masks covers");
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK_) == FP_MASK, "masks cover");

LIBC_INLINE static constexpr UIntType bit_at(int position) {
return UIntType(1) << position;
Expand Down