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

Subversion Repositories ft816float

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

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
parameter FPWID = 108;
41
parameter RADIX = 10;
42
localparam FPWID1 = FPWID;//((FPWID+2)/3)*3;    // make FPWIDth a multiple of three
43
localparam DMSB = FPWID1-1;
44
input clk;
45
input ld;
46
input [FPWID-1:0] a;
47
input [FPWID-1:0] b;
48
output reg [FPWID*2-1:0] p;
49
output reg done;
50
 
51
 
52
reg [1:0] st;
53
parameter PREP = 2'd0;
54
parameter ADDN = 2'd1;
55
parameter DONE = 2'd2;
56
 
57
reg [3:0] cnt;                          // iteration count
58
reg [5:0] dcnt;                         // digit count
59
reg [9:0] clkcnt;
60
reg [FPWID*2-1:0] pi = 0;
61
reg [FPWID-1:0] ai = 0;
62
reg [FPWID*2-1:0] bi = 0;
63
wire [FPWID*2-1:0] sum;
64
 
65
BCDAddN #(.N((FPWID*2)/4)) u1
66
(
67
        .ci(1'b0),
68
        .a(pi),
69
        .b(bi),
70
        .o(sum),
71
        .co()
72
);
73
 
74
always @(posedge clk)
75
begin
76
case(st)
77
ADDN:
78
        begin
79
                clkcnt <= clkcnt + 1'd1;
80
                if (ai[FPWID-1:FPWID-4]!=4'h0) begin
81
                        pi <= sum;
82
                        ai[FPWID-1:FPWID-4] <= ai[FPWID-1:FPWID-4] - 1'd1;
83
                        cnt <= cnt + 1'd1;
84
                end
85
                else begin
86
                        ai <= {ai,4'h0};
87
                        bi <= {4'h0,bi[FPWID*2-1:4]};
88
                        pi <= pi;
89
                        dcnt <= dcnt - 1'd1;
90
                        if (dcnt==6'd0)
91
                                st <= DONE;
92
                end
93
        end
94
DONE:
95
        begin
96
                p <= pi;
97
                done <= 1'b1;
98
        end
99
default:
100
        st <= ADDN;
101
endcase
102
if (ld) begin
103
        clkcnt <= 10'd0;
104
        cnt <= 4'd0;
105
        dcnt <= (FPWID*2)/4;
106
        pi <= {FPWID*2{1'b0}};
107
        ai <= a;
108
        bi <= {4'h0,b,{FPWID-4{1'b0}}};
109
        st <= ADDN;
110
        done <= 1'b0;
111
end
112
end
113
 
114
endmodule
115
 
116
module dfmul_tb();
117
 
118
reg clk;
119
reg ld;
120
reg [107:0] a, b;
121
wire [215:0] p;
122
 
123
initial begin
124
        clk = 1'b0;
125
        ld = 1'b0;
126
        a = 108'h099_00000000_00000000_00000000;
127
        b = 108'h560_00000000_00000000_00000000;
128
        #20 ld = 1'b1;
129
        #40 ld = 1'b0;
130
end
131
 
132
always #5 clk = ~clk;
133
 
134
dfmul #(108) u1 (
135
        .clk(clk),
136
        .ld(ld),
137
        .a(a),
138
        .b(b),
139
        .p(p),
140
        .done(done)
141
);
142
endmodule

powered by: WebSVN 2.1.0

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