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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog/] [fpdivr2.v] - Blame information for rev 8

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

Line No. Rev Author Line
1 6 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2016  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// This source file is free software: you can redistribute it and/or modify 
9
// it under the terms of the GNU Lesser General Public License as published 
10
// by the Free Software Foundation, either version 3 of the License, or     
11
// (at your option) any later version.                                      
12
//                                                                          
13
// This source file is distributed in the hope that it will be useful,      
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
16
// GNU General Public License for more details.                             
17
//                                                                          
18
// You should have received a copy of the GNU General Public License        
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
20
//
21
//      fpdivr2.v
22
//  Radix 2 floating point divider primitive
23
//      
24
// ============================================================================
25
//
26
module fpdivr2
27
#(      parameter WID = 24 )
28
(
29
        input clk,
30
        input ld,
31
        input [WID-1:0] a,
32
        input [WID-1:0] b,
33
        output reg [WID*2-1:0] q,
34
        output [WID-1:0] r,
35
        output done
36
);
37
        localparam DMSB = WID-1;
38
 
39
        reg [DMSB:0] rx [2:0];            // remainder holds
40
        reg [DMSB:0] rxx;
41
        reg [7:0] cnt;                           // iteration count
42
        wire [DMSB:0] sdq;
43
        wire [DMSB:0] sdr;
44
        wire sdval = 1'b0;
45
        wire sdbz;
46
  reg willGo0;
47
 
48
        //specialCaseDivider #(WID) u1 (.a(a), .b(b), .q(sdq), .r(sdr), .val(sdval), .dbz(sdbz) );
49
 
50
  initial begin
51
    rx[0] = 0;
52
  end
53
 
54
        always @(posedge clk)
55
                if (ld)
56
                        cnt <= sdval ? 8'b10000000 : WID*2-2;
57
                else if (!done)
58
                        cnt <= cnt - 1;
59
 
60
 
61
        always @(posedge clk)
62
                if (ld) begin
63
                        rxx <= 0;
64
                        if (sdval)
65
                                q <= {sdq,{WID{1'b0}}};
66
                        else
67
                                q <= {a,{WID{1'b0}}};
68
                end
69
                else if (!done) begin
70
                  willGo0 = {rxx  ,q[WID*2-1  ]} > b;
71
      rx[0] = willGo0 ? {rxx  ,q[WID*2-1  ]} - b : {rxx  ,q[WID*2-1  ]};
72
                        q[WID*2-1:1] <= q[WID*2-1-1:0];
73
                        q[0] <= willGo0;
74
                        rxx <= rx[0];
75
                end
76
 
77
        // correct remainder
78
        assign r = sdval ? sdr : rx[2][DMSB] ? rx[2] + b : rx[2];
79
        assign done = cnt[7];
80
 
81
endmodule
82
 
83
/*
84
module fpdivr2_tb();
85
 
86
        reg rst;
87
        reg clk;
88
        reg ld;
89
        reg [6:0] cnt;
90
 
91
        wire ce = 1'b1;
92
        wire [23:0] a = 24'h0_4000;
93
        wire [23:0] b = 24'd101;
94
        wire [45:0] q;
95
        wire [23:0] r;
96
        wire done;
97
 
98
        initial begin
99
                clk = 1;
100
                rst = 0;
101
                #100 rst = 1;
102
                #100 rst = 0;
103
        end
104
 
105
        always #20 clk = ~clk;  //  25 MHz
106
 
107
        always @(posedge clk)
108
                if (rst)
109
                        cnt <= 0;
110
                else begin
111
                        ld <= 0;
112
                        cnt <= cnt + 1;
113
                        if (cnt == 3)
114
                                ld <= 1;
115
                        $display("ld=%b q=%h r=%h done=%b", ld, q, r, done);
116
                end
117
 
118
 
119
        fpdivr2 #(24) divu0(.clk(clk), .ld(ld), .a(a), .b(b), .q(q), .r(r), .done(done) );
120
 
121
endmodule
122
*/
123
 
124
 

powered by: WebSVN 2.1.0

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