PR fortran/91414: Improved PRNG
commit0e99e0933984e0c30fda1d089bfbd6857fc9273f
authorJanne Blomqvist <jb@gcc.gnu.org>
Tue, 13 Aug 2019 08:24:43 +0000 (13 11:24 +0300)
committerJanne Blomqvist <jb@gcc.gnu.org>
Tue, 13 Aug 2019 08:24:43 +0000 (13 11:24 +0300)
tree3f4221e36f548096ee6f0e64dab1b2660ceda1c6
parent519acab098317f6eab49b612e49d8fcc6562da8f
PR fortran/91414: Improved PRNG

Update the PRNG from xorshift1024* to xoshiro256** by the same
author. For details see

http://prng.di.unimi.it/

and the paper at

https://arxiv.org/abs/1805.01407

Also the seeding is slightly improved, by reading only 8 bytes from
the operating system and using the simple splitmix64 PRNG to fill in
the rest of the PRNG state (as recommended by the xoshiro author),
instead of reading the entire state from the OS.

Regtested on x86_64-pc-linux-gnu, Ok for trunk?

gcc/fortran/ChangeLog:

2019-08-13  Janne Blomqvist  <jb@gcc.gnu.org>

PR fortran/91414
* check.c (gfc_check_random_seed): Reduce seed_size.
* intrinsic.texi (RANDOM_NUMBER): Update to match new PRNG.

gcc/testsuite/ChangeLog:

2019-08-13  Janne Blomqvist  <jb@gcc.gnu.org>

PR fortran/91414
* gfortran.dg/random_seed_1.f90: Update to match new seed size.

libgfortran/ChangeLog:

2019-08-13  Janne Blomqvist  <jb@gcc.gnu.org>

PR fortran/91414
* intrinsics/random.c (prng_state): Update state struct.
(master_state): Update to match new size.
(get_rand_state): Update to match new PRNG.
(rotl): New function.
(xorshift1024star): Replace with prng_next.
(prng_next): New function.
(jump): Update for new PRNG.
(lcg_parkmiller): Replace with splitmix64.
(splitmix64): New function.
(getosrandom): Fix return value, simplify.
(init_rand_state): Use getosrandom only to get 8 bytes, splitmix64
to fill rest of state.
(random_r4): Update to new function and struct names.
(random_r8): Likewise.
(random_r10): Likewise.
(random_r16): Likewise.
(arandom_r4): Liekwise.
(arandom_r8): Likewise.
(arandom_r10): Likwewise.
(arandom_r16): Likewise.
(xor_keys): Reduce size to match new PRNG.
(random_seed_i4): Update to new function and struct names, remove
special handling of variable p used in previous PRNG.
(random_seed_i8): Likewise.

From-SVN: r274361
gcc/fortran/ChangeLog
gcc/fortran/check.c
gcc/fortran/intrinsic.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/random_seed_1.f90
libgfortran/ChangeLog
libgfortran/intrinsics/random.c