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

Subversion Repositories ft816float

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

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
parameter FPWID1 = 112;
29
localparam REM = FPWID1 % 4;
30
localparam FPWID = ((FPWID1*4)+3)/4;
31
localparam DMSB = FPWID-1;
32
input clk;
33
input ld;
34
input [FPWID-1:0] a;
35
input [FPWID-1:0] b;
36
output reg [FPWID*2-1:0] q = 1'd0;
37
output reg [FPWID-1:0] r = 1'd0;
38
output reg done = 1'd0;
39
output reg [7:0] lzcnt = 1'd0;
40
 
41
initial begin
42
        if (FPWID % 4) begin
43
                $display("fpdvir16: FPWIDth must be a multiple of four.");
44
                $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
assign maxcnt = FPWID*2/4-1;
58
always @*
59
        b0 = b <= {rxx,q[FPWID*2-1]};
60
always @*
61
        r1 = b0 ? {rxx,q[FPWID*2-1]} - b : {rxx,q[FPWID*2-1]};
62
always @*
63
        b1 = b <= {r1,q[FPWID*2-2]};
64
always @*
65
        r2 = b1 ? {r1,q[FPWID*2-2]} - b : {r1,q[FPWID*2-2]};
66
always @*
67
        b2 = b <= {r2,q[FPWID*2-3]};
68
always @*
69
        r3 = b2 ? {r2,q[FPWID*2-3]} - b : {r2,q[FPWID*2-3]};
70
always @*
71
        b3 = b <= {r3,q[FPWID*2-4]};
72
always @*
73
        r4 = b3 ? {r3,q[FPWID*2-4]} - b : {r3,q[FPWID*2-4]};
74
 
75
reg [2:0] state = 0;
76
 
77
always @(posedge clk)
78
begin
79
done <= 1'b0;
80
case(state)
81
3'd0:
82
        if (ld) begin
83
                lzcnt <= 0;
84
                gotnz <= 0;
85
                cnt <= maxcnt;
86
                q <= {(a << REM),{FPWID{1'b0}}};
87
        rxx <= {FPWID{1'b0}};
88
                state <= 1;
89
        end
90
3'd1:
91
        if (!cnt[8]) begin
92
                q[FPWID*2-1:4] <= q[FPWID*2-5:0];
93
                q[3] <= b0;
94
                q[2] <= b1;
95
                q[1] <= b2;
96
                q[0] <= b3;
97
                if (!gotnz)
98
                        casez({b0,b1,b2,b3})
99
                        4'b1???:        ;
100
                        4'b01??:        lzcnt <= lzcnt + 8'd1;
101
                        4'b001?:        lzcnt <= lzcnt + 8'd2;
102
                        4'b0001:        lzcnt <= lzcnt + 8'd3;
103
                        4'b0000:        lzcnt <= lzcnt + 8'd4;
104
                        endcase
105
                if ({b0,b1,b2,b3} != 4'h0 && !gotnz) begin
106
                        gotnz <= 3'd1;
107
                end
108
        rxx <= r4;
109
                cnt <= cnt - 3'd1;
110
        end
111
        else
112
                state <= 3'd2;
113
3'd2:
114
        begin
115
        r <= r4;
116
        done <= 1'b1;
117
        state <= 1'd0;
118
    end
119
default:        state <= 1'd0;
120
endcase
121
end
122
 
123
endmodule
124
 

powered by: WebSVN 2.1.0

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