diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2023-08-03 13:54:11 +0100 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2023-08-03 13:54:11 +0100 |
commit | 9524718654c3e4a13dd88bc1ac6409da1ec44e71 (patch) | |
tree | 808cb3c41cf6c3c412fccaf53ada40f91bb261f6 /gcc/range-op-float.cc | |
parent | 29370f1387274ad5a35a020db6a5d06c0324e6c1 (diff) | |
download | gcc-9524718654c3e4a13dd88bc1ac6409da1ec44e71.zip gcc-9524718654c3e4a13dd88bc1ac6409da1ec44e71.tar.gz gcc-9524718654c3e4a13dd88bc1ac6409da1ec44e71.tar.bz2 |
poly_int: Handle more can_div_trunc_p cases
can_div_trunc_p (a, b, &Q, &r) tries to compute a Q and r that
satisfy the usual conditions for truncating division:
(1) a = b * Q + r
(2) |b * Q| <= |a|
(3) |r| < |b|
We can compute Q using the constant component (the case when
all indeterminates are zero). Since |r| < |b| for the constant
case, the requirements for indeterminate xi with coefficients
ai (for a) and bi (for b) are:
(2') |bi * Q| <= |ai|
(3') |ai - bi * Q| <= |bi|
(See the big comment for more details, restrictions, and reasoning).
However, the function works on abstract arithmetic types, and so
it has to be careful not to introduce new overflow. The code
therefore only handled the extreme for (3'), that is:
|ai - bi * Q| = |bi|
for the case where Q is zero.
Looking at it again, the overflow issue is a bit easier to handle than
I'd originally thought (or so I hope). This patch therefore extends the
code to handle |ai - bi * Q| = |bi| for all Q, with Q = 0 no longer
being a separate case.
The net effect is to allow the function to succeed for things like:
(a0 + b1 (Q+1) x) / (b0 + b1 x)
where Q = a0 / b0, with various sign conditions. E.g. we now handle:
(7 + 8x) / (4 + 4x)
with Q = 1 and r = 3 + 4x,
gcc/
* poly-int.h (can_div_trunc_p): Succeed for more boundary conditions.
gcc/testsuite/
* gcc.dg/plugin/poly-int-tests.h (test_can_div_trunc_p_const)
(test_can_div_trunc_p_const): Add more tests.
Diffstat (limited to 'gcc/range-op-float.cc')
0 files changed, 0 insertions, 0 deletions