Fix x86_fp80 constants.

This commit is contained in:
Christian Kamm
2008-10-06 09:07:35 +02:00
parent 0de539868e
commit 15e5f0e902
2 changed files with 19 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ using llvm::IRBuilder;
#define LLSmallVector llvm::SmallVector
#define APFloat llvm::APFloat
using llvm::APFloat;
using llvm::APInt;
#endif // GEN_LLVM_H

View File

@@ -529,7 +529,23 @@ llvm::ConstantFP* DtoConstFP(Type* t, long double value)
{
const LLType* llty = DtoType(t);
assert(llty->isFloatingPoint());
return LLConstantFP::get(llty, value);
if(llty == LLType::FloatTy || llty == LLType::DoubleTy)
return LLConstantFP::get(llty, value);
else if(llty == LLType::X86_FP80Ty) {
uint64_t bits[] = {0, 0};
bits[1] = *(uint16_t*)&value;
bits[0] = *((uint16_t*)&value + 4);
bits[0] <<= 16;
bits[0] += *((uint16_t*)&value + 3);
bits[0] <<= 16;
bits[0] += *((uint16_t*)&value + 2);
bits[0] <<= 16;
bits[0] += *((uint16_t*)&value + 1);
return LLConstantFP::get(APFloat(APInt(80, 2, bits)));
} else {
assert(0 && "Unknown floating point type encountered");
}
}
//////////////////////////////////////////////////////////////////////////////////////////