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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [fpUnit/] [fpdivr16.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 51 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2018  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 WID1 = 112;
29
localparam REM = WID1 % 4;
30
localparam WID = ((WID1*4)+3)/4;
31
localparam DMSB = WID-1;
32
input clk;
33
input ld;
34
input [WID-1:0] a;
35
input [WID-1:0] b;
36
output reg [WID*2-1:0] q;
37
output reg [WID-1:0] r;
38
output reg done;
39
output reg [7:0] lzcnt;
40
 
41
initial begin
42
        if (WID % 4) begin
43
                $display("fpdvir16: Width must be a multiple of four.");
44
                $finish;
45
        end
46
end
47
 
48
reg [DMSB:0] rxx;
49
reg [8:0] cnt;                           // iteration count
50
reg [DMSB+1:0] ri = 0;
51
wire b0,b1,b2,b3;
52
wire [DMSB+1:0] r1,r2,r3,r4;
53
reg gotnz;
54
 
55
wire [7:0] maxcnt;
56
wire [2:0] n1;
57
assign maxcnt = WID*2/4-1;
58
assign b0 = b <= {rxx,q[WID*2-1]};
59
assign r1 = b0 ? {rxx,q[WID*2-1]} - b : {rxx,q[WID*2-1]};
60
assign b1 = b <= {r1,q[WID*2-2]};
61
assign r2 = b1 ? {r1,q[WID*2-2]} - b : {r1,q[WID*2-2]};
62
assign b2 = b <= {r2,q[WID*2-3]};
63
assign r3 = b2 ? {r2,q[WID*2-3]} - b : {r2,q[WID*2-3]};
64
assign b3 = b <= {r3,q[WID*2-4]};
65
assign r4 = b3 ? {r3,q[WID*2-4]} - b : {r3,q[WID*2-4]};
66
 
67
reg [2:0] state = 0;
68
 
69
always @(posedge clk)
70
begin
71
done <= 1'b0;
72
case(state)
73
3'd0:
74
        if (ld) begin
75
                lzcnt <= 0;
76
                gotnz <= 0;
77
                cnt <= maxcnt;
78
                q <= {(a << REM),{WID{1'b0}}};
79
        rxx <= {WID{1'b0}};
80
                state <= 1;
81
        end
82
3'd1:
83
        if (!cnt[8]) begin
84
                q[WID*2-1:4] <= q[WID*2-5:0];
85
                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 <= 1;
99
                end
100
        rxx <= r4;
101
                cnt <= cnt - 1;
102
        end
103
        else
104
                state <= 2;
105
3'd2:
106
        begin
107
        r <= r4;
108
        done <= 1'b1;
109
        state <= 0;
110
    end
111
default:        state <= 0;
112
endcase
113
end
114
 
115
endmodule
116
 

powered by: WebSVN 2.1.0

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