https://github.com/gchatelet updated
https://github.com/llvm/llvm-project/pull/78588
>From 49ba96c8aa51fb56a5bf96a1e97fef48bcc42f09 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet
Date: Thu, 18 Jan 2024 14:42:54 +
Subject: [PATCH 1/3] [libc] `FPRep` builders return `FPRep` instead of raw
`StorageType`
---
libc/src/__support/FPUtil/FPBits.h| 68
.../test/src/__support/FPUtil/fpbits_test.cpp | 163 +-
2 files changed, 120 insertions(+), 111 deletions(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h
b/libc/src/__support/FPUtil/FPBits.h
index 3ee6289b749648..5df49350e3744e 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -332,7 +332,10 @@ struct FPRepBase : public internal::FPLayout {
mask_trailing_ones();
// The floating point number representation as an unsigned integer.
- StorageType bits = 0;
+ StorageType bits;
+
+ LIBC_INLINE constexpr FPRepBase() : bits(0) {}
+ LIBC_INLINE constexpr FPRepBase(StorageType value) : bits(value) {}
public:
LIBC_INLINE constexpr Sign sign() const {
@@ -418,6 +421,7 @@ template struct FPRep : public
FPRepBase {
using UP::exp_bits;
using UP::exp_sig_bits;
using UP::sig_bits;
+ using UP::UP;
public:
LIBC_INLINE constexpr bool is_nan() const {
@@ -450,37 +454,35 @@ template struct FPRep : public
FPRepBase {
return is_finite() && !is_subnormal();
}
- LIBC_INLINE static constexpr StorageType zero(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep zero(Sign sign = Sign::POS) {
return encode(sign, BiasedExponent::BITS_ALL_ZEROES(),
Significand::ZERO());
}
- LIBC_INLINE static constexpr StorageType one(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep one(Sign sign = Sign::POS) {
return encode(sign, Exponent::ZERO(), Significand::ZERO());
}
- LIBC_INLINE static constexpr StorageType
- min_subnormal(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep min_subnormal(Sign sign = Sign::POS) {
return encode(sign, BiasedExponent::BITS_ALL_ZEROES(), Significand::LSB());
}
- LIBC_INLINE static constexpr StorageType
- max_subnormal(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep max_subnormal(Sign sign = Sign::POS) {
return encode(sign, BiasedExponent::BITS_ALL_ZEROES(),
Significand::BITS_ALL_ONES());
}
- LIBC_INLINE static constexpr StorageType min_normal(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep min_normal(Sign sign = Sign::POS) {
return encode(sign, Exponent::MIN(), Significand::ZERO());
}
- LIBC_INLINE static constexpr StorageType max_normal(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep max_normal(Sign sign = Sign::POS) {
return encode(sign, Exponent::MAX(), Significand::BITS_ALL_ONES());
}
- LIBC_INLINE static constexpr StorageType inf(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep inf(Sign sign = Sign::POS) {
return encode(sign, BiasedExponent::BITS_ALL_ONES(), Significand::ZERO());
}
- LIBC_INLINE static constexpr StorageType build_nan(Sign sign = Sign::POS,
- StorageType v = 0) {
+ LIBC_INLINE static constexpr FPRep build_nan(Sign sign = Sign::POS,
+ StorageType v = 0) {
return encode(sign, BiasedExponent::BITS_ALL_ONES(),
(v ? Significand(v) : (Significand::MSB() >> 1)));
}
- LIBC_INLINE static constexpr StorageType
- build_quiet_nan(Sign sign = Sign::POS, StorageType v = 0) {
+ LIBC_INLINE static constexpr FPRep build_quiet_nan(Sign sign = Sign::POS,
+ StorageType v = 0) {
return encode(sign, BiasedExponent::BITS_ALL_ONES(),
Significand::MSB() | Significand(v));
}
@@ -507,6 +509,7 @@ struct FPRep : public
FPRepBase {
using typename UP::BiasedExponent;
using typename UP::Significand;
using UP::encode;
+ using UP::UP;
public:
// The x86 80 bit float represents the leading digit of the mantissa
@@ -570,38 +573,36 @@ struct FPRep : public
FPRepBase {
return get_implicit_bit();
}
- LIBC_INLINE static constexpr StorageType zero(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep zero(Sign sign = Sign::POS) {
return encode(sign, BiasedExponent::BITS_ALL_ZEROES(),
Significand::ZERO());
}
- LIBC_INLINE static constexpr StorageType one(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep one(Sign sign = Sign::POS) {
return encode(sign, Exponent::ZERO(), Significand::MSB());
}
- LIBC_INLINE static constexpr StorageType
- min_subnormal(Sign sign = Sign::POS) {
+ LIBC_INLINE static constexpr FPRep min_subnormal(Sign sign = Sign::POS) {
return encode(sign, BiasedExponent::BITS_ALL_ZEROES(), Significand::LSB());
}
- LIBC_INLINE static constexpr StorageType
- max_subnormal(Sign