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

Subversion Repositories thor

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

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

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

powered by: WebSVN 2.1.0

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