mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-27 13:54:19 +08:00
59b6cece54
The Knuth's division algorithm relies on the number of dividend limbs to be greater ore equal to number of divisor limbs, which is why I've added a special case for un < vn at the start of __divmodbitint4. Unfortunately, my assumption that it then implies abs(v) > abs(u) and so quotient must be 0 and remainder same as dividend is incorrect. This is because this check is done before negation of the operands. While bitint_reduce_prec reduces precision from clearly useless limbs, the problematic case is when the dividend is unsigned or non-negative and divisor is negative. We can have limbs (from MS to LS): dividend: 0 M ?... divisor: -1 -N ?... where M has most significant bit set and M >= N (if M == N then it also the following limbs matter) and the most significant limbs can be even partial. In this case, the quotient should be -1 rather than 0. bitint_reduce_prec will reduce the precision of the dividend so that M is the most significant limb, but can't reduce precision of the divisor to more than having the -1 as most significant limb, because -N doesn't have the most significant bit set. The following patch fixes it by detecting this problematic case in the un < vn handling, and instead of assuming q is 0 and r is u will decrease vn by 1 because it knows the later code will negate the divisor and it can be then expressed after negation in one fewer limbs. 2024-03-21 Jakub Jelinek <jakub@redhat.com> PR libgcc/114397 * libgcc2.c (__divmodbitint4): Don't assume un < vn always means abs(v) > abs(u), check for a special case of un + 1 == vn where u is non-negative and v negative and after v's negation vn could be reduced by 1. * gcc.dg/torture/bitint-65.c: New test. |
||
---|---|---|
.. | ||
c++-minimal | ||
config | ||
soft-fp | ||
ChangeLog | ||
config.host | ||
config.in | ||
configure | ||
configure.ac | ||
crtstuff.c | ||
dfp-bit.c | ||
dfp-bit.h | ||
divmod.c | ||
emutls.c | ||
enable-execute-stack-empty.c | ||
enable-execute-stack-mprotect.c | ||
find-symver.awk | ||
fixed-bit.c | ||
fixed-bit.h | ||
fixed-obj.mk | ||
floatunsidf.c | ||
floatunsisf.c | ||
floatunsitf.c | ||
floatunsixf.c | ||
fp-bit.c | ||
fp-bit.h | ||
gbl-ctors.h | ||
gcov.h | ||
gen-fixed.sh | ||
generic-morestack-thread.c | ||
generic-morestack.c | ||
generic-morestack.h | ||
gstdint.h | ||
gthr-posix.h | ||
gthr-single.h | ||
gthr.h | ||
hardcfr.c | ||
libgcc2.c | ||
libgcc2.h | ||
libgcc-std.ver.in | ||
libgcov-driver-system.c | ||
libgcov-driver.c | ||
libgcov-interface.c | ||
libgcov-merge.c | ||
libgcov-profiler.c | ||
libgcov-util.c | ||
libgcov.h | ||
Makefile.in | ||
memcmp.c | ||
memcpy.c | ||
memmove.c | ||
memset.c | ||
mkheader.sh | ||
mkmap-flat.awk | ||
mkmap-symver.awk | ||
offloadstuff.c | ||
shared-object.mk | ||
siditi-object.mk | ||
static-object.mk | ||
strub.c | ||
sync.c | ||
udivhi3.c | ||
udivmod.c | ||
udivmodhi4.c | ||
udivmodsi4.c | ||
unwind-arm-common.inc | ||
unwind-c.c | ||
unwind-compat.c | ||
unwind-compat.h | ||
unwind-dw2-btree.h | ||
unwind-dw2-execute_cfa.h | ||
unwind-dw2-fde-compat.c | ||
unwind-dw2-fde-dip.c | ||
unwind-dw2-fde.c | ||
unwind-dw2-fde.h | ||
unwind-dw2.c | ||
unwind-dw2.h | ||
unwind-generic.h | ||
unwind-pe.h | ||
unwind-seh.c | ||
unwind-sjlj.c | ||
unwind.inc | ||
vtv_end_preinit.c | ||
vtv_end.c | ||
vtv_start_preinit.c | ||
vtv_start.c |