1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/rtl/lm32_dcache.v Tue Mar 08 09:40:42 2011 +0000 1.3 @@ -0,0 +1,542 @@ 1.4 +// ============================================================================= 1.5 +// COPYRIGHT NOTICE 1.6 +// Copyright 2006 (c) Lattice Semiconductor Corporation 1.7 +// ALL RIGHTS RESERVED 1.8 +// This confidential and proprietary software may be used only as authorised by 1.9 +// a licensing agreement from Lattice Semiconductor Corporation. 1.10 +// The entire notice above must be reproduced on all authorized copies and 1.11 +// copies may only be made to the extent permitted by a licensing agreement from 1.12 +// Lattice Semiconductor Corporation. 1.13 +// 1.14 +// Lattice Semiconductor Corporation TEL : 1-800-Lattice (USA and Canada) 1.15 +// 5555 NE Moore Court 408-826-6000 (other locations) 1.16 +// Hillsboro, OR 97124 web : http://www.latticesemi.com/ 1.17 +// U.S.A email: techsupport@latticesemi.com 1.18 +// =============================================================================/ 1.19 +// FILE DETAILS 1.20 +// Project : LatticeMico32 1.21 +// File : lm32_dcache.v 1.22 +// Title : Data cache 1.23 +// Dependencies : lm32_include.v 1.24 +// Version : 6.1.17 1.25 +// : Initial Release 1.26 +// Version : 7.0SP2, 3.0 1.27 +// : No Change 1.28 +// Version : 3.1 1.29 +// : Support for user-selected resource usage when implementing 1.30 +// : cache memory. Additional parameters must be defined when 1.31 +// : invoking lm32_ram.v 1.32 +// ============================================================================= 1.33 + 1.34 +`include "lm32_include.v" 1.35 + 1.36 +`ifdef CFG_DCACHE_ENABLED 1.37 + 1.38 +`define LM32_DC_ADDR_OFFSET_RNG addr_offset_msb:addr_offset_lsb 1.39 +`define LM32_DC_ADDR_SET_RNG addr_set_msb:addr_set_lsb 1.40 +`define LM32_DC_ADDR_TAG_RNG addr_tag_msb:addr_tag_lsb 1.41 +`define LM32_DC_ADDR_IDX_RNG addr_set_msb:addr_offset_lsb 1.42 + 1.43 +`define LM32_DC_TMEM_ADDR_WIDTH addr_set_width 1.44 +`define LM32_DC_TMEM_ADDR_RNG (`LM32_DC_TMEM_ADDR_WIDTH-1):0 1.45 +`define LM32_DC_DMEM_ADDR_WIDTH (addr_offset_width+addr_set_width) 1.46 +`define LM32_DC_DMEM_ADDR_RNG (`LM32_DC_DMEM_ADDR_WIDTH-1):0 1.47 + 1.48 +`define LM32_DC_TAGS_WIDTH (addr_tag_width+1) 1.49 +`define LM32_DC_TAGS_RNG (`LM32_DC_TAGS_WIDTH-1):0 1.50 +`define LM32_DC_TAGS_TAG_RNG (`LM32_DC_TAGS_WIDTH-1):1 1.51 +`define LM32_DC_TAGS_VALID_RNG 0 1.52 + 1.53 +`define LM32_DC_STATE_RNG 2:0 1.54 +`define LM32_DC_STATE_FLUSH 3'b001 1.55 +`define LM32_DC_STATE_CHECK 3'b010 1.56 +`define LM32_DC_STATE_REFILL 3'b100 1.57 + 1.58 +///////////////////////////////////////////////////// 1.59 +// Module interface 1.60 +///////////////////////////////////////////////////// 1.61 + 1.62 +module lm32_dcache ( 1.63 + // ----- Inputs ----- 1.64 + clk_i, 1.65 + rst_i, 1.66 + stall_a, 1.67 + stall_x, 1.68 + stall_m, 1.69 + address_x, 1.70 + address_m, 1.71 + load_q_m, 1.72 + store_q_m, 1.73 + store_data, 1.74 + store_byte_select, 1.75 + refill_ready, 1.76 + refill_data, 1.77 + dflush, 1.78 + // ----- Outputs ----- 1.79 + stall_request, 1.80 + restart_request, 1.81 + refill_request, 1.82 + refill_address, 1.83 + refilling, 1.84 + load_data 1.85 + ); 1.86 + 1.87 +///////////////////////////////////////////////////// 1.88 +// Parameters 1.89 +///////////////////////////////////////////////////// 1.90 + 1.91 +parameter associativity = 1; // Associativity of the cache (Number of ways) 1.92 +parameter sets = 512; // Number of sets 1.93 +parameter bytes_per_line = 16; // Number of bytes per cache line 1.94 +parameter base_address = 0; // Base address of cachable memory 1.95 +parameter limit = 0; // Limit (highest address) of cachable memory 1.96 + 1.97 +localparam addr_offset_width = clogb2(bytes_per_line)-1-2; 1.98 +localparam addr_set_width = clogb2(sets)-1; 1.99 +localparam addr_offset_lsb = 2; 1.100 +localparam addr_offset_msb = (addr_offset_lsb+addr_offset_width-1); 1.101 +localparam addr_set_lsb = (addr_offset_msb+1); 1.102 +localparam addr_set_msb = (addr_set_lsb+addr_set_width-1); 1.103 +localparam addr_tag_lsb = (addr_set_msb+1); 1.104 +localparam addr_tag_msb = clogb2(`CFG_DCACHE_LIMIT-`CFG_DCACHE_BASE_ADDRESS)-1; 1.105 +localparam addr_tag_width = (addr_tag_msb-addr_tag_lsb+1); 1.106 + 1.107 +///////////////////////////////////////////////////// 1.108 +// Inputs 1.109 +///////////////////////////////////////////////////// 1.110 + 1.111 +input clk_i; // Clock 1.112 +input rst_i; // Reset 1.113 + 1.114 +input stall_a; // Stall A stage 1.115 +input stall_x; // Stall X stage 1.116 +input stall_m; // Stall M stage 1.117 + 1.118 +input [`LM32_WORD_RNG] address_x; // X stage load/store address 1.119 +input [`LM32_WORD_RNG] address_m; // M stage load/store address 1.120 +input load_q_m; // Load instruction in M stage 1.121 +input store_q_m; // Store instruction in M stage 1.122 +input [`LM32_WORD_RNG] store_data; // Data to store 1.123 +input [`LM32_BYTE_SELECT_RNG] store_byte_select; // Which bytes in store data should be modified 1.124 + 1.125 +input refill_ready; // Indicates next word of refill data is ready 1.126 +input [`LM32_WORD_RNG] refill_data; // Refill data 1.127 + 1.128 +input dflush; // Indicates cache should be flushed 1.129 + 1.130 +///////////////////////////////////////////////////// 1.131 +// Outputs 1.132 +///////////////////////////////////////////////////// 1.133 + 1.134 +output stall_request; // Request pipeline be stalled because cache is busy 1.135 +wire stall_request; 1.136 +output restart_request; // Request to restart instruction that caused the cache miss 1.137 +reg restart_request; 1.138 +output refill_request; // Request a refill 1.139 +reg refill_request; 1.140 +output [`LM32_WORD_RNG] refill_address; // Address to refill from 1.141 +reg [`LM32_WORD_RNG] refill_address; 1.142 +output refilling; // Indicates if the cache is currently refilling 1.143 +reg refilling; 1.144 +output [`LM32_WORD_RNG] load_data; // Data read from cache 1.145 +wire [`LM32_WORD_RNG] load_data; 1.146 + 1.147 +///////////////////////////////////////////////////// 1.148 +// Internal nets and registers 1.149 +///////////////////////////////////////////////////// 1.150 + 1.151 +wire read_port_enable; // Cache memory read port clock enable 1.152 +wire write_port_enable; // Cache memory write port clock enable 1.153 +wire [0:associativity-1] way_tmem_we; // Tag memory write enable 1.154 +wire [0:associativity-1] way_dmem_we; // Data memory write enable 1.155 +wire [`LM32_WORD_RNG] way_data[0:associativity-1]; // Data read from data memory 1.156 +wire [`LM32_DC_TAGS_TAG_RNG] way_tag[0:associativity-1];// Tag read from tag memory 1.157 +wire [0:associativity-1] way_valid; // Indicates which ways are valid 1.158 +wire [0:associativity-1] way_match; // Indicates which ways matched 1.159 +wire miss; // Indicates no ways matched 1.160 + 1.161 +wire [`LM32_DC_TMEM_ADDR_RNG] tmem_read_address; // Tag memory read address 1.162 +wire [`LM32_DC_TMEM_ADDR_RNG] tmem_write_address; // Tag memory write address 1.163 +wire [`LM32_DC_DMEM_ADDR_RNG] dmem_read_address; // Data memory read address 1.164 +wire [`LM32_DC_DMEM_ADDR_RNG] dmem_write_address; // Data memory write address 1.165 +wire [`LM32_DC_TAGS_RNG] tmem_write_data; // Tag memory write data 1.166 +reg [`LM32_WORD_RNG] dmem_write_data; // Data memory write data 1.167 + 1.168 +reg [`LM32_DC_STATE_RNG] state; // Current state of FSM 1.169 +wire flushing; // Indicates if cache is currently flushing 1.170 +wire check; // Indicates if cache is currently checking for hits/misses 1.171 +wire refill; // Indicates if cache is currently refilling 1.172 + 1.173 +wire valid_store; // Indicates if there is a valid store instruction 1.174 +reg [associativity-1:0] refill_way_select; // Which way should be refilled 1.175 +reg [`LM32_DC_ADDR_OFFSET_RNG] refill_offset; // Which word in cache line should be refilled 1.176 +wire last_refill; // Indicates when on last cycle of cache refill 1.177 +reg [`LM32_DC_TMEM_ADDR_RNG] flush_set; // Which set is currently being flushed 1.178 + 1.179 +genvar i, j; 1.180 + 1.181 +///////////////////////////////////////////////////// 1.182 +// Functions 1.183 +///////////////////////////////////////////////////// 1.184 + 1.185 +`include "lm32_functions.v" 1.186 + 1.187 +///////////////////////////////////////////////////// 1.188 +// Instantiations 1.189 +///////////////////////////////////////////////////// 1.190 + 1.191 + generate 1.192 + for (i = 0; i < associativity; i = i + 1) 1.193 + begin : memories 1.194 + // Way data 1.195 + if (`LM32_DC_DMEM_ADDR_WIDTH < 11) 1.196 + begin : data_memories 1.197 + lm32_ram 1.198 + #( 1.199 + // ----- Parameters ------- 1.200 + .data_width (32), 1.201 + .address_width (`LM32_DC_DMEM_ADDR_WIDTH) 1.202 +`ifdef PLATFORM_LATTICE 1.203 + , 1.204 + `ifdef CFG_DCACHE_DAT_USE_DP_TRUE 1.205 + .RAM_IMPLEMENTATION ("EBR"), 1.206 + .RAM_TYPE ("RAM_DP_TRUE") 1.207 + `else 1.208 + `ifdef CFG_DCACHE_DAT_USE_SLICE 1.209 + .RAM_IMPLEMENTATION ("SLICE") 1.210 + `else 1.211 + .RAM_IMPLEMENTATION ("AUTO") 1.212 + `endif 1.213 + `endif 1.214 +`endif 1.215 + ) way_0_data_ram 1.216 + ( 1.217 + // ----- Inputs ------- 1.218 + .read_clk (clk_i), 1.219 + .write_clk (clk_i), 1.220 + .reset (rst_i), 1.221 + .read_address (dmem_read_address), 1.222 + .enable_read (read_port_enable), 1.223 + .write_address (dmem_write_address), 1.224 + .enable_write (write_port_enable), 1.225 + .write_enable (way_dmem_we[i]), 1.226 + .write_data (dmem_write_data), 1.227 + // ----- Outputs ------- 1.228 + .read_data (way_data[i]) 1.229 + ); 1.230 + end 1.231 + else 1.232 + begin 1.233 + for (j = 0; j < 4; j = j + 1) 1.234 + begin : byte_memories 1.235 + lm32_ram 1.236 + #( 1.237 + // ----- Parameters ------- 1.238 + .data_width (8), 1.239 + .address_width (`LM32_DC_DMEM_ADDR_WIDTH) 1.240 +`ifdef PLATFORM_LATTICE 1.241 + , 1.242 + `ifdef CFG_DCACHE_DAT_USE_DP_TRUE 1.243 + .RAM_IMPLEMENTATION ("EBR"), 1.244 + .RAM_TYPE ("RAM_DP_TRUE") 1.245 + `else 1.246 + `ifdef CFG_DCACHE_DAT_USE_SLICE 1.247 + .RAM_IMPLEMENTATION ("SLICE") 1.248 + `else 1.249 + .RAM_IMPLEMENTATION ("AUTO") 1.250 + `endif 1.251 + `endif 1.252 +`endif 1.253 + ) way_0_data_ram 1.254 + ( 1.255 + // ----- Inputs ------- 1.256 + .read_clk (clk_i), 1.257 + .write_clk (clk_i), 1.258 + .reset (rst_i), 1.259 + .read_address (dmem_read_address), 1.260 + .enable_read (read_port_enable), 1.261 + .write_address (dmem_write_address), 1.262 + .enable_write (write_port_enable), 1.263 + .write_enable (way_dmem_we[i] & (store_byte_select[j] | refill)), 1.264 + .write_data (dmem_write_data[(j+1)*8-1:j*8]), 1.265 + // ----- Outputs ------- 1.266 + .read_data (way_data[i][(j+1)*8-1:j*8]) 1.267 + ); 1.268 + end 1.269 + end 1.270 + 1.271 + // Way tags 1.272 + lm32_ram 1.273 + #( 1.274 + // ----- Parameters ------- 1.275 + .data_width (`LM32_DC_TAGS_WIDTH), 1.276 + .address_width (`LM32_DC_TMEM_ADDR_WIDTH) 1.277 +`ifdef PLATFORM_LATTICE 1.278 + , 1.279 + `ifdef CFG_DCACHE_DAT_USE_DP_TRUE 1.280 + .RAM_IMPLEMENTATION ("EBR"), 1.281 + .RAM_TYPE ("RAM_DP_TRUE") 1.282 + `else 1.283 + `ifdef CFG_DCACHE_DAT_USE_SLICE 1.284 + .RAM_IMPLEMENTATION ("SLICE") 1.285 + `else 1.286 + .RAM_IMPLEMENTATION ("AUTO") 1.287 + `endif 1.288 + `endif 1.289 +`endif 1.290 + ) way_0_tag_ram 1.291 + ( 1.292 + // ----- Inputs ------- 1.293 + .read_clk (clk_i), 1.294 + .write_clk (clk_i), 1.295 + .reset (rst_i), 1.296 + .read_address (tmem_read_address), 1.297 + .enable_read (read_port_enable), 1.298 + .write_address (tmem_write_address), 1.299 + .enable_write (`TRUE), 1.300 + .write_enable (way_tmem_we[i]), 1.301 + .write_data (tmem_write_data), 1.302 + // ----- Outputs ------- 1.303 + .read_data ({way_tag[i], way_valid[i]}) 1.304 + ); 1.305 + end 1.306 + 1.307 + endgenerate 1.308 + 1.309 +///////////////////////////////////////////////////// 1.310 +// Combinational logic 1.311 +///////////////////////////////////////////////////// 1.312 + 1.313 +// Compute which ways in the cache match the address being read 1.314 +generate 1.315 + for (i = 0; i < associativity; i = i + 1) 1.316 + begin : match 1.317 +assign way_match[i] = ({way_tag[i], way_valid[i]} == {address_m[`LM32_DC_ADDR_TAG_RNG], `TRUE}); 1.318 + end 1.319 +endgenerate 1.320 + 1.321 +// Select data from way that matched the address being read 1.322 +generate 1.323 + if (associativity == 1) 1.324 + begin : data_1 1.325 +assign load_data = way_data[0]; 1.326 + end 1.327 + else if (associativity == 2) 1.328 + begin : data_2 1.329 +assign load_data = way_match[0] ? way_data[0] : way_data[1]; 1.330 + end 1.331 +endgenerate 1.332 + 1.333 +generate 1.334 + if (`LM32_DC_DMEM_ADDR_WIDTH < 11) 1.335 + begin 1.336 +// Select data to write to data memories 1.337 +always @(*) 1.338 +begin 1.339 + if (refill == `TRUE) 1.340 + dmem_write_data = refill_data; 1.341 + else 1.342 + begin 1.343 + dmem_write_data[`LM32_BYTE_0_RNG] = store_byte_select[0] ? store_data[`LM32_BYTE_0_RNG] : load_data[`LM32_BYTE_0_RNG]; 1.344 + dmem_write_data[`LM32_BYTE_1_RNG] = store_byte_select[1] ? store_data[`LM32_BYTE_1_RNG] : load_data[`LM32_BYTE_1_RNG]; 1.345 + dmem_write_data[`LM32_BYTE_2_RNG] = store_byte_select[2] ? store_data[`LM32_BYTE_2_RNG] : load_data[`LM32_BYTE_2_RNG]; 1.346 + dmem_write_data[`LM32_BYTE_3_RNG] = store_byte_select[3] ? store_data[`LM32_BYTE_3_RNG] : load_data[`LM32_BYTE_3_RNG]; 1.347 + end 1.348 +end 1.349 + end 1.350 + else 1.351 + begin 1.352 +// Select data to write to data memories - FIXME: Should use different write ports on dual port RAMs, but they don't work 1.353 +always @(*) 1.354 +begin 1.355 + if (refill == `TRUE) 1.356 + dmem_write_data = refill_data; 1.357 + else 1.358 + dmem_write_data = store_data; 1.359 +end 1.360 + end 1.361 +endgenerate 1.362 + 1.363 +// Compute address to use to index into the data memories 1.364 +generate 1.365 + if (bytes_per_line > 4) 1.366 +assign dmem_write_address = (refill == `TRUE) 1.367 + ? {refill_address[`LM32_DC_ADDR_SET_RNG], refill_offset} 1.368 + : address_m[`LM32_DC_ADDR_IDX_RNG]; 1.369 + else 1.370 +assign dmem_write_address = (refill == `TRUE) 1.371 + ? refill_address[`LM32_DC_ADDR_SET_RNG] 1.372 + : address_m[`LM32_DC_ADDR_IDX_RNG]; 1.373 +endgenerate 1.374 +assign dmem_read_address = address_x[`LM32_DC_ADDR_IDX_RNG]; 1.375 +// Compute address to use to index into the tag memories 1.376 +assign tmem_write_address = (flushing == `TRUE) 1.377 + ? flush_set 1.378 + : refill_address[`LM32_DC_ADDR_SET_RNG]; 1.379 +assign tmem_read_address = address_x[`LM32_DC_ADDR_SET_RNG]; 1.380 + 1.381 +// Compute signal to indicate when we are on the last refill accesses 1.382 +generate 1.383 + if (bytes_per_line > 4) 1.384 +assign last_refill = refill_offset == {addr_offset_width{1'b1}}; 1.385 + else 1.386 +assign last_refill = `TRUE; 1.387 +endgenerate 1.388 + 1.389 +// Compute data and tag memory access enable 1.390 +assign read_port_enable = (stall_x == `FALSE); 1.391 +assign write_port_enable = (refill_ready == `TRUE) || !stall_m; 1.392 + 1.393 +// Determine when we have a valid store 1.394 +assign valid_store = (store_q_m == `TRUE) && (check == `TRUE); 1.395 + 1.396 +// Compute data and tag memory write enables 1.397 +generate 1.398 + if (associativity == 1) 1.399 + begin : we_1 1.400 +assign way_dmem_we[0] = (refill_ready == `TRUE) || ((valid_store == `TRUE) && (way_match[0] == `TRUE)); 1.401 +assign way_tmem_we[0] = (refill_ready == `TRUE) || (flushing == `TRUE); 1.402 + end 1.403 + else 1.404 + begin : we_2 1.405 +assign way_dmem_we[0] = ((refill_ready == `TRUE) && (refill_way_select[0] == `TRUE)) || ((valid_store == `TRUE) && (way_match[0] == `TRUE)); 1.406 +assign way_dmem_we[1] = ((refill_ready == `TRUE) && (refill_way_select[1] == `TRUE)) || ((valid_store == `TRUE) && (way_match[1] == `TRUE)); 1.407 +assign way_tmem_we[0] = ((refill_ready == `TRUE) && (refill_way_select[0] == `TRUE)) || (flushing == `TRUE); 1.408 +assign way_tmem_we[1] = ((refill_ready == `TRUE) && (refill_way_select[1] == `TRUE)) || (flushing == `TRUE); 1.409 + end 1.410 +endgenerate 1.411 + 1.412 +// On the last refill cycle set the valid bit, for all other writes it should be cleared 1.413 +assign tmem_write_data[`LM32_DC_TAGS_VALID_RNG] = ((last_refill == `TRUE) || (valid_store == `TRUE)) && (flushing == `FALSE); 1.414 +assign tmem_write_data[`LM32_DC_TAGS_TAG_RNG] = refill_address[`LM32_DC_ADDR_TAG_RNG]; 1.415 + 1.416 +// Signals that indicate which state we are in 1.417 +assign flushing = state[0]; 1.418 +assign check = state[1]; 1.419 +assign refill = state[2]; 1.420 + 1.421 +assign miss = (~(|way_match)) && (load_q_m == `TRUE) && (stall_m == `FALSE); 1.422 +assign stall_request = (check == `FALSE); 1.423 + 1.424 +///////////////////////////////////////////////////// 1.425 +// Sequential logic 1.426 +///////////////////////////////////////////////////// 1.427 + 1.428 +// Record way selected for replacement on a cache miss 1.429 +generate 1.430 + if (associativity >= 2) 1.431 + begin : way_select 1.432 +always @(posedge clk_i `CFG_RESET_SENSITIVITY) 1.433 +begin 1.434 + if (rst_i == `TRUE) 1.435 + refill_way_select <= {{associativity-1{1'b0}}, 1'b1}; 1.436 + else 1.437 + begin 1.438 + if (refill_request == `TRUE) 1.439 + refill_way_select <= {refill_way_select[0], refill_way_select[1]}; 1.440 + end 1.441 +end 1.442 + end 1.443 +endgenerate 1.444 + 1.445 +// Record whether we are currently refilling 1.446 +always @(posedge clk_i `CFG_RESET_SENSITIVITY) 1.447 +begin 1.448 + if (rst_i == `TRUE) 1.449 + refilling <= `FALSE; 1.450 + else 1.451 + refilling <= refill; 1.452 +end 1.453 + 1.454 +// Instruction cache control FSM 1.455 +always @(posedge clk_i `CFG_RESET_SENSITIVITY) 1.456 +begin 1.457 + if (rst_i == `TRUE) 1.458 + begin 1.459 + state <= `LM32_DC_STATE_FLUSH; 1.460 + flush_set <= {`LM32_DC_TMEM_ADDR_WIDTH{1'b1}}; 1.461 + refill_request <= `FALSE; 1.462 + refill_address <= {`LM32_WORD_WIDTH{1'bx}}; 1.463 + restart_request <= `FALSE; 1.464 + end 1.465 + else 1.466 + begin 1.467 + case (state) 1.468 + 1.469 + // Flush the cache 1.470 + `LM32_DC_STATE_FLUSH: 1.471 + begin 1.472 + if (flush_set == {`LM32_DC_TMEM_ADDR_WIDTH{1'b0}}) 1.473 + state <= `LM32_DC_STATE_CHECK; 1.474 + flush_set <= flush_set - 1'b1; 1.475 + end 1.476 + 1.477 + // Check for cache misses 1.478 + `LM32_DC_STATE_CHECK: 1.479 + begin 1.480 + if (stall_a == `FALSE) 1.481 + restart_request <= `FALSE; 1.482 + if (miss == `TRUE) 1.483 + begin 1.484 + refill_request <= `TRUE; 1.485 + refill_address <= address_m; 1.486 + state <= `LM32_DC_STATE_REFILL; 1.487 + end 1.488 + else if (dflush == `TRUE) 1.489 + state <= `LM32_DC_STATE_FLUSH; 1.490 + end 1.491 + 1.492 + // Refill a cache line 1.493 + `LM32_DC_STATE_REFILL: 1.494 + begin 1.495 + refill_request <= `FALSE; 1.496 + if (refill_ready == `TRUE) 1.497 + begin 1.498 + if (last_refill == `TRUE) 1.499 + begin 1.500 + restart_request <= `TRUE; 1.501 + state <= `LM32_DC_STATE_CHECK; 1.502 + end 1.503 + end 1.504 + end 1.505 + 1.506 + endcase 1.507 + end 1.508 +end 1.509 + 1.510 +generate 1.511 + if (bytes_per_line > 4) 1.512 + begin 1.513 +// Refill offset 1.514 +always @(posedge clk_i `CFG_RESET_SENSITIVITY) 1.515 +begin 1.516 + if (rst_i == `TRUE) 1.517 + refill_offset <= {addr_offset_width{1'b0}}; 1.518 + else 1.519 + begin 1.520 + case (state) 1.521 + 1.522 + // Check for cache misses 1.523 + `LM32_DC_STATE_CHECK: 1.524 + begin 1.525 + if (miss == `TRUE) 1.526 + refill_offset <= {addr_offset_width{1'b0}}; 1.527 + end 1.528 + 1.529 + // Refill a cache line 1.530 + `LM32_DC_STATE_REFILL: 1.531 + begin 1.532 + if (refill_ready == `TRUE) 1.533 + refill_offset <= refill_offset + 1'b1; 1.534 + end 1.535 + 1.536 + endcase 1.537 + end 1.538 +end 1.539 + end 1.540 +endgenerate 1.541 + 1.542 +endmodule 1.543 + 1.544 +`endif 1.545 +