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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_multiplier.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2013-2017  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
reg [WID*2-1:0] prod;
55
//wire [64:0] p1 = aa[0] ? prod[127:64] + b : prod[127:64];
56
//wire [65:0] p2 = aa[1] ? p1 + {b,1'b0} : p1;
57
wire [WID+WID/4-1:0] p1 = bb * aa[WID/4-1:0] + prod[WID*2-1:WID];
58
 
59
initial begin
60
    prod = 64'd0;
61
    o = 64'd0;
62
end
63
 
64
always @(posedge clk)
65
if (rst) begin
66
        aa <= {WID{1'b0}};
67
        bb <= {WID{1'b0}};
68
        prod <= {WID*2{1'b0}};
69
        o <= {WID*2{1'b0}};
70
        state <= IDLE;
71
end
72
else
73
begin
74
if (abort)
75
    cnt <= 8'd00;
76
else if (!cnt_done)
77
        cnt <= cnt - 8'd1;
78
 
79
case(state)
80
IDLE:
81
        if (ld) begin
82
            if (sgnus) begin
83
                        aa <= a[WID-1] ? -a : a;
84
                        bb <= b;
85
                        so = a[WID-1];
86
            end
87
                else if (sgn) begin
88
                        aa <= a[WID-1] ? -a : a;
89
                        bb <= b[WID-1] ? -b : b;
90
                        so <= a[WID-1] ^ b[WID-1];
91
                end
92
                else begin
93
                        aa <= a;
94
                        bb <= b;
95
                        so <= 1'b0;
96
                end
97
                prod <= {WID*2{1'b0}};
98
                cnt <= 8'd4;
99
                state <= MULT;
100
        end
101
MULT:
102
        if (!cnt_done) begin
103
                aa <= {16'b0,aa[WID-1:WID/4]};
104
                prod <= {16'b0,prod[WID*2-1:WID/4]};
105
                prod[WID*2-1:WID*3/4] <= p1;
106
        end
107
        else begin
108
                if (sgn|sgnus) begin
109
                        if (so)
110
                                o <= -prod;
111
                        else
112
                                o <= prod;
113
                end
114
                else
115
                        o <= prod;
116
                state <= DONE;
117
        end
118
default:
119
        state <= IDLE;
120
endcase
121
end
122
 
123
endmodule
124
 
125
module FT64_multiplier_tb();
126
 
127
reg rst;
128
reg clk;
129
reg ld;
130
wire [127:0] o;
131
 
132
initial begin
133
        clk = 1;
134
        rst = 0;
135
        #100 rst = 1;
136
        #100 rst = 0;
137
        #100 ld = 1;
138
        #150 ld = 0;
139
end
140
 
141
always #10 clk = ~clk;  //  50 MHz
142
 
143
 
144
FT64_multiplier u1
145
(
146
        .rst(rst),
147
        .clk(clk),
148
        .ld(ld),
149
        .sgn(1'b0),
150
        .isMuli(1'b1),
151
        .a(64'd56),
152
        .b(64'd0),
153
        .imm(64'd27),
154
        .o(o)
155
);
156
 
157
endmodule
158
 

powered by: WebSVN 2.1.0

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