mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 10:16:36 +01:00
DMD Issue 3632 - modify float is float to do a bitwise compare
This commit is contained in:
2
druntime
2
druntime
Submodule druntime updated: fba10fa9f6...e69646d6cd
@@ -7,6 +7,7 @@
|
||||
#include "gen/dvalue.h"
|
||||
#include "gen/logger.h"
|
||||
#include "gen/complex.h"
|
||||
#include "gen/llvmhelpers.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -108,10 +109,7 @@ LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
|
||||
assert(t->isfloating());
|
||||
Logger::println("numeric equality");
|
||||
|
||||
LLValue* lv = lhs->getRVal();
|
||||
LLValue* rv = rhs->getRVal();
|
||||
LLValue* res = 0;
|
||||
|
||||
if (t->iscomplex())
|
||||
{
|
||||
Logger::println("complex");
|
||||
@@ -120,11 +118,42 @@ LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
|
||||
else if (t->isfloating())
|
||||
{
|
||||
Logger::println("floating");
|
||||
res = (op == TOKidentity || op == TOKequal)
|
||||
? gIR->ir->CreateFCmpOEQ(lv,rv,"tmp")
|
||||
: gIR->ir->CreateFCmpUNE(lv,rv,"tmp");
|
||||
res = DtoBinFloatsEquals(loc, lhs, rhs, op);
|
||||
}
|
||||
|
||||
assert(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue* DtoBinFloatsEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
|
||||
{
|
||||
LLValue* res = 0;
|
||||
#if DMDV2
|
||||
if (op == TOKequal) {
|
||||
res = gIR->ir->CreateFCmpOEQ(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
} else if (op == TOKnotequal) {
|
||||
res = gIR->ir->CreateFCmpUNE(lhs->getRVal(), rhs->getRVal(), "tmp");
|
||||
} else {
|
||||
llvm::ICmpInst::Predicate cmpop;
|
||||
if (op == TOKidentity)
|
||||
cmpop = llvm::ICmpInst::ICMP_EQ;
|
||||
else
|
||||
cmpop = llvm::ICmpInst::ICMP_NE;
|
||||
|
||||
LLValue* sz = DtoConstSize_t(getTypeStoreSize(DtoType(lhs->getType())));
|
||||
LLValue* val = DtoMemCmp(makeLValue(loc, lhs), makeLValue(loc, rhs), sz);
|
||||
res = gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp");
|
||||
}
|
||||
#else
|
||||
LLValue* lv = lhs->getRVal();
|
||||
LLValue* rv = rhs->getRVal();
|
||||
res = (op == TOKidentity || op == TOKequal) ?
|
||||
gIR->ir->CreateFCmpOEQ(lv, rv, "tmp") :
|
||||
gIR->ir->CreateFCmpUNE(lv, rv, "tmp");
|
||||
|
||||
#endif
|
||||
assert(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& im)
|
||||
void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, DValue*& re, DValue*& im)
|
||||
{
|
||||
Type* baserety;
|
||||
Type* baseimty;
|
||||
@@ -149,21 +149,30 @@ void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*&
|
||||
if (t->iscomplex()) {
|
||||
DValue* v = DtoCastComplex(loc, val, to);
|
||||
if (to->iscomplex()) {
|
||||
re = gIR->ir->CreateExtractValue(v->getRVal(), 0, ".re_part");
|
||||
im = gIR->ir->CreateExtractValue(v->getRVal(), 1, ".im_part");
|
||||
if (v->isLVal()) {
|
||||
LLValue *reVal = DtoGEP(v->getLVal(), DtoConstInt(0), DtoConstInt(0), ".re_part");
|
||||
LLValue *imVal = DtoGEP(v->getLVal(), DtoConstInt(0), DtoConstInt(1), ".im_part");
|
||||
re = new DVarValue(baserety, reVal);
|
||||
im = new DVarValue(baseimty, imVal);
|
||||
} else {
|
||||
LLValue *reVal = gIR->ir->CreateExtractValue(v->getRVal(), 0, ".re_part");
|
||||
LLValue *imVal = gIR->ir->CreateExtractValue(v->getRVal(), 1, ".im_part");
|
||||
re = new DImValue(baserety, reVal);
|
||||
im = new DImValue(baseimty, imVal);
|
||||
}
|
||||
} else
|
||||
DtoGetComplexParts(loc, to, v, re, im);
|
||||
}
|
||||
else if (t->isimaginary()) {
|
||||
re = NULL;
|
||||
im = DtoCastFloat(loc, val, baseimty)->getRVal();
|
||||
im = DtoCastFloat(loc, val, baseimty);
|
||||
}
|
||||
else if (t->isfloating()) {
|
||||
re = DtoCastFloat(loc, val, baserety)->getRVal();
|
||||
re = DtoCastFloat(loc, val, baserety);
|
||||
im = NULL;
|
||||
}
|
||||
else if (t->isintegral()) {
|
||||
re = DtoCastInt(loc, val, baserety)->getRVal();
|
||||
re = DtoCastInt(loc, val, baserety);
|
||||
im = NULL;
|
||||
}
|
||||
else {
|
||||
@@ -173,6 +182,16 @@ void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*&
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& im)
|
||||
{
|
||||
DValue *dre, *dim;
|
||||
DtoGetComplexParts(loc, to, val, dre, dim);
|
||||
re = dre ? dre->getRVal() : 0;
|
||||
im = dim ? dim->getRVal() : 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im;
|
||||
@@ -396,23 +415,16 @@ LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* type = lhs->getType();
|
||||
|
||||
llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im;
|
||||
DValue *lhs_re, *lhs_im, *rhs_re, *rhs_im;
|
||||
|
||||
// lhs values
|
||||
DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im);
|
||||
// rhs values
|
||||
DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im);
|
||||
|
||||
// select predicate
|
||||
llvm::FCmpInst::Predicate cmpop;
|
||||
if (op == TOKequal || op == TOKidentity)
|
||||
cmpop = llvm::FCmpInst::FCMP_OEQ;
|
||||
else
|
||||
cmpop = llvm::FCmpInst::FCMP_UNE;
|
||||
|
||||
// (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im)
|
||||
LLValue* b1 = gIR->ir->CreateFCmp(cmpop, lhs_re, rhs_re, "tmp");
|
||||
LLValue* b2 = gIR->ir->CreateFCmp(cmpop, lhs_im, rhs_im, "tmp");
|
||||
LLValue* b1 = DtoBinFloatsEquals(loc, lhs_re, rhs_re, op);
|
||||
LLValue* b2 = DtoBinFloatsEquals(loc, lhs_im, rhs_im, op);
|
||||
|
||||
if (op == TOKequal)
|
||||
return gIR->ir->CreateAnd(b1,b2,"tmp");
|
||||
|
||||
@@ -14,6 +14,7 @@ DValue* DtoComplex(Loc& loc, Type* to, DValue* val);
|
||||
|
||||
void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im);
|
||||
|
||||
void DtoGetComplexParts(Loc& loc, Type* to, DValue* c, DValue*& re, DValue*& im);
|
||||
void DtoGetComplexParts(Loc& loc, Type* to, DValue* c, LLValue*& re, LLValue*& im);
|
||||
|
||||
DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs);
|
||||
|
||||
@@ -121,6 +121,7 @@ DValue* DtoBinMul(Type* resulttype, DValue* lhs, DValue* rhs);
|
||||
DValue* DtoBinDiv(Type* resulttype, DValue* lhs, DValue* rhs);
|
||||
DValue* DtoBinRem(Type* resulttype, DValue* lhs, DValue* rhs);
|
||||
LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op);
|
||||
LLValue* DtoBinFloatsEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op);
|
||||
|
||||
// target stuff
|
||||
void findDefaultTarget();
|
||||
|
||||
2
phobos
2
phobos
Submodule phobos updated: 929ba44294...a8106d9d48
Reference in New Issue
Block a user