Add test for extreme 64-bit signed divide and modulo operations.
New test case covers edge cases for 64-bit signed division and modulo, particularly important for certain division algorithms.
A new test case, divmod-2.c, has been added to the GCC testsuite to cover 64-bit signed divide and modulo operations involving operands at the extremes of the type range. This scenario is critical for targets using radix-2 restoring division algorithms, where intermediate remainders near the bit-width limit can cause incorrect results. The test specifically targets a gap where operands near INT64_MIN and divisors near 2^63 might interact problematically. This fix was motivated by an issue on MicroBlaze but is applicable more broadly.
In Details
The gcc.c-torture/execute/divmod-2.c test has been added to address a gap in coverage for 64-bit signed division and modulo operations, particularly when both operands are near the extremes of the long long type. This is crucial for architectures employing radix-2 restoring division, where the partial remainder can reach 2^63—a point where sign-based decisions in the algorithm might diverge from unsigned comparisons. The test ensures that cases like INT64_MIN % -1 (or similar edge cases) are correctly handled, avoiding undefined behavior and potential hangs or aborts on specific targe…
- radix-2 restoring division
- A specific algorithm for performing division in hardware or software. It involves repeated subtractions and shifts, with a 'restoring' step if a subtraction results in a negative remainder.
- partial remainder
- In division algorithms, the intermediate result obtained after subtracting a multiple of the divisor from a part of the dividend. Its sign and magnitude are used to determine the next quotient digit.
- MicroBlaze
- A soft processor core from Xilinx, typically used in FPGAs. GCC provides a target backend for MicroBlaze.
- torture test
- A type of test in a compiler's testsuite designed to exercise compiler optimizations and code generation for particularly complex, obscure, or edge-case scenarios.