[libc-commits] [libc] 1e47a15 - [libc][NFC] Remove last use of BitsType in FloatProperties (#75174)

via libc-commits libc-commits at lists.llvm.org
Tue Dec 12 05:00:29 PST 2023


Author: Guillaume Chatelet
Date: 2023-12-12T14:00:25+01:00
New Revision: 1e47a157f84e38b8cb0caeaba84e881e173d242c

URL: https://github.com/llvm/llvm-project/commit/1e47a157f84e38b8cb0caeaba84e881e173d242c
DIFF: https://github.com/llvm/llvm-project/commit/1e47a157f84e38b8cb0caeaba84e881e173d242c.diff

LOG: [libc][NFC] Remove last use of BitsType in FloatProperties (#75174)

Also start to expose some of the internals to avoid duplication.

Added: 
    

Modified: 
    libc/src/__support/FPUtil/FPBits.h
    libc/src/__support/FPUtil/FloatProperties.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index bd075fe3d72872..65c53921181a73 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -44,8 +44,7 @@ template <typename T> struct FPBits {
   // integer value as a floating point value is used in tests. So, a convenient
   // type is provided for such reinterpretations.
   using FloatProp = FloatProperties<T>;
-  // TODO: Change UintType name to BitsType for consistency.
-  using UIntType = typename FloatProp::BitsType;
+  using UIntType = typename FloatProp::UIntType;
 
   UIntType bits;
 

diff  --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h
index 04da5c031f88a5..7f396a649e4f58 100644
--- a/libc/src/__support/FPUtil/FloatProperties.h
+++ b/libc/src/__support/FPUtil/FloatProperties.h
@@ -90,8 +90,11 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
   using UP::EXP_BITS;
   using UP::SIG_BITS;
   using UP::TOTAL_BITS;
+
+public:
   using UIntType = typename UP::UIntType;
 
+private:
   LIBC_INLINE_VAR static constexpr int STORAGE_BITS =
       sizeof(UIntType) * CHAR_BIT;
   static_assert(STORAGE_BITS >= TOTAL_BITS);
@@ -116,14 +119,16 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
       mask_trailing_ones<UIntType, SIG_BITS>() << SIG_MASK_SHIFT;
   LIBC_INLINE_VAR static constexpr UIntType EXP_MASK =
       mask_trailing_ones<UIntType, EXP_BITS>() << EXP_MASK_SHIFT;
-  // Trailing underscore on SIGN_MASK_ is temporary - it will be removed
-  // once we can replace the public part below with the private one.
-  LIBC_INLINE_VAR static constexpr UIntType SIGN_MASK_ =
+
+public:
+  LIBC_INLINE_VAR static constexpr UIntType SIGN_MASK =
       mask_trailing_ones<UIntType, SIGN_BITS>() << SIGN_MASK_SHIFT;
+
+private:
   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 cover");
+  static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
+  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;
@@ -145,25 +150,21 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
                                                                   : SIG_BITS;
 
 public:
-  // Public facing API to keep the change local to this file.
-  using BitsType = UIntType;
-
   LIBC_INLINE_VAR static constexpr uint32_t BIT_WIDTH = TOTAL_BITS;
   LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_WIDTH = FRACTION_BITS;
   LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_PRECISION =
       MANTISSA_WIDTH + 1;
-  LIBC_INLINE_VAR static constexpr BitsType MANTISSA_MASK =
+  LIBC_INLINE_VAR static constexpr UIntType MANTISSA_MASK =
       mask_trailing_ones<UIntType, MANTISSA_WIDTH>();
   LIBC_INLINE_VAR static constexpr uint32_t EXPONENT_WIDTH = EXP_BITS;
   LIBC_INLINE_VAR static constexpr int32_t EXPONENT_BIAS = EXP_BIAS;
-  LIBC_INLINE_VAR static constexpr BitsType SIGN_MASK = SIGN_MASK_;
-  LIBC_INLINE_VAR static constexpr BitsType EXPONENT_MASK = EXP_MASK;
-  LIBC_INLINE_VAR static constexpr BitsType EXP_MANT_MASK = EXP_MASK | SIG_MASK;
+  LIBC_INLINE_VAR static constexpr UIntType EXPONENT_MASK = EXP_MASK;
+  LIBC_INLINE_VAR static constexpr UIntType EXP_MANT_MASK = EXP_MASK | SIG_MASK;
 
   // If a number x is a NAN, then it is a quiet NAN if:
   //   QuietNaNMask & bits(x) != 0
   // Else, it is a signalling NAN.
-  static constexpr BitsType QUIET_NAN_MASK = QNAN_MASK;
+  static constexpr UIntType QUIET_NAN_MASK = QNAN_MASK;
 };
 
 //-----------------------------------------------------------------------------


        


More information about the libc-commits mailing list