diff --git a/code/exports.lisp b/code/exports.lisp index d5ea4b30cc835666aeabf4cba8655ce6fe7d0126..4b6cff14d5cab7e0024e15fb15bdeafa0d28615d 100644 --- a/code/exports.lisp +++ b/code/exports.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/exports.lisp,v 1.119 1997/06/03 19:11:26 dtc Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/exports.lisp,v 1.120 1997/06/11 18:32:18 dtc Exp $") ;;; ;;; ********************************************************************** ;;; @@ -1566,7 +1566,7 @@ "CLASS-DIRECT-SUPERCLASSES" "MAKE-LAYOUT" "SIMPLE-STYLE-WARNING" "BYTE-FUNCTION-TYPE" "SLOT-CLASS-PRINT-FUNCTION" "REDEFINE-LAYOUT-WARNING" "SLOT-CLASS" "INSURED-FIND-CLASS" - "CONDITION-FUNCTION-NAME" "RANDOM-CHUNK-MAX")) + "CONDITION-FUNCTION-NAME")) (dolist (name diff --git a/code/rand.lisp b/code/rand.lisp index 2f84eddcedd3f545c5c766bae7c1906cd6295002..80b03fe250bd65774623d6fc36574caac15979bb 100644 --- a/code/rand.lisp +++ b/code/rand.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/rand.lisp,v 1.9 1997/06/05 00:20:52 dtc Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/rand.lisp,v 1.10 1997/06/11 18:32:14 dtc Exp $") ;;; ;;; ********************************************************************** ;;; @@ -239,7 +239,7 @@ #+new-random (in-package "KERNEL") #+new-random -(export '(%random-single-float %random-double-float random-chunk-max)) +(export '(%random-single-float %random-double-float)) #+new-random @@ -479,14 +479,17 @@ ;;;; Random integers: -;;; We generate a random float and extract this many bits from it. The -;;; random integer is created by concatenating a bunch of these -;;; together. 31 has the nice property that Python doesn't have to -;;; box it up, and that Python can optimize the truncate call because -;;; the result is a (signed-byte 32). +;;; Random integers are created by concatenating a bunch of chunks +;;; together. Chunks are generated without consing by truncating a +;;; random float to an integer. With the latest propagate-float-type +;;; code the compiler can inline truncate (signed-byte 32) allowing 31 +;;; bits, and (unsigned-byte 32) 32 bits on the x86. When not using the +;;; propagate-float-type feature the best size that can be inlined is +;;; 29 bits. Use of sizes greater than 29 bits causes consing in +;;; argument passing to generic functions, so 29 bits is a good +;;; default. ;;; (defconstant random-chunk-size 29) -(defconstant random-chunk-max (1- (expt 2 random-chunk-size))) ;;; %RANDOM-INTEGER -- Internal ;;; @@ -497,7 +500,7 @@ (declare (type (integer 1) arg) (type random-state state)) (flet ((random-chunk (state) - (values (truncate (* (float (1+ random-chunk-max) 1d0) + (values (truncate (* (float (expt 2 random-chunk-size) 1d0) (new-random-float state)))))) (let ((shift random-chunk-size)) (do ((bits (random-chunk state) diff --git a/compiler/float-tran.lisp b/compiler/float-tran.lisp index 54d1f6fbffd72a27e808f64db0ac3dba88ca7696..dc1889437c1f68cb432b14594b02335cf2a64756 100644 --- a/compiler/float-tran.lisp +++ b/compiler/float-tran.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/float-tran.lisp,v 1.30 1997/06/03 19:11:29 dtc Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/float-tran.lisp,v 1.31 1997/06/11 18:32:24 dtc Exp $") ;;; ;;; ********************************************************************** ;;; @@ -78,10 +78,20 @@ "use inline fixnum operations" '(rem (random-chunk (or state *random-state*)) num)) +;;; With the latest propagate-float-type code the compiler can inline +;;; truncate (signed-byte 32) allowing 31 bits, and (unsigned-byte 32) +;;; 32 bits on the x86. When not using the propagate-float-type +;;; feature the best size that can be inlined is 29 bits. The choice +;;; shouldn't cause bootstrap problems just slow code. #+new-random (deftransform random ((num &optional state) - ((integer 1 #.random-chunk-max) &optional *)) - "use inline (signed-byte 32) operations" + ((integer 1 + #+(and propagate-float-type x86) #xffffffff + #+(and propagate-float-type (not x86)) #x7fffffff + #-propagate-float-type #.most-positive-fixnum) + &optional *)) + #+x86 "use inline (unsigned-byte 32) operations" + #-x86 "use inline (signed-byte 32) operations" '(values (truncate (%random-double-float (coerce num 'double-float) (or state *random-state*)))))