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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 19 21:25:49 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19075

--- Comment #2 from github-bugzilla at 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

--


More information about the Digitalmars-d-bugs mailing list