From b74c66618677ec27bc749c70b61d9b723c2e51c5 Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Wed, 17 Aug 2005 19:34:49 +0000 Subject: Culling out use of unions for converting FP to bits and vice versa. llvm-svn: 22838 --- llvm/lib/Bytecode/Writer/Writer.cpp | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'llvm/lib/Bytecode/Writer/Writer.cpp') diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp index 95bbd2e5754..b1f2634296f 100644 --- a/llvm/lib/Bytecode/Writer/Writer.cpp +++ b/llvm/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 @@ -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( (FloatUnion.i & 0xFF ))); - Out.push_back( static_cast( (FloatUnion.i >> 8) & 0xFF)); - Out.push_back( static_cast( (FloatUnion.i >> 16) & 0xFF)); - Out.push_back( static_cast( (FloatUnion.i >> 24) & 0xFF)); + uint32_t i = FloatToBits(FloatVal); + Out.push_back( static_cast( (i & 0xFF ))); + Out.push_back( static_cast( (i >> 8) & 0xFF)); + Out.push_back( static_cast( (i >> 16) & 0xFF)); + Out.push_back( static_cast( (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( (DoubleUnion.i & 0xFF ))); - Out.push_back( static_cast( (DoubleUnion.i >> 8) & 0xFF)); - Out.push_back( static_cast( (DoubleUnion.i >> 16) & 0xFF)); - Out.push_back( static_cast( (DoubleUnion.i >> 24) & 0xFF)); - Out.push_back( static_cast( (DoubleUnion.i >> 32) & 0xFF)); - Out.push_back( static_cast( (DoubleUnion.i >> 40) & 0xFF)); - Out.push_back( static_cast( (DoubleUnion.i >> 48) & 0xFF)); - Out.push_back( static_cast( (DoubleUnion.i >> 56) & 0xFF)); + uint64_t i = DoubleToBits(DoubleVal); + Out.push_back( static_cast( (i & 0xFF ))); + Out.push_back( static_cast( (i >> 8) & 0xFF)); + Out.push_back( static_cast( (i >> 16) & 0xFF)); + Out.push_back( static_cast( (i >> 24) & 0xFF)); + Out.push_back( static_cast( (i >> 32) & 0xFF)); + Out.push_back( static_cast( (i >> 40) & 0xFF)); + Out.push_back( static_cast( (i >> 48) & 0xFF)); + Out.push_back( static_cast( (i >> 56) & 0xFF)); } inline BytecodeBlock::BytecodeBlock(unsigned ID, BytecodeWriter& w, -- cgit v1.2.3