[libc-commits] [libc] [llvm] [libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (PR #78192)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Jan 16 10:34:59 PST 2024
================
@@ -132,11 +166,94 @@ struct FPRepBase : public internal::FPLayout<fp_type> {
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK) == FP_MASK, "masks cover");
-private:
+protected:
LIBC_INLINE static constexpr StorageType bit_at(int position) {
return StorageType(1) << position;
}
+ // An opaque type to store a floating point exponent.
+ // We define special values but it is valid to create arbitrary values as long
+ // as they are in the range [MIN, MAX].
+ enum class Exponent : int32_t {
+ MIN = 1 - EXP_BIAS,
+ ZERO = 0,
+ MAX = EXP_BIAS,
+ };
+
+ // An opaque type to store a floating point biased exponent.
+ // We define special values but it is valid to create arbitrary values as long
+ // as they are in the range [BITS_ALL_ZEROES, BITS_ALL_ONES].
+ // Values greater than BITS_ALL_ONES are truncated.
+ enum class BiasedExponent : uint32_t {
+ // The exponent value for denormal numbers.
+ BITS_ALL_ZEROES = 0,
+ // The exponent value for infinity.
+ BITS_ALL_ONES = 2 * EXP_BIAS + 1,
+ };
+
+ LIBC_INLINE static constexpr BiasedExponent biased(Exponent value) {
+ return static_cast<BiasedExponent>(static_cast<int32_t>(value) + EXP_BIAS);
+ }
+
+ // An opaque type to store a floating point significand.
+ // We define special values but it is valid to create arbitrary values as long
+ // as they are in the range [BITS_ALL_ZEROES, BITS_ALL_ONES].
+ // Note that the semantics of the Significand are implementation dependent.
+ // Values greater than BITS_ALL_ONES are truncated.
+ enum class Significand : StorageType {
+ ZERO = 0,
+ LSB = 1,
+ MSB = bit_at(SIG_LEN - 1),
+ // Aliases
+ BITS_ALL_ZEROES = ZERO,
+ BITS_ALL_ONES = SIG_MASK,
+ };
+
+ template <typename T>
+ LIBC_INLINE static constexpr auto storage_cast(T value) {
+ return static_cast<StorageType>(value);
+ }
+
+ LIBC_INLINE friend constexpr Significand operator|(const Significand a,
+ const Significand b) {
+ return Significand{storage_cast(storage_cast(a) | storage_cast(b))};
----------------
nickdesaulniers wrote:
32b arm build bot failure here:
```
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:219:37: error: no matching function for call to 'storage_cast'
return Significand{storage_cast(storage_cast(a) | storage_cast(b))};
^~~~~~~~~~~~
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:480:54: note: in instantiation of member function '__llvm_libc_18_0_0_git::fputil::operator|' requested here
Significand::MSB | (Significand::MSB >> 1));
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:213:37: note: candidate template ignored: substitution failure [with T = __llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::Significand]
LIBC_INLINE static constexpr auto storage_cast(T value) {
^
```
https://github.com/llvm/llvm-project/pull/78192
More information about the libc-commits
mailing list