summaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer
diff options
context:
space:
mode:
authorJim Laskey <jlaskey@mac.com>2005-08-17 19:34:49 +0000
committerJim Laskey <jlaskey@mac.com>2005-08-17 19:34:49 +0000
commitcb6682fa44e13262bdef7dd22b4ba90f8c2e7b97 (patch)
tree7007ebf49e8bf80c2f04c0df03980f65ddd88077 /lib/Bytecode/Writer
parent8482dd894d7d64134f999d8e62bc9adf5cb239a9 (diff)
downloadllvm-cb6682fa44e13262bdef7dd22b4ba90f8c2e7b97.tar.gz
llvm-cb6682fa44e13262bdef7dd22b4ba90f8c2e7b97.tar.bz2
llvm-cb6682fa44e13262bdef7dd22b4ba90f8c2e7b97.tar.xz
Culling out use of unions for converting FP to bits and vice versa.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Writer')
-rw-r--r--lib/Bytecode/Writer/Writer.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 95bbd2e575..b1f2634296 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -27,6 +27,7 @@
#include "llvm/SymbolTable.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/Compressor.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include <cstring>
@@ -139,33 +140,25 @@ inline void BytecodeWriter::output_data(const void *Ptr, const void *End) {
inline void BytecodeWriter::output_float(float& FloatVal) {
/// FIXME: This isn't optimal, it has size problems on some platforms
/// where FP is not IEEE.
- union {
- float f;
- uint32_t i;
- } FloatUnion;
- FloatUnion.f = FloatVal;
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i & 0xFF )));
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i >> 8) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i >> 16) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i >> 24) & 0xFF));
+ uint32_t i = FloatToBits(FloatVal);
+ Out.push_back( static_cast<unsigned char>( (i & 0xFF )));
+ Out.push_back( static_cast<unsigned char>( (i >> 8) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 16) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 24) & 0xFF));
}
inline void BytecodeWriter::output_double(double& DoubleVal) {
/// FIXME: This isn't optimal, it has size problems on some platforms
/// where FP is not IEEE.
- union {
- double d;
- uint64_t i;
- } DoubleUnion;
- DoubleUnion.d = DoubleVal;
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i & 0xFF )));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 8) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 16) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 24) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 32) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 40) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 48) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 56) & 0xFF));
+ uint64_t i = DoubleToBits(DoubleVal);
+ Out.push_back( static_cast<unsigned char>( (i & 0xFF )));
+ Out.push_back( static_cast<unsigned char>( (i >> 8) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 16) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 24) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 32) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 40) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 48) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 56) & 0xFF));
}
inline BytecodeBlock::BytecodeBlock(unsigned ID, BytecodeWriter& w,