You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
random: Use branchless implementation for mask generation in Randomizer::getBytesFromString() (php#10522)
* random: Add `max_offset` local to Randomizer::getBytesFromString()
* random: Use branchless implementation for mask generation in Randomizer::getBytesFromString()
This was benchmarked against clzl with a standalone script with random inputs
and is slightly faster. clzl requires an additional branch to handle the
source_length = 1 / max_offset = 0 case.
* Improve comment for masking in Randomizer::getBytesFromString()
for (size_ti=0; i<randomizer->status->last_generated_size; i++) {
446
435
uint64_toffset= (result >> (i*8)) &mask;
447
436
448
-
if (offset >= source_length) {
437
+
if (offset>max_offset) {
449
438
if (++failures>PHP_RANDOM_RANGE_ATTEMPTS) {
450
439
zend_string_free(retval);
451
440
zend_throw_error(random_ce_Random_BrokenRandomEngineError, "Failed to generate an acceptable random number in %d attempts", PHP_RANDOM_RANGE_ATTEMPTS);
0 commit comments