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

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [or1200/] [rtl/] [verilog/] [mult_mac.v] - Blame information for rev 1778

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

Line No. Rev Author Line
1 218 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Top level multiplier and MAC                       ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Multiplier is 32x32 however multiply instructions only      ////
10
////  use lower 32 bits of the result. MAC is 32x32=64+64.        ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   - make it smaller and faster                               ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Damjan Lampret, lampret@opencores.org                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48
// Revision 1.2  2001/10/14 13:12:09  lampret
49
// MP3 version.
50
//
51
// Revision 1.1.1.1  2001/10/06 10:18:38  igorm
52
// no message
53
//
54
//
55
 
56
// synopsys translate_off
57
`include "timescale.v"
58
// synopsys translate_on
59
`include "defines.v"
60
 
61
module mult_mac(clk, rst, id_macrc_op, macrc_op, a, b, alu_op, result, mac_stall_r);
62
 
63
parameter width = `OPERAND_WIDTH;
64
 
65
//
66
// I/O
67
//
68
input                           clk;
69
input                           rst;
70
input                           id_macrc_op;
71
input                           macrc_op;
72
input   [width-1:0]              a;
73
input   [width-1:0]              b;
74
input   [`ALUOP_WIDTH-1:0]       alu_op;
75
output  [width-1:0]              result;
76
output                          mac_stall_r;
77
 
78
//
79
// Internal wires and regs
80
//
81
wire    [width-1:0]              result;
82
reg     [2*width-1:0]            mul_prod_r;
83
reg     [2*width-1:0]            mac_r;
84
wire    [2*width-1:0]            mul_prod;
85
wire                            mac_op;
86
reg                             mac_op_r1;
87
reg                             mac_op_r2;
88
reg                             mac_op_r3;
89
reg                             mac_stall_r;
90
 
91
//
92
// Combinatorial logic
93
//
94
assign result = (alu_op == `ALUOP_MUL) ? mul_prod_r[31:0] : mac_r[59:28];
95
assign mac_op = (alu_op == `ALUOP_MAC);
96
 
97
//
98
// Instantiation of the multiplier
99
//
100
multp2_32x32 multp2_32x32(
101
        .X(a),
102
        .Y(b),
103
        .RST(rst),
104
        .CLK(clk),
105
        .P(mul_prod)
106
);
107
 
108
//
109
// Registered output from the multiplier
110
//
111
always @(posedge rst or posedge clk)
112
        if (rst)
113
                mul_prod_r <= #1 64'h0000_0000_0000_0000;
114
        else
115
                mul_prod_r <= #1 mul_prod[63:0];
116
 
117
//
118
// Propagation of l.mac opcode
119
//
120
always @(posedge clk or posedge rst)
121
        if (rst)
122
                mac_op_r1 <= #1 1'b0;
123
        else
124
                mac_op_r1 <= #1 mac_op;
125
 
126
//
127
// Propagation of l.mac opcode
128
//
129
always @(posedge clk or posedge rst)
130
        if (rst)
131
                mac_op_r2 <= #1 1'b0;
132
        else
133
                mac_op_r2 <= #1 mac_op_r1;
134
 
135
//
136
// Propagation of l.mac opcode
137
//
138
always @(posedge clk or posedge rst)
139
        if (rst)
140
                mac_op_r3 <= #1 1'b0;
141
        else
142
                mac_op_r3 <= #1 mac_op_r2;
143
 
144
//
145
// Implementation of MAC
146
//
147
always @(posedge rst or posedge clk)
148
        if (rst)
149
                mac_r <= #1 64'h0000_0000_0000_0000;
150
        else if (mac_op_r3)
151
                mac_r <= #1 mac_r + mul_prod_r;
152
        else if (macrc_op)
153
                mac_r <= #1 64'h0000_0000_0000_0000;
154
 
155
//
156
// Stall CPU if l.macrc is in ID and MAC still has to process l.mac instructions
157
// in EX stage (e.g. inside multiplier)
158
//
159
always @(posedge rst or posedge clk)
160
        if (rst)
161
                mac_stall_r <= #1 1'b0;
162
        else
163
                mac_stall_r <= #1 (mac_op | mac_op_r1 | mac_op_r2) & id_macrc_op;
164
 
165
endmodule

powered by: WebSVN 2.1.0

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