Branch: Tag:

2016-04-17

2016-04-17 21:57:10 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Gmp.mpz: Optimized _random() some more.

There's no need to compare the limits in the power of 2 case.

2075:    mask >>= 1;    bits--;    +  /* There's also no need to compare the limit, as +  * all bitpatterns are valid after masking. +  */ +  fast=1; +     if (!(bits & 0x07)) {    /* One less byte of random data needed. */    bytes--; -  fast=1; +  fast = 2; /* No need for masking either. */    }    }   
2104:    mpz_import(mpz_res, bytes, 1, 1, 0, 0, sp[-1].u.string->str);    pop_stack();    -  if (fast) { +  if (fast == 2) {    /* We've decreased the number of bytes above.    * Ie we have the special case of an even number of random bytes.    */
2126:    }    }    -  if( mpz_cmp(THIS, mpz_res) > 0 ) +  if( fast || mpz_cmp(THIS, mpz_res) > 0 )    goto done;    /* NB: With a rectangular distribution we have a probability    * of success of at least 50% in the test above, so the