# HG changeset patch # User Steve Losh # Date 1486862083 0 # Node ID 7781bd17fcdc6f9c5462d5f9f32d03686f9be392 # Parent c6a3ab353556d8a36d17019b89d0dbedec17b0b3 Add a ros file for testing with dieharder diff -r c6a3ab353556 -r 7781bd17fcdc .hgignore --- a/.hgignore Fri Feb 10 23:31:25 2017 +0000 +++ b/.hgignore Sun Feb 12 01:14:43 2017 +0000 @@ -2,3 +2,4 @@ scratch.lisp docs/build +build/pcg diff -r c6a3ab353556 -r 7781bd17fcdc Makefile --- a/Makefile Fri Feb 10 23:31:25 2017 +0000 +++ b/Makefile Sun Feb 12 01:14:43 2017 +0000 @@ -25,3 +25,9 @@ rsync --delete -a ./docs/build/ ~/src/sjl.bitbucket.org/cl-pcg hg -R ~/src/sjl.bitbucket.org commit -Am 'cl-pcg: Update site.' hg -R ~/src/sjl.bitbucket.org push + +# Build ----------------------------------------------------------------------- +lisps := $(shell ffind '\.(asd|lisp|ros)$$') + +build/pcg: $(lisps) + ros build build/pcg.ros diff -r c6a3ab353556 -r 7781bd17fcdc README.markdown --- a/README.markdown Fri Feb 10 23:31:25 2017 +0000 +++ b/README.markdown Sun Feb 12 01:14:43 2017 +0000 @@ -7,3 +7,18 @@ * **Documentation:** * **Mercurial:** * **Git:** + + +Testing with Dieharder +---------------------- + +There's a Roswell script you can use to make a little executable that will spew +random bytes to stdout, suitable for piping into `dieharder`: + +``` +make build/pcg +./build/pcg | dieharder -a -g 200 +``` + +`build/pcg` will dump out infinite random bytes until stdout breaks, so maybe +don't run it in a bare terminal unless you want to just totally hose it. diff -r c6a3ab353556 -r 7781bd17fcdc build/pcg.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build/pcg.ros Sun Feb 12 01:14:43 2017 +0000 @@ -0,0 +1,61 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# + + +(unless (find-package :pcg) + (ql:quickload '(:cl-pcg) :silent t)) + +(require 'sb-rotate-byte) + +(declaim (optimize (debug 0) (safety 0) (speed 3))) + +(let ((*standard-output* (make-broadcast-stream)) ; shut + (*error-output* (make-broadcast-stream))) ; up + (asdf:load-system 'cl-pcg :force t)) + + +(deftype u32 () '(unsigned-byte 32)) +(defconstant +buffer-size+ (* 1 1024)) + +(defun pcg-dump-data () + (with-open-file (out "/dev/stdout" + :direction :output + :if-exists :append + :element-type 'u32) + (loop + :with pcg = (pcg::make-pcg :seed (random (expt 2 32)) :stream-id 0) + :with buffer = (make-array +buffer-size+ + :element-type t + :initial-element 0) + :do (loop :for i :from 0 :below +buffer-size+ + :for n = (pcg::pcg-random% pcg) + :do (setf (aref buffer i) n)) + (write-sequence buffer out)))) + +(defun random-dump-data () + (with-open-file (out "/dev/stdout" + :direction :output + :if-exists :append + :element-type 'u32) + (loop + :with rs = (make-random-state t) + :with buffer = (make-array +buffer-size+ + :element-type 'u32 + :initial-element 0) + :do (loop :for i :from 0 :below +buffer-size+ + :for n = (random (expt 2 32) rs) + :do (setf (aref buffer i) n)) + (write-sequence buffer out)))) + +(defun main (&optional generator &rest argv) + (declare (ignore argv)) + (setf *random-state* (make-random-state t)) + (handler-case + (if (string= generator "random") + (random-dump-data) + (pcg-dump-data)) + (stream-error () t)) + t) diff -r c6a3ab353556 -r 7781bd17fcdc src/pcg.lisp --- a/src/pcg.lisp Fri Feb 10 23:31:25 2017 +0000 +++ b/src/pcg.lisp Sun Feb 12 01:14:43 2017 +0000 @@ -20,10 +20,7 @@ :collect `(check-type ,place ,type)))) -;; Embedded from cl-utilities, with the bugfix of putting the inline declamation -;; FIRST so it'll actually work. -(declaim (inline rotate-byte)) -(defun rotate-byte% (count bytespec integer) +(defun rotate-byte (count bytespec integer) "Rotates a field of bits within INTEGER; specifically, returns an integer that contains the bits of INTEGER rotated COUNT times leftwards within the byte specified by BYTESPEC, and elsewhere @@ -31,7 +28,7 @@ (declare (optimize (speed 3) (safety 0) (space 0) (debug 1))) (let ((size (byte-size bytespec))) (when (= size 0) - (return-from rotate-byte% integer)) + (return-from rotate-byte integer)) (let ((count (mod count size))) (flet ((rotate-byte-from-0 (count size integer) (let ((bytespec (byte size 0))) @@ -44,12 +41,6 @@ bytespec integer))))) -(defun-inline rotate-byte (count bytespec integer) - #+sbcl - (sb-rotate-byte:rotate-byte count bytespec integer) - #-sbcl - (rotate-byte% count bytespec integer)) - (defun-inline % (n) (mod n +modulus+)) @@ -114,7 +105,8 @@ (declare (optimize speed) (type (unsigned-byte 32) data) (type (unsigned-byte 5) selector)) - (rotate-byte selector (byte 32 0) data)) + #+sbcl (sb-rotate-byte:rotate-byte selector (byte 32 0) data) + #-sbcl (rotate-byte selector (byte 32 0) data)) ;;;; State Advancement --------------------------------------------------------