-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxMullerTb.bsv
More file actions
130 lines (93 loc) · 3.83 KB
/
BoxMullerTb.bsv
File metadata and controls
130 lines (93 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package BoxMullerTb;
// Bluespec standard packages.
import StmtFSM::*;
// My packages.
import FixedPoint::*;
import FIFO::*;
import RandomNumberGenerator::*;
import BoxMullerInterface::*;
import InterfaceLogTableFxdP::*;
import WellPRNG::*;
import BoxMuller::*;
import LogTableFxdP::*;
import Complex::*;
import AirblueCommon::*;
import AirblueTypes::*;
import SquareRoot::*;
import ClientServer::*;
import FIFOF::*;
import GetPut::*;
import UnitAppendList :: * ;
import BUtils::*;
import Assert::*;
//`define isDebug True // uncomment this line to display error
`define cordicIters 16 // no. iterations cordic performs before giving result
`define cordicItersPerStage 8 // no. pipeline iters per stages
typedef FixedPoint#(32,32) SqrtTFx;
// Expoents for the number of outputs to be generated (2^N).
typedef 30 N_DEFAULT; // For fast human conference.
typedef 31 N_SMALL_CRUSH; // TestU01 Small Crush Battery. Empirically determined.
typedef 41 N_CRUSH; // TestU01 Crush Battery. TestU01 user guide fails! Empirically determined.
typedef 62 N_BIG_CRUSH; // TestU01 Big Crush Battery. TestU01 user guide fails!
typedef 34 N_DIEHARD; // Marsaglia's DIEHARD. Empirically determined.
typedef 10 N_NIST; // NIST test. Empirically determined.
typedef 5 VIZUAL;
typedef FixedPoint#(33,32) SqrtTFx33;
(* synthesize *)
module mkBoxMullerTb (Empty);
// Expoent of the number of outputs to be generated (2^N).
Reg#(UInt#(32)) n <- mkReg (fromInteger (valueOf (N_DEFAULT)));
// Output counter.
Reg#(UInt#(64)) i <- mkReg (0);
Reg#(SqrtTFx) _ii <- mkReg (0);
Reg#(TupleUInt32) tup <- mkRegU;
Reg#(int) cont <- mkReg (0);
IfcBoxMullerInterface#(Int32WORD, TupleUInt32, SqrtTFx) boxmuller <- mkBoxMuller();
InterfaceLogTableFxdP#(SqrtTFx33,SqrtTFx33) mLUT <- mkLogTableFxdP();
Reg#(SqrtTFx33) uniform_rand_num <- mkReg(0);
Reg#(SqrtTFx33) fixCounter <- mkReg(0);
Stmt verify_stmt =
seq
// Get TestU01 test type and set N.
action
n <= fromInteger (valueOf (VIZUAL));
endaction
action
boxmuller.initialize (fromInteger(0), fromInteger(56249));
endaction
$display("#==================================================================");
while (i < (1 << n)) seq
action
_ii <= fromInt(cont)*fromInt(cont);
endaction
boxmuller.run(_ii);
boxmuller.run(0);
action
let temptup <- boxmuller.get();
tup <= temptup;
endaction
$display("*", $time);
action
Int32WORD v = tpl_1(tup);
uniform_rand_num <= (0.000000000232830643653869628906)* fromUInt(unpack(v));
endaction
mLUT.run(uniform_rand_num);
mLUT.run(0);
action
let logv <- mLUT.get();
// $display("# -");fxptWrite( 10, uniform_rand_num ) ; $display("" );
$display("! -");fxptWrite( 10, uniform_rand_num ) ; $display("" );
$display("! -");fxptWrite( 10, logv ) ; $display("" );
$display("### ", fshow(uniform_rand_num) , " ###\n");
$display("### ", fshow(logv) , " ###\n");
endaction
action
i <= i + 1;
cont <= cont +1;
fixCounter <= fixCounter + 0.0625;
endaction
endseq
endseq;
mkAutoFSM (verify_stmt);
endmodule: mkBoxMullerTb
endpackage: BoxMullerTb