[libc] [llvm] [libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (PR #78192)

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 00:49:41 PST 2024


================
@@ -132,6 +132,70 @@ 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");
 
+protected:
+  enum class Exp : int32_t {
+    ZERO = 0,
+    // The exponent value for denormal numbers.
+    SUBNORMAL = -EXP_BIAS,
+    // The minimum exponent value for normal numbers.
+    MIN = SUBNORMAL + 1,
+    // The maximum exponent value for normal numbers.
+    MAX = EXP_BIAS,
+    // Special value all ones.
+    INF = MAX + 1,
+    // Aliases
+    BITS_ALL_ZEROES = SUBNORMAL,
+    BITS_ALL_ONES = INF,
+  };
+
+  enum class Sig : StorageType {
+    ZERO = 0,
+    ONE = 1,
+    MSB = StorageType(1) << (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 Sig operator|(const Sig a, const Sig b) {
+    return Sig{storage_cast(storage_cast(a) | storage_cast(b))};
+  }
+  LIBC_INLINE friend constexpr Sig operator^(const Sig a, const Sig b) {
+    return Sig{storage_cast(storage_cast(a) ^ storage_cast(b))};
+  }
+  LIBC_INLINE friend constexpr Sig operator>>(const Sig a, int shift) {
+    return Sig{storage_cast(storage_cast(a) >> shift)};
+  }
+
+  LIBC_INLINE static constexpr StorageType encode(Exp exp) {
+    return storage_cast(static_cast<int32_t>(exp) + EXP_BIAS) << SIG_LEN;
+  }
+
+  LIBC_INLINE static constexpr StorageType encode(Sig value) {
+    return storage_cast(value) & SIG_MASK;
----------------
legrosbuffle wrote:

ditto

https://github.com/llvm/llvm-project/pull/78192


More information about the llvm-commits mailing list