| 1 |
64 |
robfinch |
`timescale 1ns / 1ps
|
| 2 |
|
|
// ============================================================================
|
| 3 |
|
|
// __
|
| 4 |
|
|
// \\__/ o\ (C) 2006-2022 Robert Finch, Waterloo
|
| 5 |
|
|
// \ __ / All rights reserved.
|
| 6 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
| 7 |
|
|
// ||
|
| 8 |
|
|
//
|
| 9 |
|
|
// DFPMultiply128_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 DFPMultiply128_tb();
|
| 38 |
|
|
parameter N=33;
|
| 39 |
|
|
reg rst;
|
| 40 |
|
|
reg clk;
|
| 41 |
|
|
reg [15:0] adr;
|
| 42 |
|
|
reg [127:0] a,b;
|
| 43 |
|
|
wire [127:0] o;
|
| 44 |
|
|
reg [3:0] rm;
|
| 45 |
|
|
|
| 46 |
|
|
integer n;
|
| 47 |
|
|
reg [127:0] a1, b1;
|
| 48 |
|
|
wire done;
|
| 49 |
|
|
reg ld;
|
| 50 |
|
|
|
| 51 |
|
|
integer outfile;
|
| 52 |
|
|
|
| 53 |
|
|
initial begin
|
| 54 |
|
|
rst = 1'b0;
|
| 55 |
|
|
clk = 1'b0;
|
| 56 |
|
|
adr = 0;
|
| 57 |
|
|
a = $urandom(1);
|
| 58 |
|
|
#20 rst = 1;
|
| 59 |
|
|
#50 rst = 0;
|
| 60 |
|
|
#2000000 $fclose(outfile);
|
| 61 |
|
|
#10 $finish;
|
| 62 |
|
|
end
|
| 63 |
|
|
|
| 64 |
|
|
always #5
|
| 65 |
|
|
clk = ~clk;
|
| 66 |
|
|
|
| 67 |
|
|
genvar g;
|
| 68 |
|
|
generate begin : gRand
|
| 69 |
|
|
for (g = 0; g < N*4+16+4; g = g + 4) begin
|
| 70 |
|
|
always @(posedge clk) begin
|
| 71 |
|
|
a1[g+3:g] <= $urandom() % 16;
|
| 72 |
|
|
b1[g+3:g] <= $urandom() % 16;
|
| 73 |
|
|
end
|
| 74 |
|
|
end
|
| 75 |
|
|
end
|
| 76 |
|
|
endgenerate
|
| 77 |
|
|
|
| 78 |
|
|
reg [9:0] count;
|
| 79 |
|
|
always @(posedge clk)
|
| 80 |
|
|
if (rst) begin
|
| 81 |
|
|
adr <= 0;
|
| 82 |
|
|
count <= 0;
|
| 83 |
|
|
end
|
| 84 |
|
|
else
|
| 85 |
|
|
begin
|
| 86 |
|
|
ld <= 1'b0;
|
| 87 |
|
|
if (adr==0) begin
|
| 88 |
|
|
outfile = $fopen("d:/cores2022/rf6809/rtl/dfpu/test_bench/DFPMultiply128_tvo.txt", "wb");
|
| 89 |
|
|
$fwrite(outfile, "rm ------ A ------ ------- B ------ - DUT Product - - SIM Product -\n");
|
| 90 |
|
|
end
|
| 91 |
|
|
count <= count + 1;
|
| 92 |
|
|
if (count > 750)
|
| 93 |
|
|
count <= 1'd1;
|
| 94 |
|
|
if (count==2) begin
|
| 95 |
|
|
a <= a1;
|
| 96 |
|
|
b <= b1;
|
| 97 |
|
|
rm <= adr[15:13];
|
| 98 |
|
|
ld <= 1'b1;
|
| 99 |
|
|
//ad <= memd[adr][63: 0];
|
| 100 |
|
|
//bd <= memd[adr][127:64];
|
| 101 |
|
|
end
|
| 102 |
|
|
if (adr==1 && count==2) begin
|
| 103 |
|
|
a <= 128'h25ffc000000000000000000000000000; // 1
|
| 104 |
|
|
b <= 128'h25ffc000000000000000000000000000; // 1
|
| 105 |
|
|
end
|
| 106 |
|
|
if (adr==2 && count==2) begin
|
| 107 |
|
|
a <= 128'h26000000000000000000000000000000; // 10
|
| 108 |
|
|
b <= 128'h26000000000000000000000000000000; // 10
|
| 109 |
|
|
end
|
| 110 |
|
|
if (adr==3 && count==2) begin
|
| 111 |
|
|
a <= 128'h26004000000000000000000000000000; // 100
|
| 112 |
|
|
b <= 128'h26004000000000000000000000000000; // 100
|
| 113 |
|
|
end
|
| 114 |
|
|
if (adr==4 && count==2) begin
|
| 115 |
|
|
a <= 128'h26008000000000000000000000000000; // 1000
|
| 116 |
|
|
b <= 128'h26008000000000000000000000000000; // 1000
|
| 117 |
|
|
end
|
| 118 |
|
|
if (adr==5 && count==2) begin
|
| 119 |
|
|
a <= 128'h2601934B9C0C00000000000000000000; // 12345678
|
| 120 |
|
|
b <= 128'h26000000000000000000000000000000; // 10
|
| 121 |
|
|
end
|
| 122 |
|
|
if (adr==6 && count==2) begin
|
| 123 |
|
|
a <= 128'h44000000000000000000000000000000;
|
| 124 |
|
|
b <= 128'h44000000000000000000000000000000;
|
| 125 |
|
|
end
|
| 126 |
|
|
if (adr==7 && count==2) begin
|
| 127 |
|
|
a <= 128'h44004000000000000000000000000000;
|
| 128 |
|
|
b <= 128'h44004000000000000000000000000000;
|
| 129 |
|
|
end
|
| 130 |
|
|
if (count==750) begin
|
| 131 |
|
|
$fwrite(outfile, "%h\t%h\t%h\t%h\n", rm, a, b, o);
|
| 132 |
|
|
adr <= adr + 1;
|
| 133 |
|
|
end
|
| 134 |
|
|
end
|
| 135 |
|
|
|
| 136 |
|
|
//fpMulnr #(64) u1 (clk, 1'b1, a, b, o, rm);//, sign_exe, inf, overflow, underflow);
|
| 137 |
|
|
DFPMultiply128nr u6 (clk, 1'b1, ld, a, b, o, rm, done);//, sign_exe, inf, overflow, underflow);
|
| 138 |
|
|
|
| 139 |
|
|
endmodule
|