[compiler-rt] [compiler-rt] Implement __extendxftf2 and __trunctfxf2 for x86_64 (PR #66918)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 13:48:11 PDT 2023
================
@@ -81,19 +94,37 @@ static __inline dst_t __extendXfYf2__(src_t a) {
// bit (if needed) and right-aligning the rest of the trailing NaN
// payload field.
absResult = (dst_rep_t)dstInfExp << dstSigBits;
- absResult |= (dst_rep_t)(aAbs & srcQNaN) << (dstSigBits - srcSigBits);
- absResult |= (dst_rep_t)(aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
+ absResult |= (dst_rep_t)(aAbs & srcQNaN)
+ << (dstSigFracBits - srcSigFracBits);
+ absResult |= (dst_rep_t)(aAbs & srcNaNCode)
+ << (dstSigFracBits - srcSigFracBits);
}
else if (aAbs) {
// a is denormal.
- // renormalize the significand and clear the leading bit, then insert
- // the correct adjusted exponent in the destination type.
- const int scale = src_rep_t_clz(aAbs) - src_rep_t_clz(srcMinNormal);
- absResult = (dst_rep_t)aAbs << (dstSigBits - srcSigBits + scale);
- absResult ^= dstMinNormal;
- const int resultExponent = dstExpBias - srcExpBias - scale + 1;
- absResult |= (dst_rep_t)resultExponent << dstSigBits;
+ if (srcExpBits == dstExpBits) {
----------------
efriedma-quic wrote:
If I understand correctly, the key points here are:
- The exponent fields are identical
- This is a denormal number, so all the non-significand bits are zero.
So we just need to shift the bits. (And this code could be used with other floating-point formats, e.g. converting bfloat16->float. The differences between fp80 and other formats aren't relevant.)
Please update the comment to indicate f80->f128 is just a special-case of this general issue.
https://github.com/llvm/llvm-project/pull/66918
More information about the llvm-commits
mailing list