Raymond Toy pushed to branch rtoy-xoro-default at cmucl / cmucl
Commits:
-
9cd66071
by Raymond Toy at 2017-12-20T16:30:41-08:00
2 changed files:
Changes:
... | ... | @@ -18,7 +18,8 @@ |
18 | 18 |
make-random-state))
|
19 | 19 |
|
20 | 20 |
(in-package "KERNEL")
|
21 |
-(export '(%random-single-float %random-double-float random-chunk init-random-state))
|
|
21 |
+(export '(%random-single-float %random-double-float random-chunk init-random-state
|
|
22 |
+ random-state-jump))
|
|
22 | 23 |
|
23 | 24 |
(sys:register-lisp-feature :random-xoroshiro)
|
24 | 25 |
|
... | ... | @@ -470,7 +471,12 @@ |
470 | 471 |
:format-control (intl:gettext "Argument is not a positive integer or a positive float: ~S")
|
471 | 472 |
:format-arguments (list arg)))))
|
472 | 473 |
|
473 |
-(defun xoroshiro-jump (rng-state)
|
|
474 |
+;; Jump function for the generator. See the jump function in
|
|
475 |
+;; http://xoroshiro.di.unimi.it/xoroshiro128plus.c
|
|
476 |
+(defun random-state-jump (&optional (rng-state *random-state*))
|
|
477 |
+ "Jump the RNG-STATE. This is equivalent to 2^64 calls to the
|
|
478 |
+ xoroshiro128+ generator. It can be used to generate 2^64
|
|
479 |
+ non-overlapping subsequences for parallel computations."
|
|
474 | 480 |
(declare (type random-state rng-state))
|
475 | 481 |
(let ((state (random-state-state rng-state))
|
476 | 482 |
(s0-0 0)
|
... | ... | @@ -493,7 +499,6 @@ |
493 | 499 |
(kernel:double-float-bits (aref state 1))
|
494 | 500 |
(setf s1-1 (logxor s1-1 (ldb (byte 32 0) x1))
|
495 | 501 |
s1-0 (logxor s1-0 x0))))
|
496 |
- (format t "jump: ~D s0, s1 = ~X~8,'0X ~X~8,'0X~%" b s0-1 s0-0 s1-1 s1-0)
|
|
497 | 502 |
(xoroshiro-gen state)))
|
498 | 503 |
|
499 | 504 |
(flet ((convert (x1 x0)
|
... | ... | @@ -504,4 +509,3 @@ |
504 | 509 |
(setf (aref state 0) (convert s0-1 s0-0))
|
505 | 510 |
(setf (aref state 1) (convert s1-1 s1-0)))
|
506 | 511 |
rng-state))
|
507 |
- |
... | ... | @@ -55,3 +55,16 @@ |
55 | 55 |
item
|
56 | 56 |
(assert-equal value (64-bit-value *test-state*))
|
57 | 57 |
(assert-equal state (multiple-value-list (64-bit-rng-state *test-state*))))))
|
58 |
+ |
|
59 |
+(define-test rng.jump
|
|
60 |
+ (setf *test-state*
|
|
61 |
+ (kernel::make-random-object :state (kernel::init-random-state #x12345678)
|
|
62 |
+ :rand 0
|
|
63 |
+ :cached-p nil))
|
|
64 |
+ (dolist (result '((#x291ddf8e6f6a7b67 #x1f9018a12f9e031f)
|
|
65 |
+ (#x88a7aa12158558d0 #xe264d785ab1472d9)
|
|
66 |
+ (#x207e16f73c51e7ba #x999c8a0a9a8d87c0)
|
|
67 |
+ (#x28f8959d3bcf5ff1 #x38091e563ab6eb98)))
|
|
68 |
+ (kernel:random-state-jump *test-state*)
|
|
69 |
+ (assert-equal result (multiple-value-list
|
|
70 |
+ (64-bit-rng-state *test-state*)))))
|