Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,13 @@ LLVM_C_ABI LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy,
const char *Text,
unsigned SLen);

/**
* Obtain a constant for a floating point FP128 value from 2 64 bit values.
* Only the LLVMFP128Type or LLVMPPCFP128Type are accepted.
*/

LLVM_C_ABI LLVMValueRef LLVMConstFP128(LLVMTypeRef Ty, const uint64_t N[2]);

/**
* Obtain the zero extended value for an integer constant value.
*
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,15 @@ LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
}

LLVMValueRef LLVMConstFP128(LLVMTypeRef Ty, const uint64_t N[2]) {
Type *T = unwrap(Ty);
unsigned SB = T->getScalarSizeInBits();
assert(SB == 128 && "Ty size should be 128");
APInt AI(SB, ArrayRef<uint64_t>(N, divideCeil(SB, 64)));
APFloat Quad(T->getFltSemantics(), AI);
return wrap(ConstantFP::get(T, Quad));
}

unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
}
Expand Down
14 changes: 14 additions & 0 deletions llvm/unittests/IR/ConstantsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,5 +835,19 @@ TEST(ConstantsTest, BlockAddressCAPITest) {
EXPECT_EQ(&BB, OutBB);
}

TEST(ConstantsTest, Float128Test) {
LLVMTypeRef Ty128 = LLVMFP128TypeInContext(LLVMGetGlobalContext());
LLVMTypeRef TyPPC128 = LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
LLVMBuilderRef Builder = LLVMCreateBuilder();
uint64_t n[2] = {0x4000000000000000, 0x0}; //+2
uint64_t m[2] = {0xC000000000000000, 0x0}; //-2
LLVMValueRef val1 = LLVMConstFP128(Ty128, n);
LLVMValueRef val2 = LLVMConstFP128(Ty128, m);
LLVMValueRef val3 = LLVMBuildFAdd(Builder, val1, val2, "test");
EXPECT_TRUE(val3 != nullptr);
LLVMValueRef val4 = LLVMConstFP128(TyPPC128, n);
EXPECT_TRUE(val4 != nullptr);
}

} // end anonymous namespace
} // end namespace llvm
Loading