[llvm] [llvm-c] Create a 128 bit floating point constant from 2 64 bit values (PR #164381)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 1 07:11:57 PST 2025
================
@@ -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));
+}
----------------
nikic wrote:
This looks fine for the FP128 special case, but I was more thinking along the lines of this, without the assertion:
```suggestion
LLVMValueRef LLVMConstFPFromBits(LLVMTypeRef Ty, const uint64_t N[]) {
Type *T = unwrap(Ty);
unsigned SB = T->getScalarSizeInBits();
APInt AI(SB, ArrayRef<uint64_t>(N, divideCeil(SB, 64)));
APFloat Quad(T->getFltSemantics(), AI);
return wrap(ConstantFP::get(T, Quad));
}
```
Such that it works for all FP types. Then e.g. if you use `double` (or `float`, or `half`) you'd pass a single uint64_t.
(A bit unsure on the name, it looks like all the other related functions use LLVMConstReal instead of LLVMConstFP, even though the latter is really a better name...)
https://github.com/llvm/llvm-project/pull/164381
More information about the llvm-commits
mailing list