Added another comment on the modulo trick

This commit is contained in:
wiire-a 2018-01-12 15:23:13 +01:00
parent c44ce9e923
commit b0b7dbb888

View File

@ -31,10 +31,12 @@ static inline uint32_t *glibc_fast_nonce(uint32_t seed, uint32_t *dest)
/* This does: seed = (16807LL * seed) % 0x7fffffff
using the sum of digits method which works for mod N, base N+1 */
/* Doesn't work for seed = 0x7fffffff or 0xfffffffe */
uint64_t p = 16807ULL * seed;
p = (p >> 31) + (p & 0x7fffffff);
seed = (p >> 31) + (p & 0x7fffffff);
#if 0 /* Same as PWPS_UNERRING */
if (seed == 0x7fffffff) seed = 0;
#endif
}
dest[0] = word0 >> 1;
dest[1] = word1 >> 1;
@ -57,10 +59,12 @@ static inline uint32_t glibc_fast_seed(uint32_t seed)
/* This does: seed = (16807LL * seed) % 0x7fffffff
using the sum of digits method which works for mod N, base N+1 */
/* Doesn't work for seed = 0x7fffffff or 0xfffffffe */
uint64_t p = 16807ULL * seed;
p = (p >> 31) + (p & 0x7fffffff);
seed = (p >> 31) + (p & 0x7fffffff);
#if 0 /* Same as PWPS_UNERRING */
if (seed == 0x7fffffff) seed = 0;
#endif
}
return (word0 + seed * glibc_seed_tbl[33]) >> 1;
}