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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [Thor_multiplier.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2013  Robert Finch, Stratford
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
// Thor Superscaler
23
// Thor_multiplier.v
24
//  - 64 bit multiplier
25
//
26
// ============================================================================
27
//
28
module Thor_multiplier(rst, clk, ld, sgn, isMuli, a, b, imm, o, done);
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 sgn;
38
input isMuli;
39
input [WID-1:0] a;
40
input [WID-1:0] b;
41
input [WID-1:0] imm;
42
output [WID*2-1:0] o;
43
reg [WID*2-1:0] o;
44
output done;
45
 
46
reg [WID-1:0] aa,bb;
47
reg so;
48
reg [2:0] state;
49
reg [7:0] cnt;
50
wire cnt_done = cnt==8'd0;
51
assign done = state==DONE;
52
reg ce1;
53
reg [WID*2-1:0] prod;
54
//wire [64:0] p1 = aa[0] ? prod[127:64] + b : prod[127:64];
55
//wire [65:0] p2 = aa[1] ? p1 + {b,1'b0} : p1;
56
wire [WID+WID/4-1:0] p1 = bb * aa[WID/4-1:0] + prod[WID*2-1:WID];
57
 
58
initial begin
59
    prod = 64'd0;
60
    o = 64'd0;
61
end
62
 
63
always @(posedge clk)
64
if (rst) begin
65
        aa <= {WID{1'b0}};
66
        bb <= {WID{1'b0}};
67
        prod <= {WID*2{1'b0}};
68
        o <= {WID*2{1'b0}};
69
        state <= IDLE;
70
end
71
else
72
begin
73
if (!cnt_done)
74
        cnt <= cnt - 8'd1;
75
 
76
case(state)
77
IDLE:
78
        if (ld) begin
79
                if (sgn) begin
80
                        aa <= a[WID-1] ? -a : a;
81
                        bb <= isMuli ? (imm[WID-1] ? -imm : imm) :(b[WID-1] ? -b : b);
82
                        so <= isMuli ? a[WID-1] ^ imm[WID-1] : a[WID-1] ^ b[WID-1];
83
                end
84
                else begin
85
                        aa <= a;
86
                        bb <= isMuli ? imm : b;
87
                        so <= 1'b0;
88
                end
89
                prod <= {WID*2{1'b0}};
90
                cnt <= 8'd4;
91
                state <= MULT;
92
        end
93
MULT:
94
        if (!cnt_done) begin
95
                aa <= {16'b0,aa[WID-1:WID/4]};
96
                prod <= {16'b0,prod[WID*2-1:WID/4]};
97
                prod[WID*2-1:WID*3/4] <= p1;
98
        end
99
        else begin
100
                if (sgn) begin
101
                        if (so)
102
                                o <= -prod;
103
                        else
104
                                o <= prod;
105
                end
106
                else
107
                        o <= prod;
108
                state <= DONE;
109
        end
110
default:
111
        state <= IDLE;
112
endcase
113
end
114
 
115
endmodule
116
 
117
module Thor_multiplier_tb();
118
 
119
reg rst;
120
reg clk;
121
reg ld;
122
wire [127:0] o;
123
 
124
initial begin
125
        clk = 1;
126
        rst = 0;
127
        #100 rst = 1;
128
        #100 rst = 0;
129
        #100 ld = 1;
130
        #150 ld = 0;
131
end
132
 
133
always #10 clk = ~clk;  //  50 MHz
134
 
135
 
136
Thor_multiplier u1
137
(
138
        .rst(rst),
139
        .clk(clk),
140
        .ld(ld),
141
        .sgn(1'b0),
142
        .isMuli(1'b1),
143
        .a(64'd56),
144
        .b(64'd0),
145
        .imm(64'd27),
146
        .o(o)
147
);
148
 
149
endmodule
150
 

powered by: WebSVN 2.1.0

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