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

Subversion Repositories ft816float

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

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

Line No. Rev Author Line
1 8 robfinch
// ============================================================================
2
//        __
3 26 robfinch
//   \\__/ o\    (C) 2006-2018  Robert Finch, Waterloo
4 8 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      fpdivr8.v
9 26 robfinch
//      Radix8 doesn't work !!!!
10
//    Radix 2 floating point divider primitive
11 8 robfinch
//
12
//
13
// This source file is free software: you can redistribute it and/or modify 
14
// it under the terms of the GNU Lesser General Public License as published 
15
// by the Free Software Foundation, either version 3 of the License, or     
16
// (at your option) any later version.                                      
17
//                                                                          
18
// This source file is distributed in the hope that it will be useful,      
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
21
// GNU General Public License for more details.                             
22
//                                                                          
23
// You should have received a copy of the GNU General Public License        
24
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
25
//                                                                          
26
// ============================================================================
27
 
28 10 robfinch
module fpdivr8(clk, ld, a, b, q, r, done, lzcnt);
29 8 robfinch
parameter WID = 112;
30 26 robfinch
localparam DMSB = WID-1;
31 8 robfinch
input clk;
32
input ld;
33 26 robfinch
input [WID-1:0] a;
34
input [WID-1:0] b;
35
output reg [WID-1:0] q;
36
output [WID-1:0] r;
37 10 robfinch
output reg done;
38
output reg [7:0] lzcnt;
39 8 robfinch
 
40
 
41
reg [DMSB:0] rxx;
42
reg [8:0] cnt;                           // iteration count
43 10 robfinch
reg [DMSB+1:0] ri = 0;
44 26 robfinch
wire b0,b1,b2,b3;
45 10 robfinch
wire [DMSB+1:0] r1,r2,r3;
46
reg gotnz;
47 8 robfinch
 
48
wire [7:0] maxcnt;
49
wire [2:0] n1;
50 26 robfinch
assign maxcnt = WID/3+1;
51
assign b0 = b < rxx;
52
assign r1 = b0 ? rxx - b : rxx;
53
assign b1 = b < {r1,q[WID-1]};
54
assign r2 = b1 ? {r1,q[WID-1]} - b : {r1,q[WID-1]};
55
assign b2 = b < {r2,q[WID-2]};
56
assign r3 = b2 ? {r2,q[WID-2]} - b : {r2,q[WID-2]};
57
 
58
always @(posedge clk)
59
    if (ld)
60
        rxx <= {WID{1'b0}};
61
    else if (!done)
62
        rxx <= {r3,q[WID-3]};
63
 
64
always @(posedge clk)
65 8 robfinch
begin
66 26 robfinch
        done <= 1'b0;
67
        if (ld) begin
68
                cnt <= maxcnt;
69
        end
70
        else if (cnt != 9'h1FE) begin
71
                cnt <= cnt - 1;
72
                if (cnt==9'h1FF)
73
                        done <= 1'b1;
74
        end
75 8 robfinch
end
76
 
77 26 robfinch
 
78
always @(posedge clk)
79
        if (ld) begin
80
                q <= a;
81 10 robfinch
        end
82 26 robfinch
        else if (!done) begin
83
                q[WID-1:3] <= q[WID-4:0];
84
                q[2] <= b0;
85
                q[1] <= b1;
86
                q[0] <= b2;
87
        end
88
    assign r = r3;
89 8 robfinch
 
90
endmodule
91
 

powered by: WebSVN 2.1.0

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