mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-15 06:30:19 +00:00
Revised per review feedback from previous patch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41353 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ada530b4f5
commit
d3b51fd170
@ -194,6 +194,11 @@ namespace llvm {
|
|||||||
/* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
|
/* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
|
||||||
bool operator==(const APFloat &) const;
|
bool operator==(const APFloat &) const;
|
||||||
|
|
||||||
|
/* Inversion of the preceding. */
|
||||||
|
inline bool operator!=(const APFloat &RHS) const {
|
||||||
|
return !((*this)==RHS);
|
||||||
|
}
|
||||||
|
|
||||||
/* Simple queries. */
|
/* Simple queries. */
|
||||||
fltCategory getCategory() const { return category; }
|
fltCategory getCategory() const { return category; }
|
||||||
const fltSemantics &getSemantics() const { return *semantics; }
|
const fltSemantics &getSemantics() const { return *semantics; }
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "llvm/ADT/APFloat.h"
|
#include "llvm/ADT/APFloat.h"
|
||||||
|
#include "llvm/Support/MathExtras.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -1534,10 +1535,6 @@ APFloat::getHashValue() const {
|
|||||||
|
|
||||||
double
|
double
|
||||||
APFloat::convertToDouble() const {
|
APFloat::convertToDouble() const {
|
||||||
union {
|
|
||||||
double d;
|
|
||||||
uint64_t i;
|
|
||||||
} u;
|
|
||||||
assert(semantics == (const llvm::fltSemantics* const)&IEEEdouble);
|
assert(semantics == (const llvm::fltSemantics* const)&IEEEdouble);
|
||||||
assert (partCount()==1);
|
assert (partCount()==1);
|
||||||
|
|
||||||
@ -1562,17 +1559,12 @@ APFloat::convertToDouble() const {
|
|||||||
} else
|
} else
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
||||||
u.i = ((mysign & 1) << 63) | ((myexponent & 0x7ff) << 52) |
|
return BitsToDouble(((mysign & 1) << 63) | ((myexponent & 0x7ff) << 52) |
|
||||||
(mysignificand & 0xfffffffffffffLL);
|
(mysignificand & 0xfffffffffffffLL));
|
||||||
return u.d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
APFloat::convertToFloat() const {
|
APFloat::convertToFloat() const {
|
||||||
union {
|
|
||||||
float f;
|
|
||||||
int32_t i;
|
|
||||||
} u;
|
|
||||||
assert(semantics == (const llvm::fltSemantics* const)&IEEEsingle);
|
assert(semantics == (const llvm::fltSemantics* const)&IEEEsingle);
|
||||||
assert (partCount()==1);
|
assert (partCount()==1);
|
||||||
|
|
||||||
@ -1597,26 +1589,19 @@ APFloat::convertToFloat() const {
|
|||||||
} else
|
} else
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
||||||
u.i = ((mysign&1) << 31) | ((myexponent&0xff) << 23) |
|
return BitsToFloat(((mysign&1) << 31) | ((myexponent&0xff) << 23) |
|
||||||
((mysignificand & 0x7fffff));
|
(mysignificand & 0x7fffff));
|
||||||
return u.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
APFloat::APFloat(double d) {
|
APFloat::APFloat(double d) {
|
||||||
|
uint64_t i = DoubleToBits(d);
|
||||||
|
uint64_t mysign = i >> 63;
|
||||||
|
uint64_t myexponent = (i >> 52) & 0x7ff;
|
||||||
|
uint64_t mysignificand = i & 0xfffffffffffffLL;
|
||||||
|
|
||||||
initialize(&APFloat::IEEEdouble);
|
initialize(&APFloat::IEEEdouble);
|
||||||
union {
|
|
||||||
double d;
|
|
||||||
uint64_t i;
|
|
||||||
} u;
|
|
||||||
u.d = d;
|
|
||||||
assert(partCount()==1);
|
assert(partCount()==1);
|
||||||
|
|
||||||
uint64_t mysign, myexponent, mysignificand;
|
|
||||||
|
|
||||||
mysign = u.i >> 63;
|
|
||||||
myexponent = (u.i >> 52) & 0x7ff;
|
|
||||||
mysignificand = u.i & 0xfffffffffffffLL;
|
|
||||||
|
|
||||||
if (myexponent==0 && mysignificand==0) {
|
if (myexponent==0 && mysignificand==0) {
|
||||||
// exponent, significand meaningless
|
// exponent, significand meaningless
|
||||||
category = fcZero;
|
category = fcZero;
|
||||||
@ -1637,20 +1622,14 @@ APFloat::APFloat(double d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
APFloat::APFloat(float f) {
|
APFloat::APFloat(float f) {
|
||||||
|
uint32_t i = FloatToBits(f);
|
||||||
|
uint32_t mysign = i >> 31;
|
||||||
|
uint32_t myexponent = (i >> 23) & 0xff;
|
||||||
|
uint32_t mysignificand = i & 0x7fffff;
|
||||||
|
|
||||||
initialize(&APFloat::IEEEsingle);
|
initialize(&APFloat::IEEEsingle);
|
||||||
union {
|
|
||||||
float f;
|
|
||||||
uint32_t i;
|
|
||||||
} u;
|
|
||||||
u.f = f;
|
|
||||||
assert(partCount()==1);
|
assert(partCount()==1);
|
||||||
|
|
||||||
uint32_t mysign, myexponent, mysignificand;
|
|
||||||
|
|
||||||
mysign = u.i >> 31;
|
|
||||||
myexponent = (u.i >> 23) & 0xff;
|
|
||||||
mysignificand = u.i & 0x7fffff;
|
|
||||||
|
|
||||||
if (myexponent==0 && mysignificand==0) {
|
if (myexponent==0 && mysignificand==0) {
|
||||||
// exponent, significand meaningless
|
// exponent, significand meaningless
|
||||||
category = fcZero;
|
category = fcZero;
|
||||||
|
@ -253,25 +253,14 @@ bool ConstantFP::isExactlyValue(double V) const {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct DenseMapAPFloatKeyInfo {
|
struct DenseMapAPFloatKeyInfo {
|
||||||
struct KeyTy {
|
static inline APFloat getEmptyKey() {
|
||||||
APFloat val;
|
return APFloat(APFloat::Bogus,1);
|
||||||
KeyTy(const APFloat& V) : val(V){}
|
|
||||||
KeyTy(const KeyTy& that) : val(that.val) {}
|
|
||||||
bool operator==(const KeyTy& that) const {
|
|
||||||
return this->val == that.val;
|
|
||||||
}
|
|
||||||
bool operator!=(const KeyTy& that) const {
|
|
||||||
return !this->operator==(that);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
static inline KeyTy getEmptyKey() {
|
|
||||||
return KeyTy(APFloat(APFloat::Bogus,1));
|
|
||||||
}
|
}
|
||||||
static inline KeyTy getTombstoneKey() {
|
static inline APFloat getTombstoneKey() {
|
||||||
return KeyTy(APFloat(APFloat::Bogus,2));
|
return APFloat(APFloat::Bogus,2);
|
||||||
}
|
}
|
||||||
static unsigned getHashValue(const KeyTy &Key) {
|
static unsigned getHashValue(const APFloat &Key) {
|
||||||
return Key.val.getHashValue();
|
return Key.getHashValue();
|
||||||
}
|
}
|
||||||
static bool isPod() { return false; }
|
static bool isPod() { return false; }
|
||||||
};
|
};
|
||||||
@ -279,21 +268,21 @@ namespace {
|
|||||||
|
|
||||||
//---- ConstantFP::get() implementation...
|
//---- ConstantFP::get() implementation...
|
||||||
//
|
//
|
||||||
typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
|
typedef DenseMap<APFloat, ConstantFP*,
|
||||||
DenseMapAPFloatKeyInfo> FPMapTy;
|
DenseMapAPFloatKeyInfo> FPMapTy;
|
||||||
|
|
||||||
static ManagedStatic<FPMapTy> FPConstants;
|
static ManagedStatic<FPMapTy> FPConstants;
|
||||||
|
|
||||||
ConstantFP *ConstantFP::get(const Type *Ty, double V) {
|
ConstantFP *ConstantFP::get(const Type *Ty, double V) {
|
||||||
if (Ty == Type::FloatTy) {
|
if (Ty == Type::FloatTy) {
|
||||||
DenseMapAPFloatKeyInfo::KeyTy Key(APFloat((float)V));
|
APFloat Key(APFloat((float)V));
|
||||||
ConstantFP *&Slot = (*FPConstants)[Key];
|
ConstantFP *&Slot = (*FPConstants)[Key];
|
||||||
if (Slot) return Slot;
|
if (Slot) return Slot;
|
||||||
return Slot = new ConstantFP(Ty, (float)V);
|
return Slot = new ConstantFP(Ty, (float)V);
|
||||||
} else if (Ty == Type::DoubleTy) {
|
} else if (Ty == Type::DoubleTy) {
|
||||||
// Without the redundant cast, the following is taken to be
|
// Without the redundant cast, the following is taken to be
|
||||||
// a function declaration. What a language.
|
// a function declaration. What a language.
|
||||||
DenseMapAPFloatKeyInfo::KeyTy Key(APFloat((double)V));
|
APFloat Key(APFloat((double)V));
|
||||||
ConstantFP *&Slot = (*FPConstants)[Key];
|
ConstantFP *&Slot = (*FPConstants)[Key];
|
||||||
if (Slot) return Slot;
|
if (Slot) return Slot;
|
||||||
return Slot = new ConstantFP(Ty, V);
|
return Slot = new ConstantFP(Ty, V);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user