Req #72833 [NEW]: Use RDRND operand instead of Mersenne Twister
| From: | benjamin dot balet at gmail dot com | Date: | Sun, 14 Aug 2016 15:41:48 +0000 |
| Subject: | Req #72833 [NEW]: Use RDRND operand instead of Mersenne Twister | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-203278@lists.php.net to get a copy of this message | ||
From: benjamin dot balet at gmail dot com
Operating system:
PHP version: Irrelevant
Package: *Math Functions
Bug Type: Feature/Change Request
Bug description:Use RDRND operand instead of Mersenne Twister
Description:
------------
There are many non-cryptographic applications using the rand function of
PHP and I was wondering if it is worth the effort to implement a call to
the hardware function RDRND if it is supported by the platform.
Benefits of using RDRND:
* It is seeded with a true random number generator.
* Better source of random numbers than Mersenne Twister algorithm.
Concerns of using RDRND:
* This operand is available on recent Intel CPUs (Ivy Bridge) and only
in the coming Zen AMD Architecture.
* A bit slower than Mersenne Twister (if we omit the time it takes to
seed the algo from the benchmark).
Benefits of current PHP implementation:
* The code is faster than RDRND if we don't count the generation of the
seed number.
Concerns of current PHP implementation:
* A hard-coded limit of a 32 bits integer causes the need of two calls
and a shift of the result so as to create a 64 bits number.
* If the generator is not seeded, the PHP makes a syscall in order to
get the PID of PHP, whereas RDRND is seeded.
* Maybe considered as obsolete (see #67795).
The implementation (ext/standard/mt_rand.c) would look like
#ifdef __RDRND__
#include <immintrin.h>
// No need to call GENERATE_SEED()
# ifdef ZEND_ENABLE_ZVAL_LONG64
// Call to _rdrand64_step(uint64_t*);
# else
// Call to _rdrand32_step(uint32_t*);
# endif
#else
//current PHP implementation
#endif
--
Edit bug report at https://bugs.php.net/bug.php?id=72833&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72833&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72833&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72833&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72833&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72833&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72833&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72833&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72833&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72833&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72833&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72833&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72833&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72833&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72833&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72833&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72833&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72833&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72833&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72833&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72833&r=mysqlcfg