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

Subversion Repositories ft816float

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

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

Line No. Rev Author Line
1 54 robfinch
// ============================================================================
2
//        __
3 65 robfinch
//   \\__/ o\    (C) 2006-2022  Robert Finch, Waterloo
4 54 robfinch
//    \  __ /    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 55 robfinch
reg [7:0] dcnt;                         // digit count
59 54 robfinch
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 robfinch
reg [5:0] digcnt;
65 54 robfinch
 
66 65 robfinch
BCDAdd8NClk #(.N(FPWID/4)) ubcdm1
67 54 robfinch
(
68 65 robfinch
        .clk(clk),
69 54 robfinch
        .a(pi),
70
        .b(bi),
71
        .o(sum),
72 65 robfinch
        .ci(1'b0),
73 54 robfinch
        .co()
74
);
75
 
76 65 robfinch
always_ff @(posedge clk)
77 54 robfinch
begin
78
case(st)
79
ADDN:
80
        begin
81
                clkcnt <= clkcnt + 1'd1;
82
                if (ai[FPWID-1:FPWID-4]!=4'h0) begin
83 65 robfinch
                        if (digcnt=='d0) begin
84
                                pi <= sum;
85
                                digcnt <= 6'd3;
86
                                ai[FPWID-1:FPWID-4] <= ai[FPWID-1:FPWID-4] - 1'd1;
87
                        end
88
                        else
89
                                digcnt <= digcnt - 1'd1;
90 54 robfinch
                end
91
                else begin
92
                        ai <= {ai,4'h0};
93
                        bi <= {4'h0,bi[FPWID*2-1:4]};
94
                        pi <= pi;
95
                        dcnt <= dcnt - 1'd1;
96 65 robfinch
                        if (dcnt=='d0)
97 54 robfinch
                                st <= DONE;
98
                end
99
        end
100
DONE:
101
        begin
102
                p <= pi;
103
                done <= 1'b1;
104
        end
105
default:
106
        st <= ADDN;
107
endcase
108
if (ld) begin
109
        clkcnt <= 10'd0;
110 65 robfinch
        digcnt <= 6'd3;
111 54 robfinch
        dcnt <= (FPWID*2)/4;
112
        pi <= {FPWID*2{1'b0}};
113
        ai <= a;
114
        bi <= {4'h0,b,{FPWID-4{1'b0}}};
115
        st <= ADDN;
116
        done <= 1'b0;
117
end
118
end
119
 
120
endmodule
121
 
122
module dfmul_tb();
123
 
124
reg clk;
125
reg ld;
126
reg [107:0] a, b;
127
wire [215:0] p;
128
 
129
initial begin
130
        clk = 1'b0;
131
        ld = 1'b0;
132
        a = 108'h099_00000000_00000000_00000000;
133
        b = 108'h560_00000000_00000000_00000000;
134
        #20 ld = 1'b1;
135
        #40 ld = 1'b0;
136
end
137
 
138
always #5 clk = ~clk;
139
 
140 55 robfinch
dfmul #(27) u1 (
141 54 robfinch
        .clk(clk),
142
        .ld(ld),
143
        .a(a),
144
        .b(b),
145
        .p(p),
146
        .done(done)
147
);
148
endmodule

powered by: WebSVN 2.1.0

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