Raymond Toy pushed to branch master at cmucl / cmucl
Commits: f6daa48c by Raymond Toy at 2024-03-29T13:17:17+00:00 Fix #288: Re-enable deftransform for random integers
- - - - - 1bc97727 by Raymond Toy at 2024-03-29T13:18:30+00:00 Merge branch 'issue-288-re-enable-deftransform-random-int' into 'master'
Fix #288: Re-enable deftransform for random integers
Closes #288
See merge request cmucl/cmucl!198 - - - - -
4 changed files:
- bin/run-ansi-tests.sh - src/compiler/float-tran.lisp - src/i18n/locale/cmucl.pot - tests/rng.lisp
Changes:
===================================== bin/run-ansi-tests.sh ===================================== @@ -41,7 +41,7 @@ else fi
cd ../ansi-test -git checkout cmucl-expected-failures +git checkout issue-288-new-failures
make LISP="$LISP batch -noinit -nositeinit" # There should be no unexpected successes or failures; check these separately
===================================== src/compiler/float-tran.lisp ===================================== @@ -236,7 +236,7 @@ (frob %random-single-float single-float) (frob %random-double-float double-float))
-#-(or new-random random-mt19937 rand-xoroshiro) +#-(or new-random random-mt19937 random-xoroshiro) (deftransform random ((num &optional state) ((integer 1 #.random-fixnum-max) &optional *)) _N"use inline fixnum operations" @@ -259,7 +259,7 @@ '(values (truncate (%random-double-float (coerce num 'double-float) (or state *random-state*)))))
-#+(or random-mt19937) +#+(or random-mt19937 random-xoroshiro) (deftransform random ((num &optional state) ((integer 1 #.(expt 2 32)) &optional *)) _N"use inline (unsigned-byte 32) operations"
===================================== src/i18n/locale/cmucl.pot ===================================== @@ -18997,6 +18997,10 @@ msgstr "" msgid "use inline (unsigned-byte 32) operations" msgstr ""
+#: src/compiler/float-tran.lisp +msgid "Shouldn't happen" +msgstr "" + #: src/compiler/float-tran.lisp msgid "Can't open-code float to rational comparison." msgstr ""
===================================== tests/rng.lisp ===================================== @@ -82,3 +82,27 @@ (assert-equal result (multiple-value-list (64-bit-rng-state *test-state*)))))
+;; Test that the deftransform for random integers is working. +(defun rng-int-trans (state) + (declare (type random-state state) + (optimize (speed 3))) + (random 100000 state)) + +(defun rng-int (n state) + (declare (type random-state state)) + (random n state)) + +(define-test deftransform-random-int + (:tag :issues) + ;; Using the same state, generate a random integer with RNG-INT. + ;; This is the expected value. The generate an integer with + ;; RNG-INT-TRANS. The compiler should have used a deftransform in + ;; this function. The values returned should be the same. + (let ((state (kernel::make-random-object :state (kernel::init-random-state 31415926535)))) + (dotimes (k 2) + (print state) + (assert-equal (rng-int 100000 (make-random-state state)) + (rng-int-trans (make-random-state state))) + ;; Generate a random number to change our state. + (random 100000 state)))) +
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/8ed3d1d3bf250cfe50691eb...