1 |
54 |
robfinch |
`timescale 1ns / 1ps
|
2 |
|
|
// ============================================================================
|
3 |
|
|
// __
|
4 |
|
|
// \\__/ o\ (C) 2006-2020 Robert Finch, Waterloo
|
5 |
|
|
// \ __ / All rights reserved.
|
6 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
7 |
|
|
// ||
|
8 |
|
|
//
|
9 |
|
|
// DFPMultiply_tb.v
|
10 |
|
|
// - decimal floating point multiplier test bench
|
11 |
|
|
//
|
12 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
13 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
14 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
15 |
|
|
// (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// This source file is distributed in the hope that it will be useful,
|
18 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
|
|
// GNU General Public License for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License
|
23 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
24 |
|
|
//
|
25 |
|
|
// Floating Point Multiplier / Divider
|
26 |
|
|
//
|
27 |
|
|
// This multiplier/divider handles denormalized numbers.
|
28 |
|
|
// The output format is of an internal expanded representation
|
29 |
|
|
// in preparation to be fed into a normalization unit, then
|
30 |
|
|
// rounding. Basically, it's the same as the regular format
|
31 |
|
|
// except the mantissa is doubled in size, the leading two
|
32 |
|
|
// bits of which are assumed to be whole bits.
|
33 |
|
|
//
|
34 |
|
|
//
|
35 |
|
|
// ============================================================================
|
36 |
|
|
|
37 |
|
|
module DFPMultiply_tb();
|
38 |
|
|
reg rst;
|
39 |
|
|
reg clk;
|
40 |
|
|
reg [15:0] adr;
|
41 |
|
|
reg [127:0] a,b;
|
42 |
|
|
wire [127:0] o;
|
43 |
|
|
reg [127:0] ad,bd;
|
44 |
|
|
wire [127:0] od;
|
45 |
|
|
reg [3:0] rm;
|
46 |
|
|
|
47 |
|
|
integer n;
|
48 |
|
|
reg [127:0] a1, b1;
|
49 |
|
|
wire [63:0] doubleA = {a[31], a[30], {3{~a[30]}}, a[29:23], a[22:0], {29{1'b0}}};
|
50 |
|
|
wire [63:0] doubleB = {b[31], b[30], {3{~b[30]}}, b[29:23], b[22:0], {29{1'b0}}};
|
51 |
|
|
wire done;
|
52 |
|
|
reg ld;
|
53 |
|
|
|
54 |
|
|
integer outfile;
|
55 |
|
|
|
56 |
|
|
initial begin
|
57 |
|
|
rst = 1'b0;
|
58 |
|
|
clk = 1'b0;
|
59 |
|
|
adr = 0;
|
60 |
|
|
a = $urandom(1);
|
61 |
|
|
#20 rst = 1;
|
62 |
|
|
#50 rst = 0;
|
63 |
|
|
#1000000 $fclose(outfile);
|
64 |
|
|
#10 $finish;
|
65 |
|
|
end
|
66 |
|
|
|
67 |
|
|
always #5
|
68 |
|
|
clk = ~clk;
|
69 |
|
|
|
70 |
|
|
genvar g;
|
71 |
|
|
generate begin : gRand
|
72 |
|
|
for (g = 0; g < 128; g = g + 4) begin
|
73 |
|
|
always @(posedge clk) begin
|
74 |
|
|
a1[g+3:g] <= $urandom() % 10;
|
75 |
|
|
b1[g+3:g] <= $urandom() % 10;
|
76 |
|
|
end
|
77 |
|
|
end
|
78 |
|
|
end
|
79 |
|
|
endgenerate
|
80 |
|
|
|
81 |
|
|
reg [9:0] count;
|
82 |
|
|
always @(posedge clk)
|
83 |
|
|
if (rst) begin
|
84 |
|
|
adr <= 0;
|
85 |
|
|
count <= 0;
|
86 |
|
|
end
|
87 |
|
|
else
|
88 |
|
|
begin
|
89 |
|
|
ld <= 1'b0;
|
90 |
|
|
if (adr==0) begin
|
91 |
|
|
outfile = $fopen("d:/cores2020/rtf64/v2/rtl/verilog/cpu/fpu/test_bench/DFPMultiply_tvo.txt", "wb");
|
92 |
|
|
$fwrite(outfile, "rm ------ A ------ ------- B ------ - DUT Product - - SIM Product -\n");
|
93 |
|
|
end
|
94 |
|
|
count <= count + 1;
|
95 |
|
|
if (count > 600)
|
96 |
|
|
count <= 1'd1;
|
97 |
|
|
if (count==2) begin
|
98 |
|
|
a[127:0] <= a1;
|
99 |
|
|
b[127:0] <= b1;
|
100 |
|
|
a[127:124] <= 4'h5;
|
101 |
|
|
b[127:124] <= 4'h5;
|
102 |
|
|
ld <= 1'b1;
|
103 |
|
|
rm <= adr[15:13];
|
104 |
|
|
//ad <= memd[adr][63: 0];
|
105 |
|
|
//bd <= memd[adr][127:64];
|
106 |
|
|
end
|
107 |
|
|
if (adr==1 && count==2) begin
|
108 |
|
|
a <= 127'h50000700000000000000000000000000;
|
109 |
|
|
b <= 127'h50000200000000000000000000000000;
|
110 |
|
|
end
|
111 |
|
|
if (adr==1 && count==2) begin
|
112 |
|
|
a <= 127'h40001333333333333333333333333333;
|
113 |
|
|
b <= 127'h50000300000000000000000000000000;
|
114 |
|
|
end
|
115 |
|
|
if (adr==2 && count==2) begin
|
116 |
|
|
a <= 127'h50000900000000000000000000000000;
|
117 |
|
|
b <= 127'h50000200000000000000000000000000;
|
118 |
|
|
end
|
119 |
|
|
if (adr==3 && count==2) begin
|
120 |
|
|
a <= 127'h50000000000000000000000000000000;
|
121 |
|
|
b <= 127'h50000000000000000000000000000000;
|
122 |
|
|
end
|
123 |
|
|
if (adr==4 && count==2) begin
|
124 |
|
|
a <= 127'h50001100000000000000000000000000;
|
125 |
|
|
b <= 127'h50001100000000000000000000000000;
|
126 |
|
|
end
|
127 |
|
|
if (count==600) begin
|
128 |
|
|
$fwrite(outfile, "%h\t%h\t%h\t%h\n", rm, a, b, o);
|
129 |
|
|
adr <= adr + 1;
|
130 |
|
|
end
|
131 |
|
|
end
|
132 |
|
|
|
133 |
|
|
//fpMulnr #(64) u1 (clk, 1'b1, a, b, o, rm);//, sign_exe, inf, overflow, underflow);
|
134 |
|
|
DFPMultiplynr u6 (clk, 1'b1, ld, a, b, o, rm, done);//, sign_exe, inf, overflow, underflow);
|
135 |
|
|
|
136 |
|
|
endmodule
|