Raymond Toy pushed to branch issue-276-xoroshiro128starstar at cmucl / cmucl
Commits: 7b03d6e1 by Raymond Toy at 2024-03-11T16:05:29-07:00 Remove old xoroshiro jump function; update comments/docstrings
The old xoroshiro jump function is not needed since we now have a Lisp version of xoroshiro128**; we can use the new jump function everywhere now.
Update the comments to match the implementation and add some docstrings.
- - - - - eb500219 by Raymond Toy at 2024-03-11T16:10:39-07:00 Update pot file for new docstrings.
- - - - -
2 changed files:
- src/code/rand-xoroshiro.lisp - src/i18n/locale/cmucl.pot
Changes:
===================================== src/code/rand-xoroshiro.lisp ===================================== @@ -225,18 +225,27 @@ ;;;; Random entries:
-;; Sparc and x86 have vops to implement xoroshiro-gen that are much -;; faster than the portable lisp version. Use them. -#+(or x86 sparc) +;; X86 has a vop to implement xoroshiro-gen that is about 4.5 times +;; faster than the portable lisp version below. For other +;; architectures, we use the portable version until a vop is written. +#+x86 (declaim (inline xoroshiro-gen)) -#+(or x86) +#+x86 (defun xoroshiro-gen (state) + _N"Generate the next 64-bit result from the xoroshiro128** generator + using the state in STATE, a simple-array of 2 double-floats. The + 64-bit result is returned as 2 32-bit values, with the high 32-bits + being the first value." (declare (type (simple-array double-float (2)) state) (optimize (speed 3) (safety 0))) (vm::xoroshiro-next state))
-#+(or sparc) +#-x86 (defun xoroshiro-gen (state) + _N"Generate the next 64-bit result from the xoroshiro128** generator + using the state in STATE, a simple-array of 2 double-floats. The + 64-bit result is returned as 2 32-bit values, with the high 32-bits + being the first value." (declare (type (simple-array double-float (2)) state) (optimize (speed 3) (safety 0))) (flet @@ -502,49 +511,7 @@ :format-arguments (list arg)))))
;; Jump function for the generator. See the jump function in -;; http://xoroshiro.di.unimi.it/xoroshiro128plus.c -#-x86 -(defun random-state-jump (&optional (rng-state *random-state*)) - _N"Jump the RNG-STATE. This is equivalent to 2^64 calls to the - xoroshiro128+ generator. It can be used to generate 2^64 - non-overlapping subsequences for parallel computations." - (declare (type random-state rng-state)) - (let ((state (random-state-state rng-state)) - (s0-0 0) - (s0-1 0) - (s1-0 0) - (s1-1 0)) - (declare (type (unsigned-byte 32) s0-0 s0-1 s1-0 s1-1) - (optimize (speed 3) (safety 0))) - ;; The constants are #xbeac0467eba5facb and #xd86b048b86aa9922, - ;; and we process these numbers starting from the LSB. We want ot - ;; process these in 32-bit chunks, so word-reverse the constants. - (dolist (jump '(#xeba5facb #xbeac0467 #x86aa9922 #xd86b048b)) - (declare (type (unsigned-byte 32) jump)) - (dotimes (b 32) - (declare (fixnum b)) - (when (logbitp b jump) - (multiple-value-bind (x1 x0) - (kernel:double-float-bits (aref state 0)) - (setf s0-1 (logxor s0-1 (ldb (byte 32 0) x1)) - s0-0 (logxor s0-0 x0))) - - (multiple-value-bind (x1 x0) - (kernel:double-float-bits (aref state 1)) - (setf s1-1 (logxor s1-1 (ldb (byte 32 0) x1)) - s1-0 (logxor s1-0 x0)))) - (xoroshiro-gen state))) - - (flet ((convert (x1 x0) - (declare (type (unsigned-byte 32) x1 x0)) - (kernel:make-double-float - (if (< x1 #x80000000) x1 (- x1 #x100000000)) - x0))) - (setf (aref state 0) (convert s0-1 s0-0)) - (setf (aref state 1) (convert s1-1 s1-0))) - rng-state)) - -#+x86 +;; https://prng.di.unimi.it/xoroshiro128starstar.c (defun random-state-jump (&optional (rng-state *random-state*)) _N"Jump the RNG-STATE. This is equivalent to 2^64 calls to the xoroshiro128** generator. It can be used to generate 2^64
===================================== src/i18n/locale/cmucl.pot ===================================== @@ -12222,19 +12222,20 @@ msgstr ""
#: src/code/rand-xoroshiro.lisp msgid "" -"Generate a uniformly distributed pseudo-random number between zero\n" -" and Arg. State, if supplied, is the random state to use." +"Generate the next 64-bit result from the xoroshiro128** generator\n" +" using the state in STATE, a simple-array of 2 double-floats. The\n" +" 64-bit result is returned as 2 32-bit values, with the high 32-bits\n" +" being the first value." msgstr ""
#: src/code/rand-xoroshiro.lisp -msgid "Argument is not a positive integer or a positive float: ~S" +msgid "" +"Generate a uniformly distributed pseudo-random number between zero\n" +" and Arg. State, if supplied, is the random state to use." msgstr ""
#: src/code/rand-xoroshiro.lisp -msgid "" -"Jump the RNG-STATE. This is equivalent to 2^64 calls to the\n" -" xoroshiro128+ generator. It can be used to generate 2^64\n" -" non-overlapping subsequences for parallel computations." +msgid "Argument is not a positive integer or a positive float: ~S" msgstr ""
#: src/code/rand-xoroshiro.lisp
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d7dbff3925edd162a6bc7d6...