ewrf32b18w.v 7.22 KB
/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/
// $Id: ewrf32b18w.v,v 1.4 2002/12/10 21:46:58 rws Exp $
   /////////////////////////////////////////////////////////////////////////
   //
   // Project Reality
   //
   // module:      ewrf32b18w
   // description: two 9-word by 32-bit register files.
   // 	       	   One for attributes and the other for da/de.
   // 	       	   Both has a read port and a write port.
   // 	       	   The one for da/de has a bypass feather.
   //
   // designer:    Mike M. Cai   6/28/94
   //
   /////////////////////////////////////////////////////////////////////////

module ewrf32b18w (  wa_data, wa_addr, wen_a, wde_data, wde_addr, wen_de,
      	       	     ra_addr, rb_addr, // ra_addr is for attribute
		     ra_data, rb_data, // rb_addr is for da/de
		     ew_stall_attr, start_gclk, clk);
input 	       ew_stall_attr, start_gclk, clk;
input 	       wen_a, wen_de;
input [3:0]    wa_addr;
input [3:0]    wde_addr;
input [31:0]   wa_data, wde_data;
input [3:0]    ra_addr, rb_addr;
output [31:0]  ra_data, rb_data;

reg [8:0]      ra_line, rb_line;
reg [8:0]      wa_line;
reg [8:0]      wde_line;
wire [8:0]     wa_line_wengclk, wde_line_wengclk; 
wire [31:0]    ra_data_m, rb_data_m;
// wire [31:0]    wa_data_delay;
reg [31:0]     rb_data_mm;
reg [31:0]     ra_data, rb_data;

// decode address this 
// read port a
always @(ra_addr)
   case (ra_addr)
      4'b0000:	  ra_line = 9'b000000001;
      4'b0001:	  ra_line = 9'b000000010;
      4'b0010:	  ra_line = 9'b000000100;
      4'b0011:	  ra_line = 9'b000001000;
      4'b0100:	  ra_line = 9'b000010000;
      4'b0101:	  ra_line = 9'b000100000;
      4'b0110:	  ra_line = 9'b001000000;
      4'b0111:	  ra_line = 9'b010000000;
      4'b1000:	  ra_line = 9'b100000000;
      default: 	  ra_line = 9'b100000000;
   endcase

// read port b
always @(rb_addr)
   case (rb_addr)
      4'b0000:	  rb_line = 9'b000000001;
      4'b0001:	  rb_line = 9'b000000010;
      4'b0010:	  rb_line = 9'b000000100;
      4'b0011:	  rb_line = 9'b000001000;
      4'b0100:	  rb_line = 9'b000010000;
      4'b0101:	  rb_line = 9'b000100000;
      4'b0110:	  rb_line = 9'b001000000;
      4'b0111:	  rb_line = 9'b010000000;
      4'b1000:	  rb_line = 9'b100000000;
      default: 	  rb_line = 9'b100000000;
   endcase

// write port for attributes
always @(wa_addr)
   case (wa_addr)
      4'b0000:     wa_line = 9'h001;
      4'b0001:     wa_line = 9'h002;
      4'b0010:     wa_line = 9'h004;
      4'b0011:     wa_line = 9'h008;
      4'b0100:     wa_line = 9'h010;
      4'b0101:     wa_line = 9'h020;
      4'b0110:     wa_line = 9'h040;
      4'b0111:     wa_line = 9'h080;
      4'b1000:     wa_line = 9'h100;
      default: 	   wa_line = 9'h100; 
   endcase
assign  wa_line_wengclk = wa_line & {9{wen_a}};

// write port for da/de
always @(wde_addr)
   casez (wde_addr)
      4'b0000: 	  wde_line = 9'h001;   
      4'b0001: 	  wde_line = 9'h002;   
      4'b0010: 	  wde_line = 9'h004;   
      4'b0011: 	  wde_line = 9'h008;   
      4'b0100: 	  wde_line = 9'h010;   
      4'b0101: 	  wde_line = 9'h020;   
      4'b0110: 	  wde_line = 9'h040;   
      4'b0111: 	  wde_line = 9'h080;   
      4'b1000: 	  wde_line = 9'h100;
      default: 	  wde_line = 9'h100;
   endcase
   
assign  wde_line_wengclk = wde_line & {9{wen_de}};

// ewrfdelay delaywdata(.out_data(wa_data_delay), .in_data(wa_data));

	reg [31:0] ra_data0;
	reg [31:0] ra_data1;
	reg [31:0] ra_data2;
	reg [31:0] ra_data3;
	reg [31:0] ra_data4;
	reg [31:0] ra_data5;
	reg [31:0] ra_data6;
	reg [31:0] ra_data7;
	reg [31:0] ra_data8;
	reg [31:0] rb_data0;
	reg [31:0] rb_data1;
	reg [31:0] rb_data2;
	reg [31:0] rb_data3;
	reg [31:0] rb_data4;
	reg [31:0] rb_data5;
	reg [31:0] rb_data6;
	reg [31:0] rb_data7;
	reg [31:0] rb_data8;

	wire [31:0] nxt_ra_data0 = wa_line_wengclk[0] ? wa_data : ra_data0;
	wire [31:0] nxt_ra_data1 = wa_line_wengclk[1] ? wa_data : ra_data1;
	wire [31:0] nxt_ra_data2 = wa_line_wengclk[2] ? wa_data : ra_data2;
	wire [31:0] nxt_ra_data3 = wa_line_wengclk[3] ? wa_data : ra_data3;
	wire [31:0] nxt_ra_data4 = wa_line_wengclk[4] ? wa_data : ra_data4;
	wire [31:0] nxt_ra_data5 = wa_line_wengclk[5] ? wa_data : ra_data5;
	wire [31:0] nxt_ra_data6 = wa_line_wengclk[6] ? wa_data : ra_data6;
	wire [31:0] nxt_ra_data7 = wa_line_wengclk[7] ? wa_data : ra_data7;
	wire [31:0] nxt_ra_data8 = wa_line_wengclk[8] ? wa_data : ra_data8;

	wire [31:0] nxt_rb_data0 = wde_line_wengclk[0] ? wde_data : rb_data0;
	wire [31:0] nxt_rb_data1 = wde_line_wengclk[1] ? wde_data : rb_data1;
	wire [31:0] nxt_rb_data2 = wde_line_wengclk[2] ? wde_data : rb_data2;
	wire [31:0] nxt_rb_data3 = wde_line_wengclk[3] ? wde_data : rb_data3;
	wire [31:0] nxt_rb_data4 = wde_line_wengclk[4] ? wde_data : rb_data4;
	wire [31:0] nxt_rb_data5 = wde_line_wengclk[5] ? wde_data : rb_data5;
	wire [31:0] nxt_rb_data6 = wde_line_wengclk[6] ? wde_data : rb_data6;
	wire [31:0] nxt_rb_data7 = wde_line_wengclk[7] ? wde_data : rb_data7;
	wire [31:0] nxt_rb_data8 = wde_line_wengclk[8] ? wde_data : rb_data8;

	always @(negedge clk) begin
	  if (start_gclk) begin
		ra_data0 <= nxt_ra_data0;
		ra_data1 <= nxt_ra_data1;
		ra_data2 <= nxt_ra_data2;
		ra_data3 <= nxt_ra_data3;
		ra_data4 <= nxt_ra_data4;
		ra_data5 <= nxt_ra_data5;
		ra_data6 <= nxt_ra_data6;
		ra_data7 <= nxt_ra_data7;
		ra_data8 <= nxt_ra_data8;
		ra_data8 <= nxt_ra_data8;
		rb_data0 <= nxt_rb_data0;
		rb_data1 <= nxt_rb_data1;
		rb_data2 <= nxt_rb_data2;
		rb_data3 <= nxt_rb_data3;
		rb_data4 <= nxt_rb_data4;
		rb_data5 <= nxt_rb_data5;
		rb_data6 <= nxt_rb_data6;
		rb_data7 <= nxt_rb_data7;
		rb_data8 <= nxt_rb_data8;
	  end
	end

	assign ra_data_m = {32{ra_line[0]}} & ra_data0
			 | {32{ra_line[1]}} & ra_data1
			 | {32{ra_line[2]}} & ra_data2
			 | {32{ra_line[3]}} & ra_data3
			 | {32{ra_line[4]}} & ra_data4
			 | {32{ra_line[5]}} & ra_data5
			 | {32{ra_line[6]}} & ra_data6
			 | {32{ra_line[7]}} & ra_data7
			 | {32{ra_line[8]}} & ra_data8;

	assign rb_data_m = {32{rb_line[0]}} & rb_data0
			 | {32{rb_line[1]}} & rb_data1
			 | {32{rb_line[2]}} & rb_data2
			 | {32{rb_line[3]}} & rb_data3
			 | {32{rb_line[4]}} & rb_data4
			 | {32{rb_line[5]}} & rb_data5
			 | {32{rb_line[6]}} & rb_data6
			 | {32{rb_line[7]}} & rb_data7
			 | {32{rb_line[8]}} & rb_data8;

always @(posedge clk)
   if (start_gclk) begin
      if ((rb_addr == wde_addr) && wen_de)
      	 rb_data_mm = wde_data;
      else
      	 rb_data_mm = rb_data_m;
      ra_data <= ew_stall_attr ? ra_data : ra_data_m;
      rb_data <= ew_stall_attr ? rb_data : rb_data_mm;
   end

endmodule  //  ewrf32b18w