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

Subversion Repositories aemb

[/] [aemb/] [branches/] [AEMB2_712/] [rtl/] [verilog/] [aeMB_bpcu.v] - Blame information for rev 44

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

Line No. Rev Author Line
1 44 sybreon
// $Id: aeMB_bpcu.v,v 1.2 2007-11-02 19:20:58 sybreon Exp $
2 41 sybreon
//
3
// AEMB BRANCH PROGRAMME COUNTER UNIT
4
// 
5
// Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
//  
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public License
9
// as published by the Free Software Foundation; either version 2.1 of
10
// the License, or (at your option) any later version.
11
//
12
// This library is distributed in the hope that it will be useful, but
13
// WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//  
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// $Log: not supported by cvs2svn $
23 44 sybreon
// Revision 1.1  2007/11/02 03:25:39  sybreon
24
// New EDK 3.2 compatible design with optional barrel-shifter and multiplier.
25
// Fixed various minor data hazard bugs.
26
// Code compatible with -O0/1/2/3/s generated code.
27
//
28 41 sybreon
 
29
module aeMB_bpcu (/*AUTOARG*/
30
   // Outputs
31 44 sybreon
   iwb_adr_o, rPC, rPCLNK, rBRA, rDLY, rATOM,
32 41 sybreon
   // Inputs
33
   rMXALT, rOPC, rRD, rRA, rRESULT, rDWBDI, rREGA, rXCE, gclk, grst,
34
   gena
35
   );
36
   parameter IW = 24;
37
 
38
   // INST WISHBONE
39
   output [IW-1:2] iwb_adr_o;
40
 
41
   // INTERNAL
42
   output [31:2]   rPC, rPCLNK;
43
   output          rBRA;
44
   output          rDLY;
45 44 sybreon
   output [1:0]    rATOM;
46 41 sybreon
   input [1:0]      rMXALT;
47
   input [5:0]      rOPC;
48
   input [4:0]      rRD, rRA;
49
   input [31:0]    rRESULT; // ALU
50
   input [31:0]    rDWBDI; // RAM
51 44 sybreon
   input [31:0]    rREGA;
52 41 sybreon
   input [1:0]      rXCE;
53
 
54
   // SYSTEM
55
   input           gclk, grst, gena;
56
 
57 44 sybreon
   // --- BRANCH CONTROL --------------------------------------------
58
   // Controls the branch and delay flags
59
 
60 41 sybreon
   wire            fRTD = (rOPC == 6'o55);
61
   wire            fBCC = (rOPC == 6'o47) | (rOPC == 6'o57);
62
   wire            fBRU = (rOPC == 6'o46) | (rOPC == 6'o56);
63
 
64
   wire [31:0]      wREGA;
65
   assign          wREGA = (rMXALT == 2'o2) ? rDWBDI :
66
                           (rMXALT == 2'o1) ? rRESULT :
67
                           rREGA;
68
 
69
   wire            wBEQ = (wREGA == 32'd0);
70
   wire            wBNE = ~wBEQ;
71
   wire            wBLT = wREGA[31];
72
   wire            wBLE = wBLT | wBEQ;
73
   wire            wBGE = ~wBLT;
74
   wire            wBGT = ~wBLE;
75
 
76
   reg             xXCC;
77
   always @(/*AUTOSENSE*/rRD or wBEQ or wBGE or wBGT or wBLE or wBLT
78
            or wBNE)
79
     case (rRD[2:0])
80
       3'o0: xXCC <= wBEQ;
81
       3'o1: xXCC <= wBNE;
82
       3'o2: xXCC <= wBLT;
83
       3'o3: xXCC <= wBLE;
84
       3'o4: xXCC <= wBGT;
85
       3'o5: xXCC <= wBGE;
86
       default: xXCC <= 1'bX;
87
     endcase // case (rRD[2:0])
88
 
89
   reg             rBRA, xBRA;
90
   reg             rDLY, xDLY;
91
   wire            fSKIP = rBRA & !rDLY;
92
 
93
   always @(/*AUTOSENSE*/fBCC or fBRU or fRTD or rBRA or rRA or rRD
94 44 sybreon
            or rXCE or xXCC)
95
     if (rBRA | |rXCE) begin
96 41 sybreon
        /*AUTORESET*/
97
        // Beginning of autoreset for uninitialized flops
98
        xBRA <= 1'h0;
99
        xDLY <= 1'h0;
100
        // End of automatics
101
     end else begin
102
        xDLY <= (fBRU & rRA[4]) | (fBCC & rRD[4]) | fRTD;
103
        xBRA <= (fRTD | fBRU) ? 1'b1 :
104
                (fBCC) ? xXCC :
105
                1'b0;
106
     end
107
 
108 44 sybreon
   // --- PC PIPELINE ------------------------------------------------
109
   // PC and related changes
110 41 sybreon
 
111
   reg [31:2]      rIPC, xIPC;
112
   reg [31:2]      rPC, xPC;
113 44 sybreon
   reg [31:2]      rPCLNK, xPCLNK;
114 41 sybreon
 
115
   assign          iwb_adr_o = rIPC[IW-1:2];
116
 
117 44 sybreon
   always @(/*AUTOSENSE*/rATOM or rBRA or rIPC or rPC or rRESULT
118
            or rXCE) begin
119
      xPCLNK <= (^rATOM) ? rPC : rPC;
120
      //xPCLNK <= rPC;
121
      //xPC <= (^rATOM) ? rIPC : rRESULT[31:2]; 
122
      xPC <= rIPC;
123
      //xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
124
     case (rXCE)
125
       2'o1: xIPC <= 30'h2;
126
       2'o2: xIPC <= 30'h4;
127
       2'o3: xIPC <= 30'h6;
128
       default: xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
129
     endcase // case (rXCE)      
130
   end
131 41 sybreon
 
132 44 sybreon
   // --- ATOMIC CONTROL ---------------------------------------------
133
   // This is used to indicate 'safe' instruction borders.
134
 
135
   wire         wIMM = (rOPC == 6'o54) & !fSKIP;
136
   wire         wRTD = (rOPC == 6'o55) & !fSKIP;
137
   wire         wBCC = xXCC & ((rOPC == 6'o47) | (rOPC == 6'o57)) & !fSKIP;
138
   wire         wBRU = ((rOPC == 6'o46) | (rOPC == 6'o56)) & !fSKIP;
139
 
140
   wire         fATOM = ~(wIMM | wRTD | wBCC | wBRU | rBRA);
141
   reg [1:0]     rATOM, xATOM;
142
 
143
   always @(/*AUTOSENSE*/fATOM or rATOM)
144
     xATOM <= {rATOM[0], (rATOM[0] ^ fATOM)};
145
 
146
 
147
   // --- SYNC PIPELINE ----------------------------------------------
148
 
149 41 sybreon
   always @(posedge gclk)
150
     if (grst) begin
151
        /*AUTORESET*/
152
        // Beginning of autoreset for uninitialized flops
153 44 sybreon
        rATOM <= 2'h0;
154 41 sybreon
        rBRA <= 1'h0;
155
        rDLY <= 1'h0;
156
        rIPC <= 30'h0;
157
        rPC <= 30'h0;
158
        rPCLNK <= 30'h0;
159
        // End of automatics
160
     end else if (gena) begin
161
        rIPC <= #1 xIPC;
162
        rBRA <= #1 xBRA;
163
        rPC <= #1 xPC;
164
        rPCLNK <= #1 xPCLNK;
165 44 sybreon
        rDLY <= #1 xDLY;
166
        rATOM <= #1 xATOM;
167 41 sybreon
     end
168 44 sybreon
 
169 41 sybreon
endmodule // aeMB_bpcu

powered by: WebSVN 2.1.0

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