[PATCH] soft-fp: fix sticky bit in _FP_MUL_MEAT_2_120_240_double [BZ #34640]

Stian Halseth stian@itx.no
Fri Sep 25 10:39:51 GMT 2026


Hi Adhemerval

You're pushing this, right? I don't have commit access.

Best regards,
Stian


On Thu, 2026-09-17 at 19:47 +0200, Stian Halseth wrote:
> On Thu, 2026-09-17 at 17:22 +0000, Adhemerval Zanella Netto wrote:
> > 
> > 
> > On 16/09/26 13:17, Stian Halseth wrote:
> > > When R##_f0 is assembled the _o240 chunk is shifted right by
> > > (wfracbits - 1) - 96 bits, which is 19 for the quad format. 
> > > Those
> > > bits
> > > are discarded without being folded into the sticky bit _y240,
> > > which
> > > is
> > > computed only from _s240, _r240, _q240 and _p240, so a product
> > > whose
> > > only inexactness lies in the discarded bits is reported as exact.
> > > 
> > > sparc64 is the only user of this macro.  There _Qp_mul does not
> > > raise
> > > FE_INEXACT, and in the directed rounding modes the result is one
> > > ulp
> > > short because the rounding step sees no sticky bit;
> > > math/test-float64x-float128-mul reports 65 errors.
> > > 
> > > Fold the discarded bits into _y240.
> > > 
> > > Tested on sparc64: math/test-float64x-float128-mul goes from 65
> > > errors
> > > to none, the macro then agrees bit for bit with
> > > _FP_MUL_MEAT_2_wide
> > > on
> > > 200000 random operand pairs, and full make check shows no test
> > > that
> > > passed before failing after.
> > > 
> > > Signed-off-by: Stian Halseth <stian@itx.no>
> > 
> > LGTM, thanks.  It would good to send a similar fix to gcc/libgcc,
> > since
> > they share the implementation.
> 
> Thanks, will do!
> > 
> > Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
> > 
> > > ---
> > >  soft-fp/op-2.h | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/soft-fp/op-2.h b/soft-fp/op-2.h
> > > index 8778af21..760ca9b0 100644
> > > --- a/soft-fp/op-2.h
> > > +++ b/soft-fp/op-2.h
> > > @@ -515,6 +515,10 @@
> > >        _v240 = _m240.i; \
> > >        _w240 = _n240.i; \
> > >        _x240 = _o240.i; \
> > > +      /* The low bits of the _o240 chunk are shifted out when
> > > R##_f0 \
> > > + is assembled; fold them into the sticky bit.  */ \
> > > +      if ((_x240 & ((((UDItype) 1) << ((wfracbits) - 97)) - 1))
> > > !=
> > > 0) \
> > > + _y240 = 1; \
> > >        R##_f1 = ((_t240 << (128 - (wfracbits - 1))) \
> > >   | ((_u240 & 0xffffff) >> ((wfracbits - 1) - 104))); \
> > >        R##_f0 = (((_u240 & 0xffffff) << (168 - (wfracbits - 1)))
> > > \
> > 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260925/eb26752e/attachment-0001.sig>


More information about the Libc-alpha mailing list