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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpdivr16.v] - Blame information for rev 30

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

Line No. Rev Author Line
1 29 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2019  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      fpdivr16.v
9
//    Radix 16 floating point divider primitive
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 <http://www.gnu.org/licenses/>.    
24
//                                                                          
25
// ============================================================================
26
 
27
module fpdivr16(clk, ld, a, b, q, r, done, lzcnt);
28 30 robfinch
parameter WID1 = 112;
29
localparam REM = WID1 % 4;
30
localparam WID = ((WID1*4)+3)/4;
31
localparam DMSB = WID-1;
32 29 robfinch
input clk;
33
input ld;
34 30 robfinch
input [WID-1:0] a;
35
input [WID-1:0] b;
36
output reg [WID*2-1:0] q = 1'd0;
37
output reg [WID-1:0] r = 1'd0;
38 29 robfinch
output reg done = 1'd0;
39
output reg [7:0] lzcnt = 1'd0;
40
 
41
initial begin
42 30 robfinch
        if (WID % 4) begin
43
                $display("fpdvir16: Width must be a multiple of four.");
44 29 robfinch
                $finish;
45
        end
46
end
47
 
48
wire [7:0] maxcnt;
49
reg [DMSB:0] rxx = 1'd0;
50
reg [8:0] cnt = 1'd0;                            // iteration count
51
// Simulation didn't like all the wiring.
52
reg [DMSB+1:0] ri = 1'd0;
53
reg b0 = 1'd0,b1 = 1'd0,b2 = 1'd0,b3 = 1'd0;
54
reg [DMSB+1:0] r1 = 1'd0,r2 = 1'd0,r3 = 1'd0,r4 = 1'd0;
55
reg gotnz = 0;
56
 
57 30 robfinch
assign maxcnt = WID*2/4-1;
58 29 robfinch
always @*
59 30 robfinch
        b0 = b <= {rxx,q[WID*2-1]};
60 29 robfinch
always @*
61 30 robfinch
        r1 = b0 ? {rxx,q[WID*2-1]} - b : {rxx,q[WID*2-1]};
62 29 robfinch
always @*
63 30 robfinch
        b1 = b <= {r1,q[WID*2-2]};
64 29 robfinch
always @*
65 30 robfinch
        r2 = b1 ? {r1,q[WID*2-2]} - b : {r1,q[WID*2-2]};
66 29 robfinch
always @*
67 30 robfinch
        b2 = b <= {r2,q[WID*2-3]};
68 29 robfinch
always @*
69 30 robfinch
        r3 = b2 ? {r2,q[WID*2-3]} - b : {r2,q[WID*2-3]};
70 29 robfinch
always @*
71 30 robfinch
        b3 = b <= {r3,q[WID*2-4]};
72 29 robfinch
always @*
73 30 robfinch
        r4 = b3 ? {r3,q[WID*2-4]} - b : {r3,q[WID*2-4]};
74 29 robfinch
 
75
reg [2:0] state = 0;
76
 
77
always @(posedge clk)
78
begin
79
done <= 1'b0;
80
case(state)
81 30 robfinch
3'd0:   ;
82 29 robfinch
3'd1:
83
        if (!cnt[8]) begin
84 30 robfinch
                q[WID*2-1:4] <= q[WID*2-5:0];
85 29 robfinch
                q[3] <= b0;
86
                q[2] <= b1;
87
                q[1] <= b2;
88
                q[0] <= b3;
89
                if (!gotnz)
90
                        casez({b0,b1,b2,b3})
91
                        4'b1???:        ;
92
                        4'b01??:        lzcnt <= lzcnt + 8'd1;
93
                        4'b001?:        lzcnt <= lzcnt + 8'd2;
94
                        4'b0001:        lzcnt <= lzcnt + 8'd3;
95
                        4'b0000:        lzcnt <= lzcnt + 8'd4;
96
                        endcase
97
                if ({b0,b1,b2,b3} != 4'h0 && !gotnz) begin
98
                        gotnz <= 3'd1;
99
                end
100
        rxx <= r4;
101
                cnt <= cnt - 3'd1;
102
        end
103
        else
104
                state <= 3'd2;
105
3'd2:
106
        begin
107
        r <= r4;
108
        done <= 1'b1;
109
        state <= 1'd0;
110
    end
111
default:        state <= 1'd0;
112
endcase
113 30 robfinch
if (ld) begin
114
        lzcnt <= 0;
115
        gotnz <= 1'b0;
116
        cnt <= {1'b0,maxcnt};
117
        q <= {(a << REM),{WID{1'b0}}};
118
      rxx <= {WID{1'b0}};
119
        state <= 3'd1;
120 29 robfinch
end
121 30 robfinch
end
122 29 robfinch
 
123
endmodule
124
 

powered by: WebSVN 2.1.0

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