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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [fpUnit/] [fpdivr8.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 robfinch
/* ===============================================================
2
        (C) 2006  Robert Finch
3
        All rights reserved.
4
        rob@birdcomputer.ca
5
 
6
        fpdivr8.v
7
                Radix 8 floating point divider primitive
8
 
9
 
10
        This source code is free for use and modification for
11
        non-commercial or evaluation purposes, provided this
12
        copyright statement and disclaimer remains present in
13
        the file.
14
 
15
        If you do modify the code, please state the origin and
16
        note that you have modified the code.
17
 
18
        NO WARRANTY.
19
        THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF
20
        ANY KIND, WHETHER EXPRESS OR IMPLIED. The user must assume
21
        the entire risk of using the Work.
22
 
23
        IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24
        ANY INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES
25
        WHATSOEVER RELATING TO THE USE OF THIS WORK, OR YOUR
26
        RELATIONSHIP WITH THE AUTHOR.
27
 
28
        IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU
29
        TO USE THE WORK IN APPLICATIONS OR SYSTEMS WHERE THE
30
        WORK'S FAILURE TO PERFORM CAN REASONABLY BE EXPECTED
31
        TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN LOSS
32
        OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK,
33
        AND YOU AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS
34
        FROM ANY CLAIMS OR LOSSES RELATING TO SUCH UNAUTHORIZED
35
        USE.
36
 
37
 
38
        Performance
39
        Webpack 7.1i  xc3s1000-4ft256
40
        222 slices / 410 LUTs / 51.5 MHz
41
=============================================================== */
42
 
43
module fpdivr8
44
#(      parameter WID = 24 )
45
(
46
        input clk,
47
        input ld,
48
        input [WID-1:0] a,
49
        input [WID-1:0] b,
50
        output reg [WID*2-1:0] q,
51
        output [WID-1:0] r,
52
        output done
53
);
54
        localparam DMSB = WID-1;
55
 
56
        wire [DMSB:0] rx [2:0];           // remainder holds
57
        reg [DMSB:0] rxx;
58
        reg [5:0] cnt;                           // iteration count
59
        wire [DMSB:0] sdq;
60
        wire [DMSB:0] sdr;
61
        wire sdval;
62
        wire sddbz;
63
 
64
        specialCaseDivider #(WID) u1 (.a(a), .b(b), .q(sdq), .val(sdval), .dbz(sdbz) );
65
 
66
 
67
        assign rx[0] = rxx  [DMSB] ? {rxx  ,q[WID*2-1  ]} + b : {rxx  ,q[WID*2-1  ]} - b;
68
        assign rx[1] = rx[0][DMSB] ? {rx[0],q[WID*2-1-1]} + b : {rx[0],q[WID*2-1-1]} - b;
69
        assign rx[2] = rx[1][DMSB] ? {rx[1],q[WID*2-1-2]} + b : {rx[1],q[WID*2-1-2]} - b;
70
 
71
 
72
        always @(posedge clk)
73
                if (ld)
74
                        cnt <= sdval ? 6'b100000 : WID*2/3;
75
                else if (!done)
76
                        cnt <= cnt - 1;
77
 
78
 
79
        always @(posedge clk)
80
                if (ld)
81
                        rxx <= 0;
82
                else if (!done)
83
                        rxx <= rx[2];
84
 
85
 
86
        always @(posedge clk)
87
                if (ld) begin
88
                        if (sdval)
89
                                q <= {sdq,{WID{1'b0}}};
90
                        else
91
                                q <= {a,{WID{1'b0}}};
92
                end
93
                else if (!done) begin
94
                        q[WID*2-1:3] <= q[WID*2-1-3:0];
95
                        q[0] <= ~rx[2][DMSB];
96
                        q[1] <= ~rx[1][DMSB];
97
                        q[2] <= ~rx[0][DMSB];
98
                end
99
 
100
        // correct remainder
101
        assign r = sdval ? sdr : rx[2][DMSB] ? rx[2] + b : rx[2];
102
        assign done = cnt[5];
103
 
104
endmodule
105
 
106
/*
107
module fpdiv_tb();
108
 
109
        reg rst;
110
        reg clk;
111
        reg ld;
112
        reg [6:0] cnt;
113
 
114
        wire ce = 1'b1;
115
        wire [49:0] a = 50'h0_0000_0400_0000;
116
        wire [23:0] b = 24'd101;
117
        wire [49:0] q;
118
        wire [49:0] r;
119
        wire done;
120
 
121
        initial begin
122
                clk = 1;
123
                rst = 0;
124
                #100 rst = 1;
125
                #100 rst = 0;
126
        end
127
 
128
        always #20 clk = ~clk;  //  25 MHz
129
 
130
        always @(posedge clk)
131
                if (rst)
132
                        cnt <= 0;
133
                else begin
134
                        ld <= 0;
135
                        cnt <= cnt + 1;
136
                        if (cnt == 3)
137
                                ld <= 1;
138
                        $display("ld=%b q=%h r=%h done=%b", ld, q, r, done);
139
                end
140
 
141
 
142
        fpdivr8 divu0(.clk(clk), .ce(ce), .ld(ld), .a(a), .b(b), .q(q), .r(r), .done(done) );
143
 
144
endmodule
145
 
146
*/
147
 

powered by: WebSVN 2.1.0

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