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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [common/] [FT64_multiplier.v] - Blame information for rev 66

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

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2013-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// This source file is free software: you can redistribute it and/or modify 
9
// it under the terms of the GNU Lesser General Public License as published 
10
// by the Free Software Foundation, either version 3 of the License, or     
11
// (at your option) any later version.                                      
12
//                                                                          
13
// This source file is distributed in the hope that it will be useful,      
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
16
// GNU General Public License for more details.                             
17
//                                                                          
18
// You should have received a copy of the GNU General Public License        
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
20
//
21
//
22
// FT64 Superscaler
23
// FT64_multiplier.v
24
//  - 64 bit multiplier
25
//
26
// ============================================================================
27
//
28
module FT64_multiplier(rst, clk, ld, abort, sgn, sgnus, a, b, o, done, idle);
29
parameter WID=64;
30
parameter SGNADJO=3'd2;
31
parameter MULT=3'd3;
32
parameter IDLE=3'd4;
33
parameter DONE=3'd5;
34
input clk;
35
input rst;
36
input ld;
37
input abort;
38
input sgn;
39
input sgnus;
40
input [WID-1:0] a;
41
input [WID-1:0] b;
42
output [WID*2-1:0] o;
43
reg [WID*2-1:0] o;
44
output done;
45
output idle;
46
 
47
reg [WID-1:0] aa,bb;
48
reg so;
49
reg [2:0] state;
50
reg [7:0] cnt;
51
wire cnt_done = cnt==8'd0;
52
assign done = state==DONE || (state==IDLE && !ld); // State == DONE
53
assign idle = state==IDLE;
54
 
55
wire [127:0] pp;
56
 
57
generate begin : gMults
58
if (WID > 32) begin
59
FT64_mult umul1
60
(
61
  .CLK(clk),  // input wire CLK
62
  .A(aa),      // input wire [63 : 0] A
63
  .B(bb),      // input wire [63 : 0] B
64
  .P(pp)      // output wire [127 : 0] P
65
);
66
end
67
else if (WID > 16) begin
68
FT64_mult32 umul1
69
(
70
  .CLK(clk),  // input wire CLK
71
  .A(aa),      // input wire [63 : 0] A
72
  .B(bb),      // input wire [63 : 0] B
73
  .P(pp)      // output wire [127 : 0] P
74
);
75
end
76
else if (WID > 8) begin
77
FT64_mult16 umul1
78
(
79
  .CLK(clk),  // input wire CLK
80
  .A(aa),      // input wire [63 : 0] A
81
  .B(bb),      // input wire [63 : 0] B
82
  .P(pp)      // output wire [127 : 0] P
83
);
84
end
85
else begin
86
FT64_mult8 umul1
87
(
88
  .CLK(clk),  // input wire CLK
89
  .A(aa),      // input wire [63 : 0] A
90
  .B(bb),      // input wire [63 : 0] B
91
  .P(pp)      // output wire [127 : 0] P
92
);
93
end
94
end
95
endgenerate
96
 
97
always @(posedge clk)
98
if (rst) begin
99
        aa <= {WID{1'b0}};
100
        bb <= {WID{1'b0}};
101
        o <= {WID*2{1'b0}};
102
        state <= IDLE;
103
end
104
else
105
begin
106
if (abort)
107
  cnt <= 8'd00;
108
else if (!cnt_done)
109
        cnt <= cnt - 8'd1;
110
 
111
case(state)
112
IDLE:
113
        if (ld) begin
114
          if (sgnus) begin
115
                        aa <= a[WID-1] ? -a : a;
116
                        bb <= b;
117
                        so = a[WID-1];
118
          end
119
                else if (sgn) begin
120
                        aa <= a[WID-1] ? -a : a;
121
                        bb <= b[WID-1] ? -b : b;
122
                        so <= a[WID-1] ^ b[WID-1];
123
                end
124
                else begin
125
                        aa <= a;
126
                        bb <= b;
127
                        so <= 1'b0;
128
                end
129
                cnt <= 8'd20;
130
                state <= MULT;
131
        end
132
MULT:
133
        if (cnt_done) begin
134
                if (sgn|sgnus) begin
135
                        if (so)
136
                                o <= -pp;
137
                        else
138
                                o <= pp;
139
                end
140
                else
141
                        o <= pp;
142
                state <= DONE;
143
        end
144
DONE:
145
        state <= IDLE;
146
default:
147
        state <= IDLE;
148
endcase
149
end
150
 
151
endmodule
152
 
153
module FT64_multiplier_tb();
154
 
155
reg rst;
156
reg clk;
157
reg ld;
158
wire [127:0] o;
159
 
160
initial begin
161
        clk = 1;
162
        rst = 0;
163
        #100 rst = 1;
164
        #100 rst = 0;
165
        #100 ld = 1;
166
        #150 ld = 0;
167
end
168
 
169
always #10 clk = ~clk;  //  50 MHz
170
 
171
 
172
FT64_multiplier u1
173
(
174
        .rst(rst),
175
        .clk(clk),
176
        .ld(ld),
177
        .sgn(1'b1),
178
        .isMuli(1'b0),
179
        .a(64'd0),
180
        .b(64'd48),
181
        .o(o)
182
);
183
 
184
endmodule
185
 

powered by: WebSVN 2.1.0

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