[libc-commits] [llvm] [libc] [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:35:00 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,
----------------
nickdesaulniers wrote:
32b arm build bot failure:
```
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:209:21: error: no viable conversion from 'const __llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::StorageType' (aka 'const BigInt<128U, false>') to 'int'
BITS_ALL_ONES = SIG_MASK,
^~~~~~~~
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:106:56: note: explicit conversion function is not a candidate
template <typename T> LIBC_INLINE constexpr explicit operator T() const {
^
```
https://github.com/llvm/llvm-project/pull/78192
More information about the libc-commits
mailing list