Fix #288: Re-enable deftransform for random integers

When xoroshiro was implemented, we forgot to enable the deftransform for word-sized (or smaller) random integers. Turn this back on.

Add a test for this as well.

Merge request reports

Loading
+1 −1
Changes for bin/run-ansi-tests.sh: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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
+2 −2
Changes for src/compiler/float-tran.lisp: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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"
+4 −0
Changes for src/i18n/locale/cmucl.pot: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -19001,6 +19001,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 ""
+24 −0
Changes for tests/rng.lisp: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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))))
    
Loading