Raymond Toy pushed to branch issue-276-xoroshiro128starstar at cmucl / cmucl

Commits:

3 changed files:

Changes:

  • src/code/rand-xoroshiro.lisp
    ... ... @@ -496,6 +496,7 @@
    496 496
     
    
    497 497
     ;; Jump function for the generator.  See the jump function in
    
    498 498
     ;; http://xoroshiro.di.unimi.it/xoroshiro128plus.c
    
    499
    +#-x86
    
    499 500
     (defun random-state-jump (&optional (rng-state *random-state*))
    
    500 501
       _N"Jump the RNG-STATE.  This is equivalent to 2^64 calls to the
    
    501 502
       xoroshiro128+ generator.  It can be used to generate 2^64
    
    ... ... @@ -535,3 +536,44 @@
    535 536
           (setf (aref state 0) (convert s0-1 s0-0))
    
    536 537
           (setf (aref state 1) (convert s1-1 s1-0)))
    
    537 538
         rng-state))
    
    539
    +
    
    540
    +#+x86
    
    541
    +(defun random-state-jump (&optional (rng-state *random-state*))
    
    542
    +  _N"Jump the RNG-STATE.  This is equivalent to 2^64 calls to the
    
    543
    +  xoroshiro128** generator.  It can be used to generate 2^64
    
    544
    +  non-overlapping subsequences for parallel computations."
    
    545
    +  (declare (type random-state rng-state))
    
    546
    +  (let ((state (random-state-state rng-state))
    
    547
    +	(s0-0 0)
    
    548
    +	(s0-1 0)
    
    549
    +	(s1-0 0)
    
    550
    +	(s1-1 0))
    
    551
    +    (declare (type (unsigned-byte 32) s0-0 s0-1 s1-0 s1-1)
    
    552
    +	     (optimize (speed 3) (safety 0)))
    
    553
    +    ;; The constants are #xdf900294d8f554a5 and #x170865df4b3201fc,
    
    554
    +    ;; and we process these numbers starting from the LSB.  We want ot
    
    555
    +    ;; process these in 32-bit chunks, so word-reverse the constants.
    
    556
    +    (dolist (jump '(#xdf900294d8f554a5 #x170865df4b3201fc))
    
    557
    +      (declare (type (unsigned-byte 64) jump))
    
    558
    +      (dotimes (b 64)
    
    559
    +	(declare (fixnum b))
    
    560
    +	(when (logbitp b jump)
    
    561
    +	  (multiple-value-bind (x1 x0)
    
    562
    +	      (kernel:double-float-bits (aref state 0))
    
    563
    +	    (setf s0-1 (logxor s0-1 (ldb (byte 32 0) x1))
    
    564
    +		  s0-0 (logxor s0-0 x0)))
    
    565
    +	  
    
    566
    +	  (multiple-value-bind (x1 x0)
    
    567
    +	      (kernel:double-float-bits (aref state 1))
    
    568
    +	    (setf s1-1 (logxor s1-1 (ldb (byte 32 0) x1))
    
    569
    +		  s1-0 (logxor s1-0 x0))))
    
    570
    +	(xoroshiro-gen state)))
    
    571
    +
    
    572
    +    (flet ((convert (x1 x0)
    
    573
    +	     (declare (type (unsigned-byte 32) x1 x0))
    
    574
    +	     (kernel:make-double-float
    
    575
    +	      (if (< x1 #x80000000) x1 (- x1 #x100000000))
    
    576
    +	      x0)))
    
    577
    +      (setf (aref state 0) (convert s0-1 s0-0))
    
    578
    +      (setf (aref state 1) (convert s1-1 s1-0)))
    
    579
    +    rng-state))

  • src/i18n/locale/cmucl.pot
    ... ... @@ -12237,6 +12237,13 @@ msgid ""
    12237 12237
     "  non-overlapping subsequences for parallel computations."
    
    12238 12238
     msgstr ""
    
    12239 12239
     
    
    12240
    +#: src/code/rand-xoroshiro.lisp
    
    12241
    +msgid ""
    
    12242
    +"Jump the RNG-STATE.  This is equivalent to 2^64 calls to the\n"
    
    12243
    +"  xoroshiro128** generator.  It can be used to generate 2^64\n"
    
    12244
    +"  non-overlapping subsequences for parallel computations."
    
    12245
    +msgstr ""
    
    12246
    +
    
    12240 12247
     #: src/code/ntrace.lisp
    
    12241 12248
     msgid ""
    
    12242 12249
     "This is bound to the returned values when evaluating :BREAK-AFTER and\n"
    

  • tests/rng.lisp
    ... ... @@ -81,10 +81,16 @@
    81 81
     	(kernel::make-random-object :state (kernel::init-random-state #x12345678)
    
    82 82
     				    :rand 0
    
    83 83
     				    :cached-p nil))
    
    84
    -  (dolist (result '((#x291ddf8e6f6a7b67 #x1f9018a12f9e031f)
    
    85
    -		    (#x88a7aa12158558d0 #xe264d785ab1472d9)
    
    86
    -		    (#x207e16f73c51e7ba #x999c8a0a9a8d87c0)
    
    87
    -		    (#x28f8959d3bcf5ff1 #x38091e563ab6eb98)))
    
    84
    +  (dolist (result
    
    85
    +           #-x86 '((#x291ddf8e6f6a7b67 #x1f9018a12f9e031f)
    
    86
    +		   (#x88a7aa12158558d0 #xe264d785ab1472d9)
    
    87
    +		   (#x207e16f73c51e7ba #x999c8a0a9a8d87c0)
    
    88
    +		   (#x28f8959d3bcf5ff1 #x38091e563ab6eb98))
    
    89
    +           #+x86 '((#x19a22191480b0a4e #x43b3d7ee592dd4cf)
    
    90
    +                   (#x76cb87035d0b6e99 #xb6827bcf2ef8267c)
    
    91
    +                   (#x5125201dbdf76860 #x8984c075043869e2)
    
    92
    +                   (#x2c06f0667255309f #xa48cbe2e60fc1d65)
    
    93
    +                   ))
    
    88 94
         (kernel:random-state-jump *test-state*)
    
    89 95
         (assert-equal result (multiple-value-list
    
    90 96
     			  (64-bit-rng-state *test-state*)))))