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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [fpUnit/] [fpdivr4.v] - Blame information for rev 55

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

Line No. Rev Author Line
1 51 robfinch
/* ===============================================================
2
        (C) 2006  Robert Finch
3
        All rights reserved.
4
        rob@birdcomputer.ca
5
 
6
        fpdivr4.v
7
                Radix 4 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 8.1i  xc3s1000-4ft256
40
        202 slices / 382 LUTs / 72.5 MHz
41
=============================================================== */
42
 
43
module fpdivr4
44
#(      parameter WID = 24 )
45
(
46
        input clk,
47
        input ce,
48
        input ld,
49
        input [WID-1:0] a,
50
        input [WID-1:0] b,
51
        output reg [WID*2-1:0] q,
52
        output [WID-1:0] r,
53
        output done
54
);
55
        localparam DMSB = WID-1;
56
 
57
        wire [DMSB:0] rx [1:0];           // remainder holds
58
        reg [DMSB:0] rxx;
59
        reg [5:0] cnt;                           // iteration count
60
        wire [DMSB:0] sdq;
61
        wire [DMSB:0] sdr;
62
        wire sdval;
63
        wire sddbz;
64
 
65
        specialDivider #(WID) u1 (.a(a), .b(b), .q(sdq), .r(sdr), .val(sdval), .divByZero(sdbz) );
66
 
67
 
68
        assign rx[0] = rxx  [DMSB] ? {rxx  ,q[WID*2-1  ]} + b : {rxx  ,q[WID*2-1  ]} - b;
69
        assign rx[1] = rx[0][DMSB] ? {rx[0],q[WID*2-1-1]} + b : {rx[0],q[WID*2-1-1]} - b;
70
 
71
 
72
        always @(posedge clk)
73
                if (ce) begin
74
                        if (ld)
75
                                cnt <= sdval ? 0 : WID;
76
                        else if (!done)
77
                                cnt <= cnt - 1;
78
                end
79
 
80
 
81
        always @(posedge clk)
82
                if (ce) begin
83
                        if (ld)
84
                                rxx = 0;
85
                        else if (!done)
86
                                rxx = rx[1];
87
                end
88
 
89
 
90
        always @(posedge clk)
91
                if (ce) begin
92
                        if (ld) begin
93
                                if (sdval)
94
                                        q = {sdq,{WID{1'b0}}};
95
                                else
96
                                        q = {a,{WID{1'b0}}};
97
                        end
98
                        else if (!done) begin
99
                                q[WID*2-1:2] = q[WID*2-1-2:0];
100
                                q[0] = ~rx[1][DMSB];
101
                                q[1] = ~rx[0][DMSB];
102
                        end
103
                end
104
 
105
        // correct remainder
106
        assign r = sdval ? sdr : rx[1][DMSB] ? rx[1] + b : rx[1];
107
        assign done = ~|cnt;
108
 
109
endmodule
110
 
111
/*
112
module fpdiv_tb();
113
 
114
        reg rst;
115
        reg clk;
116
        reg ld;
117
        reg [6:0] cnt;
118
 
119
        wire ce = 1'b1;
120
        wire [49:0] a = 50'h0_0000_0400_0000;
121
        wire [23:0] b = 24'd101;
122
        wire [49:0] q;
123
        wire [49:0] r;
124
        wire done;
125
 
126
        initial begin
127
                clk = 1;
128
                rst = 0;
129
                #100 rst = 1;
130
                #100 rst = 0;
131
        end
132
 
133
        always #20 clk = ~clk;  //  25 MHz
134
 
135
        always @(posedge clk)
136
                if (rst)
137
                        cnt <= 0;
138
                else begin
139
                        ld <= 0;
140
                        cnt <= cnt + 1;
141
                        if (cnt == 3)
142
                                ld <= 1;
143
                        $display("ld=%b q=%h r=%h done=%b", ld, q, r, done);
144
                end
145
 
146
 
147
        fpdivr8 divu0(.clk(clk), .ce(ce), .ld(ld), .a(a), .b(b), .q(q), .r(r), .done(done) );
148
 
149
endmodule
150
 
151
*/
152
 

powered by: WebSVN 2.1.0

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