bodr...@mail.dm.unipi.it writes: Code says: if (d & GMP_NUMB_HIGHBIT) { /* Normalized case */ uh = up[--n]; /* Here n goes to 0 */ ... if (BELOW_THRESHOLD (n, DIV_QR_1_NORM_THRESHOLD)) { while (n > 0) udiv_qrnnd (...); return uh; } return mpn_div_qr_1n_pi1 (qp, up, n, uh, d, dinv); } The error arises when DIV_QR_1_NORM_THRESHOLD is zero, and the BELOW_THRESHOLD is unconditionally false, so that the code doesn't simply return uh, but calls mpn_div_qr_1n_pi1 with n = 0... I disallowed zero DIV_QR_1_NORM_THRESHOLD with this patch: https://gmplib.org/repo/gmp/rev/83258bea6f8f and the GMP_CHECK_RANDOMIZE=3526906869 test passes. I believe that we should, for the same reasons, disallow zero DIV_QR_1_UNNORM_THRESHOLD in the /* Unnormalized case */ branch. Since we control these thresholds at the source level, if it is desirable to keep DIV_QR_1_UNNORM_THRESHOLD >= 1, that should be done in tuneup.
Your patch adds some overhead when tuning, since then DIV_QR_1_UNNORM_THRESHOLD is not really constant. Also, keeping DIV_QR_1_UNNORM_THRESHOLD >= 1 surely does the job, but it puts another test it the critical path. Perhaps that's unavoidable, I haven't checked. Torbjörn _______________________________________________ gmp-devel mailing list gmp-devel@gmplib.org https://gmplib.org/mailman/listinfo/gmp-devel