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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [rtl/] [verilog/] [Raptor64Mult.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 robfinch
// ============================================================================
2
// (C) 2011 Robert Finch
3
// All Rights Reserved.
4
// robfinch<remove>@sympatico.ca
5
//
6
// Raptor64Mult.v
7
//  - 64 bit multiplier
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
// ============================================================================
23
//
24
module Raptor64Mult(rst, clk, ld, sgn, isMuli, a, b, imm, o, done);
25
parameter SGNADJO=3'd2;
26
parameter MULT=3'd3;
27
parameter IDLE=3'd4;
28
parameter DONE=3'd5;
29
input clk;
30
input rst;
31
input ld;
32
input sgn;
33
input isMuli;
34
input [63:0] a;
35
input [63:0] b;
36
input [63:0] imm;
37
output [127:0] o;
38
reg [127:0] o;
39
output done;
40
 
41
reg [63:0] aa,bb;
42
reg so;
43
reg [2:0] state;
44
reg [7:0] cnt;
45
wire cnt_done = cnt==8'd0;
46
assign done = state==DONE;
47
reg ce1;
48
reg [127:0] prod;
49
//wire [64:0] p1 = aa[0] ? prod[127:64] + b : prod[127:64];
50
//wire [65:0] p2 = aa[1] ? p1 + {b,1'b0} : p1;
51
wire [79:0] p1 = bb * aa[15:0] + prod[127:64];
52
 
53
always @(posedge clk)
54
if (rst) begin
55
        aa <= 64'd0;
56
        bb <= 64'd0;
57
        prod <= 128'd0;
58
        o <= 128'd0;
59
        state <= IDLE;
60
end
61
else
62
begin
63
if (!cnt_done)
64
        cnt <= cnt - 8'd1;
65
 
66
case(state)
67
IDLE:
68
        if (ld) begin
69
                if (sgn) begin
70
                        aa <= a[63] ? -a : a;
71
                        bb <= isMuli ? (imm[63] ? -imm : imm) :(b[63] ? -b : b);
72
                        so <= isMuli ? a[63] ^ imm[63] : a[63] ^ b[63];
73
                end
74
                else begin
75
                        aa <= a;
76
                        bb <= isMuli ? imm : b;
77
                        so <= 1'b0;
78
                end
79
                prod <= 128'd0;
80
                cnt <= 8'd4;
81
                state <= MULT;
82
        end
83
MULT:
84
        if (!cnt_done) begin
85
                aa <= {16'b0,aa[63:16]};
86
                prod <= {16'b0,prod[127:16]};
87
                prod[127:48] <= p1;
88
        end
89
        else begin
90
                if (sgn) begin
91
                        if (so)
92
                                o <= -prod;
93
                        else
94
                                o <= prod;
95
                end
96
                else
97
                        o <= prod;
98
                state <= DONE;
99
        end
100
DONE:
101
        state <= IDLE;
102
endcase
103
end
104
 
105
endmodule
106
 
107
module Raptor64Mult_tb();
108
 
109
reg rst;
110
reg clk;
111
reg ld;
112
wire [127:0] o;
113
 
114
initial begin
115
        clk = 1;
116
        rst = 0;
117
        #100 rst = 1;
118
        #100 rst = 0;
119
        #100 ld = 1;
120
        #150 ld = 0;
121
end
122
 
123
always #10 clk = ~clk;  //  50 MHz
124
 
125
 
126
Raptor64Mult u1
127
(
128
        .rst(rst),
129
        .clk(clk),
130
        .ld(ld),
131
        .sgn(1'b1),
132
        .isMuli(1'b0),
133
        .a(64'd10005),
134
        .b(64'd1117),
135
        .imm(64'd27),
136
        .o(o)
137
);
138
 
139
endmodule
140
 

powered by: WebSVN 2.1.0

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