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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpdivr4.v] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2020  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 fpdivr4(clk, ld, a, b, q, r, done, lzcnt);
28
parameter WID1 = 112;
29
localparam REM = WID1 % 2;
30
localparam WID = ((WID1*2)+1)/2;
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 = 1'd0;
37
output reg [WID-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 (WID % 2) begin
43
                $display("fpdvir4: Width must be a multiple of two.");
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 = WID*2/2-1;
58
always @*
59
        b0 = b <= {rxx,q[WID*2-1]};
60
always @*
61
        r1 = b0 ? {rxx,q[WID*2-1]} - b : {rxx,q[WID*2-1]};
62
always @*
63
        b1 = b <= {r1,q[WID*2-2]};
64
always @*
65
        r2 = b1 ? {r1,q[WID*2-2]} - b : {r1,q[WID*2-2]};
66
 
67
reg [2:0] state = 0;
68
always @(posedge clk)
69
begin
70
  if (ld) state <= 3'd1;
71
  case(state)
72
  3'd0: ;
73
  3'd1: if (cnt[8]) state <= 3'd2;
74
  3'd2: state <= 3'd0;
75
  default:  state <= 3'd0;
76
  endcase
77
end
78
 
79
always @(posedge clk)
80
begin
81
done <= 1'b0;
82
case(state)
83
3'd0:   ;
84
3'd1:
85
        if (!cnt[8]) begin
86
                q[WID*2-1:2] <= q[WID*2-3:0];
87
                q[1] <= b0;
88
                q[0] <= b1;
89
                if (!gotnz)
90
                        casez({b0,b1})
91
                        2'b1?:  ;
92
                        2'b01:  lzcnt <= lzcnt + 8'd1;
93
                        2'b00:  lzcnt <= lzcnt + 8'd2;
94
                        endcase
95
                if ({b0,b1} != 2'h0 && !gotnz) begin
96
                        gotnz <= 3'd1;
97
                end
98
        rxx <= r2;
99
                cnt <= cnt - 3'd1;
100
        end
101
3'd2:
102
        begin
103
        r <= r2;
104
        done <= 1'b1;
105
    end
106
default:        ;
107
endcase
108
if (ld) begin
109
        lzcnt <= 0;
110
        gotnz <= 1'b0;
111
        cnt <= {1'b0,maxcnt};
112
        q <= {(a << REM),{WID{1'b0}}};
113
      rxx <= {WID{1'b0}};
114
end
115
end
116
 
117
endmodule
118
 

powered by: WebSVN 2.1.0

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