[llvm] 0f52c1f - [llvm] Deprecate {Bits,Float,Double}To{Bits,Float,Double} (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 09:52:43 PST 2023


Author: Kazu Hirata
Date: 2023-02-14T09:52:36-08:00
New Revision: 0f52c1f86c62dadf69a7b732779abf59edea3d5c

URL: https://github.com/llvm/llvm-project/commit/0f52c1f86c62dadf69a7b732779abf59edea3d5c
DIFF: https://github.com/llvm/llvm-project/commit/0f52c1f86c62dadf69a7b732779abf59edea3d5c.diff

LOG: [llvm] Deprecate {Bits,Float,Double}To{Bits,Float,Double} (NFC)

Differential Revision: https://reviews.llvm.org/D143990

Added: 
    

Modified: 
    llvm/include/llvm/Support/MathExtras.h
    llvm/unittests/Support/MathExtrasTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index b009ba3fcea98..92f5b4562be97 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -403,12 +403,14 @@ inline unsigned Log2_64_Ceil(uint64_t Value) {
 }
 
 /// This function takes a 64-bit integer and returns the bit equivalent double.
+LLVM_DEPRECATED("use llvm::bit_cast instead", "llvm::bit_cast<double>")
 inline double BitsToDouble(uint64_t Bits) {
   static_assert(sizeof(uint64_t) == sizeof(double), "Unexpected type sizes");
   return llvm::bit_cast<double>(Bits);
 }
 
 /// This function takes a 32-bit integer and returns the bit equivalent float.
+LLVM_DEPRECATED("use llvm::bit_cast instead", "llvm::bit_cast<float>")
 inline float BitsToFloat(uint32_t Bits) {
   static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes");
   return llvm::bit_cast<float>(Bits);
@@ -417,6 +419,7 @@ inline float BitsToFloat(uint32_t Bits) {
 /// This function takes a double and returns the bit equivalent 64-bit integer.
 /// Note that copying doubles around changes the bits of NaNs on some hosts,
 /// notably x86, so this routine cannot be used if these bits are needed.
+LLVM_DEPRECATED("use llvm::bit_cast instead", "llvm::bit_cast<uint64_t>")
 inline uint64_t DoubleToBits(double Double) {
   static_assert(sizeof(uint64_t) == sizeof(double), "Unexpected type sizes");
   return llvm::bit_cast<uint64_t>(Double);
@@ -425,6 +428,7 @@ inline uint64_t DoubleToBits(double Double) {
 /// This function takes a float and returns the bit equivalent 32-bit integer.
 /// Note that copying floats around changes the bits of NaNs on some hosts,
 /// notably x86, so this routine cannot be used if these bits are needed.
+LLVM_DEPRECATED("use llvm::bit_cast instead", "llvm::bit_cast<uint32_t>")
 inline uint32_t FloatToBits(float Float) {
   static_assert(sizeof(uint32_t) == sizeof(float), "Unexpected type sizes");
   return llvm::bit_cast<uint32_t>(Float);

diff  --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp
index ca724d1c2b944..72c765d9ba300 100644
--- a/llvm/unittests/Support/MathExtrasTest.cpp
+++ b/llvm/unittests/Support/MathExtrasTest.cpp
@@ -162,16 +162,6 @@ TEST(MathExtras, CTLog2) {
   EXPECT_EQ(CTLog2<1ULL << 15>(), 15U);
 }
 
-TEST(MathExtras, FloatBits) {
-  static const float kValue = 5632.34f;
-  EXPECT_FLOAT_EQ(kValue, BitsToFloat(FloatToBits(kValue)));
-}
-
-TEST(MathExtras, DoubleBits) {
-  static const double kValue = 87987234.983498;
-  EXPECT_DOUBLE_EQ(kValue, BitsToDouble(DoubleToBits(kValue)));
-}
-
 TEST(MathExtras, MinAlign) {
   EXPECT_EQ(1u, MinAlign(2, 3));
   EXPECT_EQ(2u, MinAlign(2, 4));


        


More information about the llvm-commits mailing list