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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [test_bench/] [df128Toi_tb.sv] - Blame information for rev 67

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

Line No. Rev Author Line
1 62 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      df128Toi_tb.sv
9
//  - test convert decimal floating point to integer
10
//
11
// BSD 3-Clause License
12
// Redistribution and use in source and binary forms, with or without
13
// modification, are permitted provided that the following conditions are met:
14
//
15
// 1. Redistributions of source code must retain the above copyright notice, this
16
//    list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright notice,
19
//    this list of conditions and the following disclaimer in the documentation
20
//    and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the copyright holder nor the names of its
23
//    contributors may be used to endorse or promote products derived from
24
//    this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// ============================================================================
38
 
39 60 robfinch
module df128Toi_tb();
40
 
41
reg rst;
42
reg clk;
43
reg [15:0] adr;
44
reg [127:0] flt;
45
reg [7:0] count;
46
 
47
wire [127:0] bin;
48
wire vf;
49
 
50
integer outfile;
51
 
52
initial begin
53
        rst = 1'b0;
54
        clk = 1'b0;
55
        adr = 0;
56
        flt = $urandom(1);
57
        #20 rst = 1;
58
        #50 rst = 0;
59
        #10000000  $fclose(outfile);
60
        #10 $finish;
61
end
62
 
63
always #5
64
        clk = ~clk;
65
 
66
genvar g;
67
generate begin : gRand
68
        for (g = 0; g < 128; g = g + 4) begin
69
                always @(posedge clk) begin
70
                        if (count==2)
71
                                flt[g+3:g] <= $urandom() % 16;
72
                end
73
        end
74
end
75
endgenerate
76
 
77
always @(posedge clk)
78
if (rst) begin
79
        adr <= 0;
80
        count <= 0;
81
end
82
else
83
begin
84
  if (adr==0) begin
85
    outfile = $fopen("d:/cores2022/rf6809/rtl/dfpu/test_bench/df128Toi_tvo.txt", "wb");
86
    $fwrite(outfile, "s ------ flt ------  ------ bin ------  \n");
87
  end
88
        count <= count + 1;
89
        if (count > 140)
90
                count <= 1'd1;
91 62 robfinch
        if (adr==1) begin
92 64 robfinch
                flt <= 128'h25ffc000000000000000000000000000;   // 1
93 62 robfinch
        end
94 60 robfinch
        if (adr==2) begin
95 64 robfinch
                flt <= 128'h26000000000000000000000000000000;   // 10
96 60 robfinch
        end
97
        if (adr==3) begin
98 64 robfinch
                flt <= 128'h26004000000000000000000000000000;   // 100
99 60 robfinch
        end
100 62 robfinch
        if (adr==4) begin
101 64 robfinch
                flt <= 128'h26008000000000000000000000000000;   // 1000
102 62 robfinch
        end
103 60 robfinch
        if (adr==5) begin
104 64 robfinch
                flt <= 128'h2601934B9C0C00000000000000000000;   // 12345678
105 60 robfinch
        end
106
        if (count==140) begin
107
        $fwrite(outfile, "%c %h\t%h%c\n", adr[11] ? "s" : "u", flt, bin, vf ? "v": " ");
108
                adr <= adr + 1;
109
        end
110
end
111
 
112
df128Toi u6 (
113
        .rst(rst),
114
  .clk(clk),
115
  .ce(1'b1),
116
  .op(adr[11]),
117
  .ld(count==3),
118
  .i(flt),
119
  .o(bin),
120
  .overflow(vf),
121
  .done()
122
);
123
 
124
endmodule

powered by: WebSVN 2.1.0

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