Thread overview
[Issue 19075] rt.util.random.Rand48.defaultSeed should prefer RDTSC or mach_absolute_time or QueryPerformanceCounter to ctime.time
Jul 19, 2018
Nathan S.
July 19, 2018
https://issues.dlang.org/show_bug.cgi?id=19075

Nathan S. <n8sh.secondary@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|rt.util.random.Rand48.defau |rt.util.random.Rand48.defau
                   |ltSeed should prefer RDTSC  |ltSeed should prefer RDTSC
                   |or mach_absolute_time to    |or mach_absolute_time or
                   |ctime.time                  |QueryPerformanceCounter to
                   |                            |ctime.time

--- Comment #1 from Nathan S. <n8sh.secondary@hotmail.com> ---
Verified that QueryPerformanceCounter is faster.

--
July 19, 2018
https://issues.dlang.org/show_bug.cgi?id=19075

--- Comment #2 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/449ef5265e46d57000bfb5a745b2be5856325e1e Fix Issue 19075 - rt.util.random.Rand48.defaultSeed should prefer RDTSC or mach_absolute_time or QueryPerformanceCounter to ctime.time

`rt.util.random.Rand48.defaultSeed` generates a seed from the clock using `ctime.time`. With `D_InlineAsm_X86_64` it would be better to use the RDTSC instruction because it is much faster as well as being finer precision. (Finer precision is a benefit not because we care about accurate time, but because the differences between seeds generated this way are potentially greater.) The same is true of `mach_absolute_time` on macOS and `QueryPerformanceCounter` on Microsoft Windows.

This PR doesn't use RDTSC with `D_InlineAsm_X86` because some x86 processors don't support RDTSC and because on x86 (but not x86-64) Linux `prctl` can disable a process's ability to use RDTSC.

https://github.com/dlang/druntime/commit/b3edb173828b75c23d3e2bd8614389d4a5ccb845 Merge pull request #2248 from n8sh/rt-defaultSeed-rdtsc

Fix Issue 19075 - rt.util.random.Rand48.defaultSeed should prefer RDTSC or mach_absolute_time or QueryPerformanceCounter to ctime.time

--
July 19, 2018
https://issues.dlang.org/show_bug.cgi?id=19075

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--