[6] | 1 | // ========== Copyright Header Begin ========================================== |
---|
| 2 | // |
---|
| 3 | // OpenSPARC T1 Processor File: sparc_ifu_lru4.v |
---|
| 4 | // Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
---|
| 5 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
---|
| 6 | // |
---|
| 7 | // The above named program is free software; you can redistribute it and/or |
---|
| 8 | // modify it under the terms of the GNU General Public |
---|
| 9 | // License version 2 as published by the Free Software Foundation. |
---|
| 10 | // |
---|
| 11 | // The above named program is distributed in the hope that it will be |
---|
| 12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 14 | // General Public License for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public |
---|
| 17 | // License along with this work; if not, write to the Free Software |
---|
| 18 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 19 | // |
---|
| 20 | // ========== Copyright Header End ============================================ |
---|
| 21 | //////////////////////////////////////////////////////////////////////// |
---|
| 22 | /* |
---|
| 23 | // Module Name: sparc_ifu_lru4 |
---|
| 24 | // Description: |
---|
| 25 | // LRU scheduler. Least priority to the last granted |
---|
| 26 | // customer. If no requests, the priority remains the same. |
---|
| 27 | */ |
---|
| 28 | //////////////////////////////////////////////////////////////////////// |
---|
| 29 | |
---|
| 30 | module sparc_ifu_lru4(/*AUTOARG*/ |
---|
| 31 | // Outputs |
---|
| 32 | grant_vec, so, |
---|
| 33 | // Inputs |
---|
| 34 | clk, reset, se, si, recent_vec, load_recent, req_vec, spec_vec, |
---|
| 35 | use_spec |
---|
| 36 | ); |
---|
| 37 | |
---|
| 38 | input clk, reset, se, si; |
---|
| 39 | |
---|
| 40 | input [3:0] recent_vec; |
---|
| 41 | input load_recent; |
---|
| 42 | input [3:0] req_vec, |
---|
| 43 | spec_vec; |
---|
| 44 | |
---|
| 45 | input use_spec; |
---|
| 46 | |
---|
| 47 | output [3:0] grant_vec; |
---|
| 48 | |
---|
| 49 | output so; |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | wire [3:0] used0, // used0 is mru |
---|
| 53 | used1, |
---|
| 54 | used2, |
---|
| 55 | used3; // used3 is lru |
---|
| 56 | |
---|
| 57 | wire [3:0] used23, |
---|
| 58 | used23_nxt; |
---|
| 59 | |
---|
| 60 | wire [3:0] used0_buf, |
---|
| 61 | used1_buf, |
---|
| 62 | used2_buf, |
---|
| 63 | used3_buf; |
---|
| 64 | |
---|
| 65 | wire [3:0] sp_used0, |
---|
| 66 | sp_used1, |
---|
| 67 | sp_used2, |
---|
| 68 | sp_used3; |
---|
| 69 | wire [3:0] nosp_used0, |
---|
| 70 | nosp_used1, |
---|
| 71 | nosp_used2, |
---|
| 72 | nosp_used3; |
---|
| 73 | |
---|
| 74 | wire [3:0] used0_calc, |
---|
| 75 | used0_nxt, |
---|
| 76 | used1_calc, |
---|
| 77 | used1_nxt, |
---|
| 78 | used2_calc, |
---|
| 79 | used2_nxt, |
---|
| 80 | used3_calc, |
---|
| 81 | used3_nxt; |
---|
| 82 | |
---|
| 83 | wire hit1, |
---|
| 84 | hit2, |
---|
| 85 | hit3; |
---|
| 86 | |
---|
| 87 | wire [3:0] nospec_grant, |
---|
| 88 | spec_grant; |
---|
| 89 | |
---|
| 90 | wire reqhit1, |
---|
| 91 | reqhit2, |
---|
| 92 | reqhit3, |
---|
| 93 | reqhit23; |
---|
| 94 | |
---|
| 95 | wire spechit1, |
---|
| 96 | spechit2, |
---|
| 97 | spechit3, |
---|
| 98 | spechit23; |
---|
| 99 | |
---|
| 100 | wire sel_u0, |
---|
| 101 | sel_u1, |
---|
| 102 | sel_u2, |
---|
| 103 | sel_u3; |
---|
| 104 | |
---|
| 105 | wire sel_su0, |
---|
| 106 | sel_su1, |
---|
| 107 | sel_su2, |
---|
| 108 | sel_su3; |
---|
| 109 | |
---|
| 110 | dp_buffer #(4) use_buf0(.dout(used0_buf), |
---|
| 111 | .in (used0)); |
---|
| 112 | dp_buffer #(4) use_buf1(.dout(used1_buf), |
---|
| 113 | .in (used1)); |
---|
| 114 | dp_buffer #(4) use_buf2(.dout(used2_buf), |
---|
| 115 | .in (used2)); |
---|
| 116 | dp_buffer #(4) use_buf3(.dout(used3_buf), |
---|
| 117 | .in (used3)); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | // determine lru order for next cycle |
---|
| 121 | // assign hit0 = (used0_buf[0] & recent_vec[0] | |
---|
| 122 | // used0_buf[1] & recent_vec[1] | |
---|
| 123 | // used0_buf[2] & recent_vec[2] | |
---|
| 124 | // used0_buf[3] & recent_vec[3]) & load_recent; |
---|
| 125 | |
---|
| 126 | assign hit1 = (used1_buf[0] & recent_vec[0] | |
---|
| 127 | used1_buf[1] & recent_vec[1] | |
---|
| 128 | used1_buf[2] & recent_vec[2] | |
---|
| 129 | used1_buf[3] & recent_vec[3]) & load_recent; |
---|
| 130 | |
---|
| 131 | assign hit2 = (used2_buf[0] & recent_vec[0] | |
---|
| 132 | used2_buf[1] & recent_vec[1] | |
---|
| 133 | used2_buf[2] & recent_vec[2] | |
---|
| 134 | used2_buf[3] & recent_vec[3]) & load_recent; |
---|
| 135 | |
---|
| 136 | assign hit3 = (used3_buf[0] & recent_vec[0] | |
---|
| 137 | used3_buf[1] & recent_vec[1] | |
---|
| 138 | used3_buf[2] & recent_vec[2] | |
---|
| 139 | used3_buf[3] & recent_vec[3]) & load_recent; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | assign used0_calc = load_recent ? recent_vec : used0_buf; |
---|
| 143 | assign used1_calc = (hit3 | hit2 | hit1) ? used0_buf : used1_buf; |
---|
| 144 | assign used2_calc = (hit3 | hit2) ? used1_buf : used2_buf; |
---|
| 145 | assign used3_calc = (hit3) ? used2_buf : used3_buf; |
---|
| 146 | |
---|
| 147 | assign used0_nxt = reset ? 4'b0001 : used0_calc; |
---|
| 148 | assign used1_nxt = reset ? 4'b0010 : used1_calc; |
---|
| 149 | assign used2_nxt = reset ? 4'b0100 : used2_calc; |
---|
| 150 | assign used3_nxt = reset ? 4'b1000 : used3_calc; |
---|
| 151 | |
---|
| 152 | // use 4X4 matrix to hold lru info |
---|
| 153 | dff_s #(4) use0_reg(.din (used0_nxt), |
---|
| 154 | .q (used0), |
---|
| 155 | .clk (clk), .se(se), .si(), .so()); |
---|
| 156 | |
---|
| 157 | dff_s #(4) use1_reg(.din (used1_nxt), |
---|
| 158 | .q (used1), |
---|
| 159 | .clk (clk), .se(se), .si(), .so()); |
---|
| 160 | |
---|
| 161 | dff_s #(4) use2_reg(.din (used2_nxt), |
---|
| 162 | .q (used2), |
---|
| 163 | .clk (clk), .se(se), .si(), .so()); |
---|
| 164 | |
---|
| 165 | // used3 is lru |
---|
| 166 | dff_s #(4) use3_reg(.din (used3_nxt), |
---|
| 167 | .q (used3), |
---|
| 168 | .clk (clk), .se(se), .si(), .so()); |
---|
| 169 | |
---|
| 170 | assign used23_nxt = used2_nxt | used3_nxt; |
---|
| 171 | |
---|
| 172 | dff_s #(4) use23_reg(.din (used23_nxt), |
---|
| 173 | .q (used23), |
---|
| 174 | .clk (clk), .se(se), .si(), .so()); |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | // grant request based on lru |
---|
| 178 | |
---|
| 179 | // save some loading on req_vec by not doing this |
---|
| 180 | // assign reqhit0 = (used0[0] & req_vec[0] | |
---|
| 181 | // used0[1] & req_vec[1] | |
---|
| 182 | // used0[2] & req_vec[2] | |
---|
| 183 | // used0[3] & req_vec[3]); |
---|
| 184 | |
---|
| 185 | assign reqhit1 = (used1[0] & req_vec[0] | |
---|
| 186 | used1[1] & req_vec[1] | |
---|
| 187 | used1[2] & req_vec[2] | |
---|
| 188 | used1[3] & req_vec[3]); |
---|
| 189 | |
---|
| 190 | assign reqhit2 = (used2[0] & req_vec[0] | |
---|
| 191 | used2[1] & req_vec[1] | |
---|
| 192 | used2[2] & req_vec[2] | |
---|
| 193 | used2[3] & req_vec[3]); |
---|
| 194 | |
---|
| 195 | assign reqhit3 = (used3[0] & req_vec[0] | |
---|
| 196 | used3[1] & req_vec[1] | |
---|
| 197 | used3[2] & req_vec[2] | |
---|
| 198 | used3[3] & req_vec[3]); |
---|
| 199 | |
---|
| 200 | assign reqhit23 = (used23[0] & req_vec[0] | |
---|
| 201 | used23[1] & req_vec[1] | |
---|
| 202 | used23[2] & req_vec[2] | |
---|
| 203 | used23[3] & req_vec[3]); |
---|
| 204 | |
---|
| 205 | assign sel_u3 = reqhit3; |
---|
| 206 | assign sel_u2 = ~reqhit3 & reqhit2; |
---|
| 207 | assign sel_u1 = ~reqhit23 & reqhit1; |
---|
| 208 | assign sel_u0 = ~reqhit23 & ~reqhit1; |
---|
| 209 | |
---|
| 210 | assign nosp_used0 = used0 & {4{~use_spec}}; |
---|
| 211 | assign nosp_used1 = used1 & {4{~use_spec}}; |
---|
| 212 | assign nosp_used2 = used2 & {4{~use_spec}}; |
---|
| 213 | assign nosp_used3 = used3 & {4{~use_spec}}; |
---|
| 214 | |
---|
| 215 | mux4ds #(4) nsgnt_mux(.dout (nospec_grant), |
---|
| 216 | .in0 (nosp_used0), |
---|
| 217 | .in1 (nosp_used1), |
---|
| 218 | .in2 (nosp_used2), |
---|
| 219 | .in3 (nosp_used3), |
---|
| 220 | .sel0 (sel_u0), |
---|
| 221 | .sel1 (sel_u1), |
---|
| 222 | .sel2 (sel_u2), |
---|
| 223 | .sel3 (sel_u3)); |
---|
| 224 | |
---|
| 225 | assign spechit1 = (used1[0] & spec_vec[0] | |
---|
| 226 | used1[1] & spec_vec[1] | |
---|
| 227 | used1[2] & spec_vec[2] | |
---|
| 228 | used1[3] & spec_vec[3]); |
---|
| 229 | |
---|
| 230 | assign spechit2 = (used2[0] & spec_vec[0] | |
---|
| 231 | used2[1] & spec_vec[1] | |
---|
| 232 | used2[2] & spec_vec[2] | |
---|
| 233 | used2[3] & spec_vec[3]); |
---|
| 234 | |
---|
| 235 | assign spechit3 = (used3[0] & spec_vec[0] | |
---|
| 236 | used3[1] & spec_vec[1] | |
---|
| 237 | used3[2] & spec_vec[2] | |
---|
| 238 | used3[3] & spec_vec[3]); |
---|
| 239 | |
---|
| 240 | assign spechit23 = (used23[0] & spec_vec[0] | |
---|
| 241 | used23[1] & spec_vec[1] | |
---|
| 242 | used23[2] & spec_vec[2] | |
---|
| 243 | used23[3] & spec_vec[3]); |
---|
| 244 | |
---|
| 245 | assign sel_su3 = spechit3; |
---|
| 246 | assign sel_su2 = ~spechit3 & spechit2; |
---|
| 247 | assign sel_su1 = ~spechit23 & spechit1; |
---|
| 248 | assign sel_su0 = ~spechit23 & ~spechit1; |
---|
| 249 | |
---|
| 250 | assign sp_used0 = used0 & {4{use_spec}}; |
---|
| 251 | assign sp_used1 = used1 & {4{use_spec}}; |
---|
| 252 | assign sp_used2 = used2 & {4{use_spec}}; |
---|
| 253 | assign sp_used3 = used3 & {4{use_spec}}; |
---|
| 254 | |
---|
| 255 | mux4ds #(4) sgnt_mux(.dout (spec_grant), |
---|
| 256 | .in0 (sp_used0), |
---|
| 257 | .in1 (sp_used1), |
---|
| 258 | .in2 (sp_used2), |
---|
| 259 | .in3 (sp_used3), |
---|
| 260 | .sel0 (sel_su0), |
---|
| 261 | .sel1 (sel_su1), |
---|
| 262 | .sel2 (sel_su2), |
---|
| 263 | .sel3 (sel_su3)); |
---|
| 264 | |
---|
| 265 | assign grant_vec = spec_grant | nospec_grant; |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | endmodule // sparc_ifu_lru4 |
---|
| 269 | |
---|