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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [test_bench/] [fpRsqrte_tb.sv] - Blame information for rev 39

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

Line No. Rev Author Line
1 17 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2019  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      fpRsqrte_tb.v
9
//              - test reciprocal square root estimate
10
//
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 .
24
//
25
//
26
// This module returns the sigmoid of a number using a lookup table.
27
// -1.0 or +1.0 is returned for entries outside of the range -8.0 to +8.0
28
//
29
//
30
// ============================================================================
31
 
32
module fpRsqrte_tb();
33
reg clk, rst;
34
reg [12:0] ndx;
35
wire [31:0] o;
36
 
37
reg [5:0] cnt;
38
reg [63:0] mem [0:8191];
39
reg [63:0] memo [0:8191];
40
reg ld;
41
 
42
initial begin
43
  #0 rst = 1'b0;
44
  #0 clk = 1'b0;
45
        $readmemh("d:/cores6/rtfItanium/v1/rtl/fpUnit/test_bench/fpRsqrte_tv.txt", mem);
46
  #10 rst = 1'b1;
47
  #40 rst = 1'b0;
48
end
49
 
50
always #5 clk = ~clk;
51
 
52
wire [31:0] a = mem[ndx][31:0];
53
wire [79:0] a1, o3;
54
F32ToF80 u2 (a, a1);
55
fpRsqrte #(80) u1 (clk, 1'b1, ld, a1, o3);
56
F80ToF32 u3 (o3, o);
57
 
58
always @(posedge clk)
59
if (rst)
60
  cnt = 0;
61
else begin
62
  cnt = cnt + 2'd1;
63
end
64
always @(posedge clk)
65
if (rst)
66
  ndx = 0;
67
else begin
68
        ld <= 1'b0;
69
        if (cnt==6'd0)
70
                ld <= 1'b1;
71
        if (cnt==6'd63) begin
72
                memo[ndx] <= {o,a};
73
        ndx = ndx + 2'd1;
74
  end
75
        if (ndx==8191) begin
76
                $writememh("d:/cores6/rtfItanium/v1/rtl/fpUnit/test_bench/fpRsqrte_tvo.txt", memo);
77
                $finish;
78
        end
79
end
80
 
81
wire [31:0] o1, o2;
82
// Multiply number by 4096 (it is in range -1 to 1) then convert to integer
83
assign o1[22:0] = o[22:0];
84
assign o1[30:23] = o[30:23] + 8'd12; // we know this won't overflow
85
assign o1[31] = o[31];
86
 
87
f2i #(32) u4
88
(
89
  .clk(clk),
90
  .ce(1'b1),
91
  .i(o1),
92
  .o(o2)
93
);
94
 
95
endmodule

powered by: WebSVN 2.1.0

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