[PATCH] D33116: [APInt] Use MathExtras.h BitsToFloat/Double and Float/DoubleToBits instead of type punning through a union
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 12 09:41:44 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL302916: [APInt] Use MathExtras.h BitsToFloat/Double and Float/DoubleToBits instead of… (authored by ctopper).
Changed prior to commit:
https://reviews.llvm.org/D33116?vs=98724&id=98791#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33116
Files:
llvm/trunk/include/llvm/ADT/APInt.h
Index: llvm/trunk/include/llvm/ADT/APInt.h
===================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h
+++ llvm/trunk/include/llvm/ADT/APInt.h
@@ -1657,52 +1657,32 @@
/// re-interprets the bits as a double. Note that it is valid to do this on
/// any bit width. Exactly 64 bits will be translated.
double bitsToDouble() const {
- union {
- uint64_t I;
- double D;
- } T;
- T.I = (isSingleWord() ? U.VAL : U.pVal[0]);
- return T.D;
+ return BitsToDouble(getWord(0));
}
/// \brief Converts APInt bits to a double
///
/// The conversion does not do a translation from integer to float, it just
/// re-interprets the bits as a float. Note that it is valid to do this on
/// any bit width. Exactly 32 bits will be translated.
float bitsToFloat() const {
- union {
- unsigned I;
- float F;
- } T;
- T.I = unsigned((isSingleWord() ? U.VAL : U.pVal[0]));
- return T.F;
+ return BitsToFloat(getWord(0));
}
/// \brief Converts a double to APInt bits.
///
/// The conversion does not do a translation from double to integer, it just
/// re-interprets the bits of the double.
static APInt doubleToBits(double V) {
- union {
- uint64_t I;
- double D;
- } T;
- T.D = V;
- return APInt(sizeof T * CHAR_BIT, T.I);
+ return APInt(sizeof(double) * CHAR_BIT, DoubleToBits(V));
}
/// \brief Converts a float to APInt bits.
///
/// The conversion does not do a translation from float to integer, it just
/// re-interprets the bits of the float.
static APInt floatToBits(float V) {
- union {
- unsigned I;
- float F;
- } T;
- T.F = V;
- return APInt(sizeof T * CHAR_BIT, T.I);
+ return APInt(sizeof(float) * CHAR_BIT, FloatToBits(V));
}
/// @}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33116.98791.patch
Type: text/x-patch
Size: 1850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170512/a13d56b7/attachment.bin>
More information about the llvm-commits
mailing list