-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFP_Div_Test.sv
151 lines (120 loc) · 3.57 KB
/
FP_Div_Test.sv
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 04/12/2022 05:13:45 PM
// Design Name:
// Module Name: FP_Div_Test
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module booth_test;
reg [31:0] A, B;
wire DONE;
wire [31:0] result;
shortreal value;
shortreal valueA, valueB;
real EPSILON=0.00001;
real error;
integer i, fail=0, pass=0, Spass=0, Sfail=0;
fpdiv tester( result, A, B);
initial
begin
// CORNER CASES 0/1
A = 32'h0; // 0.0
B = 32'h1; // 1.0
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : %f got : %f",valueA,valueB,valueA/valueB,value);
// CORNER CASES 1/0
A = 32'h3F800000; // 1.0
B = 32'h0; // 0.0
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : %f got : %f",valueA,valueB,valueA/valueB,value);
// CORNER CASES 0/0
A = 32'h0; // 0.0
B = 32'h0; // 0.0
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : %f got : %f",valueA,valueB,valueA/valueB,value);
// CORNER CASES 1/inf
A = 32'h3F800000; // 1.0
B = 32'h7F800000;
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : %f got : %f",valueA,valueB,valueA/valueB,value);
// SPECIAL TEST PATTERNS
// CORNER CASES +inf/negative
A = 32'h7F800000; // +inf
B = 32'h85634992; // any negative
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : -inf got : %f",valueA,valueB,value);
// CORNER CASES 0.0/something
A = 32'h0; // zero
B = 32'h85634992; // something
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : %f, got : %f",valueA,valueB,valueA/valueB,value);
// CORNER CASES inf/zero
A = 32'h7F800000; // +inf
B = 32'h0; // 0.0
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : inf, got : %f",valueA,valueB,value);
// CORNER CASES NaN/something
A = 32'h7FC00000; // NaN
B = 32'h85634993; // something
#15
value =$bitstoshortreal(result);
valueA = $bitstoshortreal(A);
valueB = $bitstoshortreal(B);
$display("Special Case For A = %f and B = %f, expected : nan, got : %f",valueA,valueB,value);
// GENRAL CASES
for(i =0 ; i < 500; i=i+1) begin
#100
valueA = $random;
valueB = $random;
A =$shortrealtobits(valueA);
B =$shortrealtobits(valueB);
#15
value =$bitstoshortreal(result);
error = (value - (valueA/valueB));
error = error<0 ? -error : error;
if( error < EPSILON ) begin
$display("Passed for A = %f and B = %f, expected : %f got : %f",valueA,valueB,valueA/valueB,value);
pass = pass + 1;
end
else begin
$display("Failed for A = %f and B = %f, expected : %f got : %f",valueA,valueB,valueA/valueB,value);
fail = fail + 1;
end
end
$display("No. of Passes = %f and No. of Fails = %f",pass,fail);
end
endmodule