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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [test_bench/] [fpAddsub_tb.v] - Blame information for rev 87

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

Line No. Rev Author Line
1 49 robfinch
`timescale 1ns / 1ps
2 32 robfinch
// ============================================================================
3
//        __
4 49 robfinch
//   \\__/ o\    (C) 2006-2020  Robert Finch, Waterloo
5 32 robfinch
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
//      fpAddsub_tb.v
10 49 robfinch
//              - floating point divider test bench
11 32 robfinch
//
12 49 robfinch
// 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 32 robfinch
//                                                                          
38
// ============================================================================
39
 
40 31 robfinch
module fpAddsub_tb();
41
reg rst;
42
reg clk;
43
reg [15:0] adr;
44 49 robfinch
reg [63:0] a,b;
45
wire [63:0] o;
46
reg [63:0] ad,bd;
47
reg [63:0] od;
48
reg [3:0] rm;
49 31 robfinch
 
50 49 robfinch
wire [63:0] doubleA = {a[31], a[30], {3{~a[30]}}, a[29:23], a[22:0], {29{1'b0}}};
51
wire [63:0] doubleB = {b[31], b[30], {3{~b[30]}}, b[29:23], b[22:0], {29{1'b0}}};
52
 
53
integer outfile;
54
 
55 31 robfinch
initial begin
56
        rst = 1'b0;
57
        clk = 1'b0;
58
        adr = 0;
59 49 robfinch
        a = $urandom(1);
60
        b = 1;
61 31 robfinch
        #20 rst = 1;
62
        #50 rst = 0;
63 49 robfinch
        #10000000  $fclose(outfile);
64
        #10 $finish;
65 31 robfinch
end
66
 
67
always #5
68
        clk = ~clk;
69
 
70
reg [7:0] count;
71
always @(posedge clk)
72
if (rst) begin
73
        adr <= 0;
74
        count <= 0;
75
end
76
else
77
begin
78 49 robfinch
  if (adr==0) begin
79
    outfile = $fopen("d:/cores2020/rtf64/v2/rtl/verilog/cpu/fpu/test_bench/fpAddsub_tvo.txt", "wb");
80
    $fwrite(outfile, " rm ------- A ------  ------- B ------  ------ sum -----  -- SIM Sum --\n");
81
  end
82 31 robfinch
        count <= count + 1;
83 49 robfinch
        if (count > 32)
84
                count <= 1'd1;
85
        if (count==2) begin
86
                a[31:0] <= $urandom();
87
                b[31:0] <= $urandom();
88
                a[63:32] <= $urandom();
89
                b[63:32] <= $urandom();
90
                rm <= adr[14:12];
91
                //ad <= memd[adr][63: 0];
92
                //bd <= memd[adr][127:64];
93 31 robfinch
        end
94 49 robfinch
        if (count==31) begin
95
                if (adr[11]) begin
96
                  od = $realtobits($bitstoreal(a) - $bitstoreal(b));
97
                $fwrite(outfile, "%c%h\t%h\t%h\t%h\t%h%c\n", "-",rm, a, b, o, od,od!=o ? "*":" ");
98
          end
99
          else begin
100
                  od = $realtobits($bitstoreal(a) + $bitstoreal(b));
101
                $fwrite(outfile, "%c%h\t%h\t%h\t%h\t%h%c\n", "+",rm, a, b, o, od,od!=o ? "*":" ");
102
          end
103 31 robfinch
                adr <= adr + 1;
104
        end
105
end
106
 
107 49 robfinch
//fpMulnr #(64) u1 (clk, 1'b1, a, b, o, rm);//, sign_exe, inf, overflow, underflow);
108
fpAddsubnr u6 (
109
  .clk(clk),
110
  .ce(1'b1),
111
  .op(adr[11]),
112
  .a(a),
113
  .b(b),
114
  .o(o),
115
  .rm(rm)
116
  );
117 31 robfinch
 
118
endmodule

powered by: WebSVN 2.1.0

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