summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorJF Bastien <jfbastien@apple.com>2018-09-07 23:23:47 +0000
committerJF Bastien <jfbastien@apple.com>2018-09-07 23:23:47 +0000
commit05430cc6e55ff3ec6e8f38960c54e9b593e3718c (patch)
treee0ab4873f8261232b4958d191b414d5ccdfede07 /llvm/lib/Support
parentda4b63ab9afede44bb063adf26d5e9e5f14818c2 (diff)
downloadbcm5719-llvm-05430cc6e55ff3ec6e8f38960c54e9b593e3718c.tar.gz
bcm5719-llvm-05430cc6e55ff3ec6e8f38960c54e9b593e3718c.zip
Revert "ADT: add <bit> header, implement C++20 bit_cast, use"
Bots sad. Looks like missing std::is_trivially_copyable. llvm-svn: 341730
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/APInt.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index f2f5cca946f..f3c2ca5dab9 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -19,7 +19,6 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/bit.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
@@ -713,20 +712,24 @@ APInt llvm::APIntOps::GreatestCommonDivisor(APInt A, APInt B) {
}
APInt llvm::APIntOps::RoundDoubleToAPInt(double Double, unsigned width) {
- uint64_t I = bit_cast<uint64_t>(Double);
+ union {
+ double D;
+ uint64_t I;
+ } T;
+ T.D = Double;
// Get the sign bit from the highest order bit
- bool isNeg = I >> 63;
+ bool isNeg = T.I >> 63;
// Get the 11-bit exponent and adjust for the 1023 bit bias
- int64_t exp = ((I >> 52) & 0x7ff) - 1023;
+ int64_t exp = ((T.I >> 52) & 0x7ff) - 1023;
// If the exponent is negative, the value is < 0 so just return 0.
if (exp < 0)
return APInt(width, 0u);
// Extract the mantissa by clearing the top 12 bits (sign + exponent).
- uint64_t mantissa = (I & (~0ULL >> 12)) | 1ULL << 52;
+ uint64_t mantissa = (T.I & (~0ULL >> 12)) | 1ULL << 52;
// If the exponent doesn't shift all bits out of the mantissa
if (exp < 52)
@@ -803,8 +806,12 @@ double APInt::roundToDouble(bool isSigned) const {
// The leading bit of mantissa is implicit, so get rid of it.
uint64_t sign = isNeg ? (1ULL << (APINT_BITS_PER_WORD - 1)) : 0;
- uint64_t I = sign | (exp << 52) | mantissa;
- return bit_cast<double>(I);
+ union {
+ double D;
+ uint64_t I;
+ } T;
+ T.I = sign | (exp << 52) | mantissa;
+ return T.D;
}
// Truncate to new width.
OpenPOWER on IntegriCloud