Esempio n. 1
0
LLConstant* DtoConstFP(Type* t, longdouble value)
{
    LLType* llty = DtoType(t);
    assert(llty->isFloatingPointTy());

    if(llty == LLType::getFloatTy(gIR->context()) || llty == LLType::getDoubleTy(gIR->context()))
        return LLConstantFP::get(llty, value);
    else if(llty == LLType::getX86_FP80Ty(gIR->context())) {
        uint64_t bits[] = { 0, 0 };
        bits[0] = *reinterpret_cast<uint64_t*>(&value);
        bits[1] = *reinterpret_cast<uint16_t*>(reinterpret_cast<uint64_t*>(&value) + 1);
#if LDC_LLVM_VER >= 303
        return LLConstantFP::get(gIR->context(), APFloat(APFloat::x87DoubleExtended, APInt(80, 2, bits)));
#else
        return LLConstantFP::get(gIR->context(), APFloat(APInt(80, 2, bits)));
#endif
    } else if(llty == LLType::getPPC_FP128Ty(gIR->context())) {
        uint64_t bits[] = {0, 0};
        bits[0] = *reinterpret_cast<uint64_t*>(&value);
        bits[1] = *reinterpret_cast<uint16_t*>(reinterpret_cast<uint64_t*>(&value) + 1);
#if LDC_LLVM_VER >= 303
        return LLConstantFP::get(gIR->context(), APFloat(APFloat::PPCDoubleDouble, APInt(128, 2, bits)));
#else
        return LLConstantFP::get(gIR->context(), APFloat(APInt(128, 2, bits)));
#endif
    }

    llvm_unreachable("Unknown floating point type encountered");
}
Esempio n. 2
0
LLConstant *DtoConstFP(Type *t, const real_t value) {
  LLType *llty = DtoType(t);
  assert(llty->isFloatingPointTy());

  // 1) represent host real_t as llvm::APFloat
  const auto &targetSemantics = llty->getFltSemantics();
  APFloat v(targetSemantics, APFloat::uninitialized);
  CTFloat::toAPFloat(value, v);

  // 2) convert to target format
  if (&v.getSemantics() != &targetSemantics) {
    bool ignored;
    v.convert(targetSemantics, APFloat::rmNearestTiesToEven, &ignored);
  }

  return LLConstantFP::get(gIR->context(), v);
}
Esempio n. 3
0
File: tollvm.cpp Progetto: Doeme/ldc
LLConstant *DtoConstFP(Type *t, longdouble value) {
  LLType *llty = DtoType(t);
  assert(llty->isFloatingPointTy());

  if (llty == LLType::getFloatTy(gIR->context()) ||
      llty == LLType::getDoubleTy(gIR->context())) {
    return LLConstantFP::get(llty, value);
  }
  if (llty == LLType::getX86_FP80Ty(gIR->context())) {
    uint64_t bits[] = {0, 0};
    bits[0] = *reinterpret_cast<uint64_t *>(&value);
    bits[1] =
        *reinterpret_cast<uint16_t *>(reinterpret_cast<uint64_t *>(&value) + 1);
    return LLConstantFP::get(gIR->context(), APFloat(APFloat::x87DoubleExtended,
                                                     APInt(80, 2, bits)));
  }
  if (llty == LLType::getFP128Ty(gIR->context())) {
    union {
      longdouble ld;
      uint64_t bits[2];
    } t;
    t.ld = value;
    return LLConstantFP::get(gIR->context(),
                             APFloat(APFloat::IEEEquad, APInt(128, 2, t.bits)));
  }
  if (llty == LLType::getPPC_FP128Ty(gIR->context())) {
    uint64_t bits[] = {0, 0};
    bits[0] = *reinterpret_cast<uint64_t *>(&value);
    bits[1] =
        *reinterpret_cast<uint16_t *>(reinterpret_cast<uint64_t *>(&value) + 1);
    return LLConstantFP::get(
        gIR->context(), APFloat(APFloat::PPCDoubleDouble, APInt(128, 2, bits)));
  }

  llvm_unreachable("Unknown floating point type encountered");
}