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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog/] [fpdivr8.v] - Blame information for rev 16

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

Line No. Rev Author Line
1 8 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2016  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      fpdivr8.v
9
//    Radix 8 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 10 robfinch
module fpdivr8(clk, ld, a, b, q, r, done, lzcnt);
28 8 robfinch
parameter WID = 112;
29
parameter RADIX = 8;
30
localparam WID1 = WID;//((WID+2)/3)*3;    // make width a multiple of three
31
localparam DMSB = WID1-1;
32
input clk;
33
input ld;
34
input [WID1-1:0] a;
35
input [WID1-1:0] b;
36
output reg [WID1*2-1:0] q;
37
output [WID1-1:0] r;
38 10 robfinch
output reg done;
39
output reg [7:0] lzcnt;
40 8 robfinch
 
41
 
42
wire [DMSB:0] rx [2:0];           // remainder holds
43
reg [DMSB:0] rxx;
44
reg [8:0] cnt;                           // iteration count
45
wire [DMSB:0] sdq;
46
wire [DMSB:0] sdr;
47
wire sdval;
48
wire sddbz;
49 10 robfinch
reg [DMSB+1:0] ri = 0;
50 8 robfinch
wire b0,b1,b2;
51 10 robfinch
wire [DMSB+1:0] r1,r2,r3;
52
reg gotnz;
53 8 robfinch
 
54
specialCaseDivider #(WID1) u1 (.a(a), .b(b), .q(sdq), .val(sdval), .dbz(sdbz) );
55
 
56
wire [7:0] maxcnt;
57
wire [2:0] n1;
58
generate
59
begin
60
if (RADIX==8) begin
61
    assign maxcnt = WID1*2/3+1;
62
    assign b0 = b < rxx;
63
    assign r1 = b0 ? rxx - b : rxx;
64
    assign b1 = b < {r1,q[WID*2-1]};
65
    assign r2 = b1 ? {r1,q[WID*2-1]} - b : {r1,q[WID*2-1]};
66
    assign b2 = b < {r2,q[WID*2-1-1]};
67
    assign r3 = b2 ? {r2,q[WID*2-1-1]} - b : {r2,q[WID*2-1-1]};
68
    assign n1 = 2;
69
        always @(posedge clk)
70
        if (ld)
71
            rxx <= 0;
72
        else if (!done)
73
            rxx <= {r3,q[WID*2-1]};
74
end
75
else if (RADIX==2) begin
76
    assign b0 = b <= ri;
77
    assign r1 = b0 ? ri - b : ri;
78 10 robfinch
    assign maxcnt = WID1*2-1;
79 8 robfinch
    assign n1 = 0;
80
//      assign rx[0] = rxx  [DMSB] ? {rxx  ,q[WID*2-1  ]} + b : {rxx  ,q[WID*2-1  ]} - b;
81
end
82
end
83
endgenerate
84
 
85
        always @(posedge clk)
86 10 robfinch
        begin
87
                done <= 1'b0;
88
                if (ld) begin
89
                        cnt <= sdval ? 9'h1FE : maxcnt;
90
                        done <= sdval;
91
                end
92
                else if (cnt != 9'h1FE) begin
93 8 robfinch
                        cnt <= cnt - 1;
94 10 robfinch
                        if (cnt==9'h1FF)
95
                                done <= 1'b1;
96
                end
97
        end
98 8 robfinch
 
99
 
100
generate
101
begin
102
if (RADIX==8) begin
103
        always @(posedge clk)
104
                if (ld) begin
105 10 robfinch
                        gotnz <= 1'b0;
106
                        lzcnt <= 8'h00;
107 8 robfinch
                        if (sdval)
108
                                q <= {3'b0,sdq,{WID1{1'b0}}};
109
                        else
110
                                q <= {3'b0,a,{WID1{1'b0}}};
111
                end
112
                else if (!done) begin
113
                        q[WID1-1:3] <= q[WID1-1-3:0];
114
                        q[0] <= b0;
115
                        q[1] <= b1;
116
                        q[2] <= b2;
117
                end
118
        // correct remainder
119
        assign r = sdval ? sdr : r3;
120
end
121
if (RADIX==2) begin
122
        always @(posedge clk)
123
    if (ld) begin
124 10 robfinch
                gotnz <= 1'b0;
125
                lzcnt <= 8'h00;
126 8 robfinch
        ri <= 0;
127
        if (sdval)
128
            q <= {3'b0,sdq,{WID1{1'b0}}};
129
        else
130
            q <= {3'b0,a,{WID1{1'b0}}};
131
    end
132 10 robfinch
    else if (cnt!=9'h1FE) begin
133
        if (b0)
134
                gotnz <= 1'b1;
135
        if (b0==0 && !gotnz)
136
                lzcnt <= lzcnt + 8'd1;
137 8 robfinch
        q[WID1*2-1:1] <= q[WID1*2-1-1:0];
138
        q[0] <= b0;
139
        ri <= {r1[DMSB:0],q[WID1*2-1]};
140
    end
141
        // correct remainder
142
    assign r = sdval ? sdr : ri;
143
end
144
end
145
endgenerate
146
 
147
endmodule
148
 
149
 

powered by: WebSVN 2.1.0

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