Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of denormals in nqp::div_In
Makes 3.1x faster: nqp::div_In with 2**1020 Ints 19.3x faster: nqp::div_In with 2**1020100020 Ints Fixes RT#130155: https://rt.perl.org/Ticket/Display.html?id=130155 Fixes RT#130154: https://rt.perl.org/Ticket/Display.html?id=130154 Fixes RT#130153: https://rt.perl.org/Ticket/Display.html?id=130153 The current code makes two incorrect assumptions: - USED()*DIGIT_BIT actually gives the maximum bits were the largest digit filled. With 60-bit digits we use, we were wasting cycles reducing numbers we didn't have to. This is also the reason why large normal doubles were overflowing, despite the bug affecting denormals only. Fix by using mp_count_bits() instead - mp_div_2d() reduces up to zero, but because denormals exist we have conditions (e.g. nqp::div_In(1, 2**1074)) where denominator is a lot larger than can fit into a double, despite the devision producing a perfectly cromulent denormal double. Fix by getting rid of all the mp_div_2d() and reduced_* stuff and instead making mp_get_double() take a shift parameter that adjusts the power of two we raise the result to (including negatives). This lets us adjust `1` in nqp::div_In(1, 2**1074) to be below `1`, so that after division, we get a proper denormal.
- Loading branch information