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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mp3/] [rtl/] [verilog/] [or1200.xcv/] [mult_mac.v] - Blame information for rev 266

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

Line No. Rev Author Line
1 266 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.1.1.1  2001/10/06 10:18:38  igorm
49
// no message
50
//
51
//
52
 
53
// synopsys translate_off
54
`include "timescale.v"
55
// synopsys translate_on
56
`include "defines.v"
57
 
58
module mult_mac(clk, rst, id_macrc_op, macrc_op, a, b, alu_op, result, mac_stall_r);
59
 
60
parameter width = `OPERAND_WIDTH;
61
 
62
//
63
// I/O
64
//
65
input                           clk;
66
input                           rst;
67
input                           id_macrc_op;
68
input                           macrc_op;
69
input   [width-1:0]              a;
70
input   [width-1:0]              b;
71
input   [`ALUOP_WIDTH-1:0]       alu_op;
72
output  [width-1:0]              result;
73
output                          mac_stall_r;
74
 
75
//
76
// Internal wires and regs
77
//
78
wire    [width-1:0]              result;
79
reg     [2*width-1:0]            mul_prod_r;
80
reg     [2*width-1:0]            mac_r;
81
wire    [2*width-1:0]            mul_prod;
82
wire                            mac_op;
83
reg                             mac_op_r1;
84
reg                             mac_op_r2;
85
reg                             mac_op_r3;
86
reg                             mac_stall_r;
87
 
88
//
89
// Combinatorial logic
90
//
91
assign result = (alu_op == `ALUOP_MUL) ? mul_prod_r[31:0] : mac_r[59:28];
92
assign mac_op = (alu_op == `ALUOP_MAC);
93
 
94
//
95
// Instantiation of the multiplier
96
//
97
multp2_32x32 multp2_32x32(
98
        .X(a),
99
        .Y(b),
100
        .RST(rst),
101
        .CLK(clk),
102
        .P(mul_prod)
103
);
104
 
105
//
106
// Registered output from the multiplier
107
//
108
always @(posedge rst or posedge clk)
109
        if (rst)
110
                mul_prod_r <= #1 64'h0000_0000_0000_0000;
111
        else
112
                mul_prod_r <= #1 mul_prod[63:0];
113
 
114
//
115
// Propagation of l.mac opcode
116
//
117
always @(posedge clk or posedge rst)
118
        if (rst)
119
                mac_op_r1 <= #1 1'b0;
120
        else
121
                mac_op_r1 <= #1 mac_op;
122
 
123
//
124
// Propagation of l.mac opcode
125
//
126
always @(posedge clk or posedge rst)
127
        if (rst)
128
                mac_op_r2 <= #1 1'b0;
129
        else
130
                mac_op_r2 <= #1 mac_op_r1;
131
 
132
//
133
// Propagation of l.mac opcode
134
//
135
always @(posedge clk or posedge rst)
136
        if (rst)
137
                mac_op_r3 <= #1 1'b0;
138
        else
139
                mac_op_r3 <= #1 mac_op_r2;
140
 
141
//
142
// Implementation of MAC
143
//
144
always @(posedge rst or posedge clk)
145
        if (rst)
146
                mac_r <= #1 64'h0000_0000_0000_0000;
147
        else if (mac_op_r3)
148
                mac_r <= #1 mac_r + mul_prod_r;
149
        else if (macrc_op)
150
                mac_r <= #1 64'h0000_0000_0000_0000;
151
 
152
//
153
// Stall CPU if l.macrc is in ID and MAC still has to process l.mac instructions
154
// in EX stage (e.g. inside multiplier)
155
//
156
always @(posedge rst or posedge clk)
157
        if (rst)
158
                mac_stall_r <= #1 1'b0;
159
        else
160
                mac_stall_r <= #1 (mac_op | mac_op_r1 | mac_op_r2) & id_macrc_op;
161
 
162
endmodule

powered by: WebSVN 2.1.0

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