mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
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
This commit is contained in:
@ -27,6 +27,7 @@
|
||||
#include "llvm/Config/alloca.h"
|
||||
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||
#include "llvm/Support/Compressor.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
@ -162,29 +163,19 @@ inline void BytecodeReader::read_data(void *Ptr, void *End) {
|
||||
inline void BytecodeReader::read_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.i = At[0] | (At[1] << 8) | (At[2] << 16) | (At[3] << 24);
|
||||
FloatVal = BitsToFloat(At[0] | (At[1] << 8) | (At[2] << 16) | (At[3] << 24));
|
||||
At+=sizeof(uint32_t);
|
||||
FloatVal = FloatUnion.f;
|
||||
}
|
||||
|
||||
/// Read a double value in little-endian order
|
||||
inline void BytecodeReader::read_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.i = (uint64_t(At[0]) << 0) | (uint64_t(At[1]) << 8) |
|
||||
(uint64_t(At[2]) << 16) | (uint64_t(At[3]) << 24) |
|
||||
(uint64_t(At[4]) << 32) | (uint64_t(At[5]) << 40) |
|
||||
(uint64_t(At[6]) << 48) | (uint64_t(At[7]) << 56);
|
||||
DoubleVal = BitsToDouble((uint64_t(At[0]) << 0) | (uint64_t(At[1]) << 8) |
|
||||
(uint64_t(At[2]) << 16) | (uint64_t(At[3]) << 24) |
|
||||
(uint64_t(At[4]) << 32) | (uint64_t(At[5]) << 40) |
|
||||
(uint64_t(At[6]) << 48) | (uint64_t(At[7]) << 56));
|
||||
At+=sizeof(uint64_t);
|
||||
DoubleVal = DoubleUnion.d;
|
||||
}
|
||||
|
||||
/// Read a block header and obtain its type and size
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user