Skip to content

Commit 18e65e2

Browse files
committed
Update after review. Extend the function to accept the two 128 bit float
types and add a testcase
1 parent 624b310 commit 18e65e2

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

llvm/include/llvm-c/Core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,10 +2341,10 @@ LLVM_C_ABI LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy,
23412341

23422342
/**
23432343
* Obtain a constant for a floating point FP128 value from 2 64 bit values.
2344-
* (112 bit mantissa)
2344+
* Only the LLVMFP128Type or LLVMPPCFP128Type are accepted.
23452345
*/
23462346

2347-
LLVMValueRef LLVMConstFP128(LLVMContextRef C, const uint64_t N[2]);
2347+
LLVM_C_ABI LLVMValueRef LLVMConstFP128(LLVMTypeRef Ty, const uint64_t N[2]);
23482348

23492349
/**
23502350
* Obtain the zero extended value for an integer constant value.

llvm/lib/IR/Core.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,11 +1573,12 @@ LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
15731573
return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
15741574
}
15751575

1576-
LLVMValueRef LLVMConstFP128(LLVMContextRef C, const uint64_t N[2]) {
1577-
Type *Ty = Type::getFP128Ty(*unwrap(C));
1576+
LLVMValueRef LLVMConstFP128(LLVMTypeRef Ty, const uint64_t N[2]) {
1577+
Type *T = unwrap(Ty);
1578+
assert(T->getPrimitiveSizeInBits() == 128 && "Ty size should be 128");
15781579
APInt AI(128, ArrayRef<uint64_t>(N, 2));
1579-
APFloat Quad(APFloat::IEEEquad(), AI);
1580-
return wrap(ConstantFP::get(Ty, Quad));
1580+
APFloat Quad(T->getFltSemantics(), AI);
1581+
return wrap(ConstantFP::get(T, Quad));
15811582
}
15821583

15831584
unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {

llvm/unittests/IR/ConstantsTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,5 +835,19 @@ TEST(ConstantsTest, BlockAddressCAPITest) {
835835
EXPECT_EQ(&BB, OutBB);
836836
}
837837

838+
TEST(ConstantsTest, Float128Test) {
839+
LLVMTypeRef Ty128 = LLVMFP128TypeInContext(LLVMGetGlobalContext());
840+
LLVMTypeRef TyPPC128 = LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
841+
LLVMBuilderRef Builder = LLVMCreateBuilder();
842+
uint64_t n[2] = {0x4000000000000000, 0x0}; //+2
843+
uint64_t m[2] = {0xC000000000000000, 0x0}; //-2
844+
LLVMValueRef val1 = LLVMConstFP128(Ty128, n);
845+
LLVMValueRef val2 = LLVMConstFP128(Ty128, m);
846+
LLVMValueRef val3 = LLVMBuildFAdd(Builder, val1, val2, "test");
847+
EXPECT_TRUE(val3 != nullptr);
848+
LLVMValueRef val4 = LLVMConstFP128(TyPPC128, n);
849+
EXPECT_TRUE(val4 != nullptr);
850+
}
851+
838852
} // end anonymous namespace
839853
} // end namespace llvm

0 commit comments

Comments
 (0)