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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [dfmul.sv] - Blame information for rev 59

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

Line No. Rev Author Line
1 54 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2020  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      dfmul.v
9
//    Decimal Float multiplier primitive
10
//
11
// BSD 3-Clause License
12
// Redistribution and use in source and binary forms, with or without
13
// modification, are permitted provided that the following conditions are met:
14
//
15
// 1. Redistributions of source code must retain the above copyright notice, this
16
//    list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright notice,
19
//    this list of conditions and the following disclaimer in the documentation
20
//    and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the copyright holder nor the names of its
23
//    contributors may be used to endorse or promote products derived from
24
//    this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// ============================================================================
38
 
39
module dfmul(clk, ld, a, b, p, done);
40 55 robfinch
parameter N=33;
41
localparam FPWID = N*4;
42 54 robfinch
parameter RADIX = 10;
43
localparam FPWID1 = FPWID;//((FPWID+2)/3)*3;    // make FPWIDth a multiple of three
44
localparam DMSB = FPWID1-1;
45
input clk;
46
input ld;
47
input [FPWID-1:0] a;
48
input [FPWID-1:0] b;
49
output reg [FPWID*2-1:0] p;
50
output reg done;
51
 
52
 
53
reg [1:0] st;
54
parameter PREP = 2'd0;
55
parameter ADDN = 2'd1;
56
parameter DONE = 2'd2;
57
 
58
reg [3:0] cnt;                          // iteration count
59 55 robfinch
reg [7:0] dcnt;                         // digit count
60 54 robfinch
reg [9:0] clkcnt;
61
reg [FPWID*2-1:0] pi = 0;
62
reg [FPWID-1:0] ai = 0;
63
reg [FPWID*2-1:0] bi = 0;
64
wire [FPWID*2-1:0] sum;
65
 
66
BCDAddN #(.N((FPWID*2)/4)) u1
67
(
68
        .ci(1'b0),
69
        .a(pi),
70
        .b(bi),
71
        .o(sum),
72
        .co()
73
);
74
 
75
always @(posedge clk)
76
begin
77
case(st)
78
ADDN:
79
        begin
80
                clkcnt <= clkcnt + 1'd1;
81
                if (ai[FPWID-1:FPWID-4]!=4'h0) begin
82
                        pi <= sum;
83
                        ai[FPWID-1:FPWID-4] <= ai[FPWID-1:FPWID-4] - 1'd1;
84
                        cnt <= cnt + 1'd1;
85
                end
86
                else begin
87
                        ai <= {ai,4'h0};
88
                        bi <= {4'h0,bi[FPWID*2-1:4]};
89
                        pi <= pi;
90
                        dcnt <= dcnt - 1'd1;
91
                        if (dcnt==6'd0)
92
                                st <= DONE;
93
                end
94
        end
95
DONE:
96
        begin
97
                p <= pi;
98
                done <= 1'b1;
99
        end
100
default:
101
        st <= ADDN;
102
endcase
103
if (ld) begin
104
        clkcnt <= 10'd0;
105
        cnt <= 4'd0;
106
        dcnt <= (FPWID*2)/4;
107
        pi <= {FPWID*2{1'b0}};
108
        ai <= a;
109
        bi <= {4'h0,b,{FPWID-4{1'b0}}};
110
        st <= ADDN;
111
        done <= 1'b0;
112
end
113
end
114
 
115
endmodule
116
 
117
module dfmul_tb();
118
 
119
reg clk;
120
reg ld;
121
reg [107:0] a, b;
122
wire [215:0] p;
123
 
124
initial begin
125
        clk = 1'b0;
126
        ld = 1'b0;
127
        a = 108'h099_00000000_00000000_00000000;
128
        b = 108'h560_00000000_00000000_00000000;
129
        #20 ld = 1'b1;
130
        #40 ld = 1'b0;
131
end
132
 
133
always #5 clk = ~clk;
134
 
135 55 robfinch
dfmul #(27) u1 (
136 54 robfinch
        .clk(clk),
137
        .ld(ld),
138
        .a(a),
139
        .b(b),
140
        .p(p),
141
        .done(done)
142
);
143
endmodule

powered by: WebSVN 2.1.0

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