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

Subversion Repositories thor

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

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

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

powered by: WebSVN 2.1.0

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