OpenCores
URL https://opencores.org/ocsvn/ft816float/ft816float/trunk

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [test_bench/] [DFPDivide_tb.v] - Blame information for rev 54

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
//      DFPDivider_tb.v
10
//              - decimal floating point divider test bench
11
//
12
// BSD 3-Clause License
13
// Redistribution and use in source and binary forms, with or without
14
// modification, are permitted provided that the following conditions are met:
15
//
16
// 1. Redistributions of source code must retain the above copyright notice, this
17
//    list of conditions and the following disclaimer.
18
//
19
// 2. Redistributions in binary form must reproduce the above copyright notice,
20
//    this list of conditions and the following disclaimer in the documentation
21
//    and/or other materials provided with the distribution.
22
//
23
// 3. Neither the name of the copyright holder nor the names of its
24
//    contributors may be used to endorse or promote products derived from
25
//    this software without specific prior written permission.
26
//
27
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
//                                                                          
39
//      Floating Point Multiplier / Divider
40
//
41
//      This multiplier/divider handles denormalized numbers.
42
//      The output format is of an internal expanded representation
43
//      in preparation to be fed into a normalization unit, then
44
//      rounding. Basically, it's the same as the regular format
45
//      except the mantissa is doubled in size, the leading two
46
//      bits of which are assumed to be whole bits.
47
//
48
//
49
// ============================================================================
50
 
51
module DFPDivide_tb();
52
reg rst;
53
reg clk;
54
reg [15:0] adr;
55
reg [127:0] a,b;
56
wire [127:0] o;
57
reg [127:0] ad,bd;
58
wire [127:0] od;
59
reg [3:0] rm;
60
wire done;
61
 
62
integer n;
63
reg [127:0] a1, b1;
64
reg [39:0] sum_cc;
65
 
66
wire [63:0] doubleA = {a[31], a[30], {3{~a[30]}}, a[29:23], a[22:0], {29{1'b0}}};
67
wire [63:0] doubleB = {b[31], b[30], {3{~b[30]}}, b[29:23], b[22:0], {29{1'b0}}};
68
 
69
integer outfile;
70
 
71
initial begin
72
        rst = 1'b0;
73
        clk = 1'b0;
74
        adr = 0;
75
        a = $urandom(1);
76
        b = 1;
77
        #20 rst = 1;
78
        #50 rst = 0;
79
        #5000000  $fclose(outfile);
80
        #10 $finish;
81
end
82
 
83
always #5
84
        clk = ~clk;
85
 
86
genvar g;
87
generate begin : gRand
88
        for (g = 0; g < 128; g = g + 4) begin
89
                always @(posedge clk) begin
90
                        a1[g+3:g] <= $urandom() % 10;
91
                        b1[g+3:g] <= $urandom() % 10;
92
                end
93
        end
94
end
95
endgenerate
96
 
97
reg [9:0] count;
98
always @(posedge clk)
99
if (rst) begin
100
        adr <= 0;
101
        count <= 0;
102
        sum_cc = 0;
103
end
104
else
105
begin
106
  if (adr==0) begin
107
    outfile = $fopen("d:/cores2020/rtf64/v2/rtl/verilog/cpu/fpu/test_bench/DFPDivide_tvo.txt", "wb");
108
    $fwrite(outfile, "rm ------ A ------  ------- B ------  - DUT Quotient - - SIM Quotient -\n");
109
    sum_cc = 0;
110
  end
111
        count <= count + 1;
112
        if (count > 700)
113
                count <= 1'd1;
114
        if (count==2) begin
115
                a[127:0] <= a1;
116
                b[127:0] <= b1;
117
                a[127:124] <= 4'h5;
118
                b[127:124] <= 4'h5;
119
                rm <= adr[15:13];
120
                //ad <= memd[adr][63: 0];
121
                //bd <= memd[adr][127:64];
122
        end
123
        if (adr==1 && count==2) begin
124
                a <= 127'h50000700000000000000000000000000;
125
                b <= 127'h50000200000000000000000000000000;
126
        end
127
        if (adr==1 && count==2) begin
128
                a <= 127'h50000100000000000000000000000000;
129
                b <= 127'h50000300000000000000000000000000;
130
        end
131
        if (adr==2 && count==2) begin
132
                a <= 127'h50000900000000000000000000000000;
133
                b <= 127'h50000200000000000000000000000000;
134
        end
135
        if (adr==3 && count==2) begin
136
                a <= 127'h50000000000000000000000000000000;
137
                b <= 127'h50000000000000000000000000000000;
138
        end
139
        if (adr==4 && count==2) begin
140
                a <= 127'h50001100000000000000000000000000;
141
                b <= 127'h50001100000000000000000000000000;
142
        end
143
        if (adr==4 && count==2) begin
144
                a <= 127'h50000100000000000000000000000000;
145
                b <= 127'h50000300000000000000000000000000;
146
        end
147
        if (count > 700) begin
148
                sum_cc = sum_cc + u6.u1.u2.clkcnt;
149
          $fwrite(outfile, "%h\t%h\t%h\t%h\t%d\t%f\n", rm, a, b, o, u6.u1.u2.clkcnt, $itor(sum_cc) / $itor(adr));
150
                adr <= adr + 1;
151
        end
152
end
153
 
154
//fpMulnr #(64) u1 (clk, 1'b1, a, b, o, rm);//, sign_exe, inf, overflow, underflow);
155
DFPDividenr u6 (
156
  .rst(rst),
157
  .clk(clk),
158
  .ce(1'b1),
159
  .ld(count==3),
160
  .op(1'b0),
161
  .a(a),
162
  .b(b),
163
  .o(o),
164
  .rm(rm),
165
  .done(done),
166
  .sign_exe(),
167
  .inf(),
168
  .overflow(),
169
  .underflow()
170
  );
171
 
172
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.