On Fri, 15 Mar 2024, Jakub Jelinek wrote: > Hi! > > While for __mulbitint3 we actually don't negate anything and perform the > multiplication in unsigned style always, for __divmodbitint4 if the operands > aren't unsigned and are negative, we negate them first and then try to > negate them as needed at the end. > quotient is negated if just one of the operands was negated and the other > wasn't or vice versa, and remainder is negated if the first operand was > negated. > The case which doesn't work correctly is if due to limited range of the > operands we perform the division/modulo in some smaller number of limbs > and then extend it to the desired precision of the quotient and/or > remainder results. If they aren't negated, the extension is done with > memset to 0, if they are negated, the extension was done with memset > to -1. The problem is that if the quotient or remainder is zero, > then bitint_negate negates it again to zero (that is ok), but we should > then extend with memset to 0, not memset to -1. > > The following patch achieves that by letting bitint_negate also check if > the negated operand is zero and changes the memset argument based on that. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK. -- Joseph S. Myers josmy...@redhat.com