data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v
1: b"%Error: data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v:229: Define or directive not defined: '`PA_WIDTH'\nassign arb_snq_snoop_addr[`PA_WIDTH-1:0] = biu_lsu_ac_addr[`PA_WIDTH-1:0];\n                          ^~~~~~~~~\n%Error: data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v:229: Define or directive not defined: '`PA_WIDTH'\nassign arb_snq_snoop_addr[`PA_WIDTH-1:0] = biu_lsu_ac_addr[`PA_WIDTH-1:0];\n                                                           ^~~~~~~~~\n%Error: data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v:253: Define or directive not defined: '`PA_WIDTH'\nassign arb_ctcq_ctc_asid_va[`PA_WIDTH-17:0] = biu_lsu_ac_addr[`PA_WIDTH-1:16];  \n                            ^~~~~~~~~\n%Error: data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v:253: Define or directive not defined: '`PA_WIDTH'\nassign arb_ctcq_ctc_asid_va[`PA_WIDTH-17:0] = biu_lsu_ac_addr[`PA_WIDTH-1:16];  \n                                                              ^~~~~~~~~\n%Error: data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v:255: Define or directive not defined: '`PA_WIDTH'\nassign arb_ctcq_ctc_va_pa[`PA_WIDTH-5:0]    = biu_lsu_ac_addr[`PA_WIDTH-1:4];   \n                          ^~~~~~~~~\n%Error: data/full_repos/permissive/418752214/C910_RTL_FACTORY/gen_rtl/lsu/rtl/ct_lsu_snoop_req_arbiter.v:255: Define or directive not defined: '`PA_WIDTH'\nassign arb_ctcq_ctc_va_pa[`PA_WIDTH-5:0]    = biu_lsu_ac_addr[`PA_WIDTH-1:4];   \n                                                              ^~~~~~~~~\n%Error: Exiting due to 6 error(s)\n"
module ct_lsu_snoop_req_arbiter(
  arb_ctcq_ctc_2nd_trans,
  arb_ctcq_ctc_asid_va,
  arb_ctcq_ctc_type,
  arb_ctcq_ctc_va_pa,
  arb_ctcq_entry_oldest_index,
  arb_snq_entry_oldest_index,
  arb_snq_snoop_addr,
  arb_snq_snoop_depd,
  arb_snq_snoop_prot,
  arb_snq_snoop_type,
  biu_lsu_ac_addr,
  biu_lsu_ac_prot,
  biu_lsu_ac_req,
  biu_lsu_ac_snoop,
  biu_lsu_cr_resp_acept,
  biu_lsu_ctc_req,
  cp0_lsu_icg_en,
  cpurst_b,
  ctc_req_create_en,
  ctcq_biu_2_cmplt,
  ctcq_biu_cr_valid,
  cur_ctcq_entry_empty,
  cur_snq_entry_empty,
  forever_cpuclk,
  icc_snq_create_permit,
  lm_snq_stall,
  lsu_biu_ac_empty,
  lsu_biu_ac_ready,
  lsu_ctcq_not_empty,
  lsu_sdb_not_empty,
  lsu_snoop_clk,
  lsu_snq_not_empty,
  pad_yy_icg_scan_en,
  snoop_req_create_en,
  snq_biu_cr_valid,
  vb_snq_depd,
  wmb_snq_depd
);


input   [39:0]  biu_lsu_ac_addr;            
input   [2 :0]  biu_lsu_ac_prot;            
input           biu_lsu_ac_req;             
input   [3 :0]  biu_lsu_ac_snoop;           
input           biu_lsu_cr_resp_acept;      
input           cp0_lsu_icg_en;             
input           cpurst_b;                   
input           ctcq_biu_2_cmplt;           
input           ctcq_biu_cr_valid;          
input           cur_ctcq_entry_empty;       
input           cur_snq_entry_empty;        
input           forever_cpuclk;             
input           icc_snq_create_permit;      
input           lm_snq_stall;               
input           lsu_ctcq_not_empty;         
input           lsu_sdb_not_empty;          
input           lsu_snq_not_empty;          
input           pad_yy_icg_scan_en;         
input           snq_biu_cr_valid;           
input   [1 :0]  vb_snq_depd;                
input   [7 :0]  wmb_snq_depd;               
output          arb_ctcq_ctc_2nd_trans;     
output  [23:0]  arb_ctcq_ctc_asid_va;       
output  [5 :0]  arb_ctcq_ctc_type;          
output  [35:0]  arb_ctcq_ctc_va_pa;         
output  [5 :0]  arb_ctcq_entry_oldest_index; 
output  [5 :0]  arb_snq_entry_oldest_index; 
output  [39:0]  arb_snq_snoop_addr;         
output  [9 :0]  arb_snq_snoop_depd;         
output  [2 :0]  arb_snq_snoop_prot;         
output  [3 :0]  arb_snq_snoop_type;         
output          biu_lsu_ctc_req;            
output          ctc_req_create_en;          
output          lsu_biu_ac_empty;           
output          lsu_biu_ac_ready;           
output          lsu_snoop_clk;              
output          snoop_req_create_en;        


reg     [4 :0]  coq_create_ptr;             
reg     [4 :0]  coq_pop_ptr;                
reg     [17:0]  create_order_source;        
reg     [5 :0]  ctcq_entry_oldest_index;    
reg     [5 :0]  snq_entry_oldest_index;     


wire            arb_ctcq_ctc_2nd_trans;     
wire    [23:0]  arb_ctcq_ctc_asid_va;       
wire    [5 :0]  arb_ctcq_ctc_type;          
wire    [35:0]  arb_ctcq_ctc_va_pa;         
wire    [5 :0]  arb_ctcq_entry_oldest_index; 
wire    [5 :0]  arb_snq_entry_oldest_index; 
wire    [39:0]  arb_snq_snoop_addr;         
wire    [9 :0]  arb_snq_snoop_depd;         
wire    [2 :0]  arb_snq_snoop_prot;         
wire    [3 :0]  arb_snq_snoop_type;         
wire    [39:0]  biu_lsu_ac_addr;            
wire    [2 :0]  biu_lsu_ac_prot;            
wire            biu_lsu_ac_req;             
wire    [3 :0]  biu_lsu_ac_snoop;           
wire            biu_lsu_cr_resp_acept;      
wire            biu_lsu_ctc_req;            
wire            biu_lsu_snp_req;            
wire            coq_create_max;             
wire            coq_pop_max;                
wire            cp0_lsu_icg_en;             
wire            cpurst_b;                   
wire            ctc_req_aft_check;          
wire            ctc_req_create_en;          
wire            ctcq_biu_2_cmplt;           
wire            ctcq_biu_cr_valid;          
wire            cur_ctcq_entry_empty;       
wire            cur_snq_entry_empty;        
wire            forever_cpuclk;             
wire            icc_snq_create_permit;      
wire            lm_snq_stall;               
wire            lsu_biu_ac_empty;           
wire            lsu_biu_ac_ready;           
wire            lsu_ctcq_not_empty;         
wire            lsu_sdb_not_empty;          
wire            lsu_snoop_clk;              
wire            lsu_snoop_clk_en;           
wire            lsu_snq_not_empty;          
wire            pad_yy_icg_scan_en;         
wire            snoop_req_aft_check;        
wire            snoop_req_create_en;        
wire            snp_create_clk_en;          
wire            snp_ctcq_clk_en;            
wire            snp_pop_clk_en;             
wire            snp_snq_clk_en;             
wire            snpcrtclk;                  
wire            snpindexclk0;               
wire            snpindexclk1;               
wire            snppopclk;                  
wire            snq_biu_cr_valid;           
wire    [1 :0]  vb_snq_depd;                
wire    [7 :0]  wmb_snq_depd;               


assign lsu_snoop_clk_en =  biu_lsu_ac_req
                        || lsu_snq_not_empty
                        || lsu_sdb_not_empty
                        || lsu_ctcq_not_empty; 


gated_clk_cell  x_lsu_snoop_clk (
  .clk_in             (forever_cpuclk    ),
  .clk_out            (lsu_snoop_clk     ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (lsu_snoop_clk_en  ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);





















assign snoop_req_create_en = snoop_req_aft_check && lsu_biu_ac_ready;
assign ctc_req_create_en   = ctc_req_aft_check   && lsu_biu_ac_ready;

assign snoop_req_aft_check =   biu_lsu_snp_req
                           &&  icc_snq_create_permit

                           &&  !lm_snq_stall
                           &&  cur_snq_entry_empty;

assign ctc_req_aft_check   =   biu_lsu_ctc_req
                           &&  cur_ctcq_entry_empty;

assign biu_lsu_snp_req  =   biu_lsu_ac_req
                        && !biu_lsu_ctc_req;

assign biu_lsu_ctc_req  =   biu_lsu_ac_req 
                        &&  biu_lsu_ac_snoop[3:0] == 4'b1111;


assign lsu_biu_ac_ready =  ((cur_snq_entry_empty && biu_lsu_snp_req) || (cur_ctcq_entry_empty && biu_lsu_ctc_req))

                        && !lm_snq_stall
                        && icc_snq_create_permit;


assign lsu_biu_ac_empty = !lsu_snoop_clk_en;










assign arb_snq_snoop_depd[9:0] = {wmb_snq_depd[7:0], vb_snq_depd[1:0]};
assign arb_snq_snoop_type[3:0]  = biu_lsu_ac_snoop[3:0];
assign arb_snq_snoop_addr[`PA_WIDTH-1:0] = biu_lsu_ac_addr[`PA_WIDTH-1:0];
assign arb_snq_snoop_prot[2:0]  = biu_lsu_ac_prot[2:0];



















assign arb_ctcq_ctc_type[5:0]     = {biu_lsu_ac_addr[14:12]
                                    ,biu_lsu_ac_addr[6:5]
                                    ,biu_lsu_ac_addr[0]};
assign arb_ctcq_ctc_asid_va[`PA_WIDTH-17:0] = biu_lsu_ac_addr[`PA_WIDTH-1:16];
assign arb_ctcq_ctc_2nd_trans               = biu_lsu_ac_addr[0];
assign arb_ctcq_ctc_va_pa[`PA_WIDTH-5:0]    = biu_lsu_ac_addr[`PA_WIDTH-1:4];














assign coq_create_max = (coq_create_ptr[4:0] == 5'd17);
assign coq_pop_max    = (coq_pop_ptr[4:0] == 5'd17);

parameter COQ_ENTRY = 18;
always @(posedge snpcrtclk or negedge cpurst_b)
begin
  if(~cpurst_b)
    coq_create_ptr[4:0] <= 5'b0;
  else if(snoop_req_create_en || ctc_req_create_en)
  begin
    if(coq_create_max)
      coq_create_ptr[4:0] <= 5'b0;
    else
      coq_create_ptr[4:0] <= coq_create_ptr[4:0] + 5'b1;
  end
end

always @(posedge snppopclk or negedge cpurst_b)
begin
  if(~cpurst_b)
    coq_pop_ptr[4:0] <= 5'b0;
  else if(biu_lsu_cr_resp_acept)
  begin
    if(coq_pop_max)
      coq_pop_ptr[4:0] <= 5'b0;
    else
      coq_pop_ptr[4:0] <= coq_pop_ptr[4:0] + 5'b1;
  end
end
integer i;

always @(posedge snpcrtclk or negedge cpurst_b)
begin
  if(~cpurst_b)
  begin
   for(i=0;i<COQ_ENTRY;i=i+1)
     create_order_source[i] <= 1'b0;
  end
  else
  begin
    for(i=0;i<COQ_ENTRY;i=i+1)
    begin
      if(snoop_req_create_en && (coq_create_ptr[4:0] == i))
        create_order_source[i]  <= 1'b0;
      else if(ctc_req_create_en && (coq_create_ptr[4:0] == i))
        create_order_source[i]  <= 1'b1;
      else
        create_order_source[i]  <= create_order_source[i];
    end
  end
end

always @(posedge snpindexclk0 or negedge cpurst_b)
begin
  if(~cpurst_b)
    snq_entry_oldest_index[5:0] <= 6'b000001;
  else if(biu_lsu_cr_resp_acept && snq_biu_cr_valid)
    snq_entry_oldest_index[5:0] <= {snq_entry_oldest_index[4:0],snq_entry_oldest_index[5]};
end
always @(posedge snpindexclk1 or negedge cpurst_b)
begin
  if(~cpurst_b)
    ctcq_entry_oldest_index[5:0] <= 6'b000001;
  else if(biu_lsu_cr_resp_acept && ctcq_biu_cr_valid && !ctcq_biu_2_cmplt)
    ctcq_entry_oldest_index[5:0] <= {ctcq_entry_oldest_index[4:0],ctcq_entry_oldest_index[5]};
end



assign arb_snq_entry_oldest_index[5:0]  = snq_entry_oldest_index[5:0]
                                        & {6{~create_order_source[coq_pop_ptr[4:0]]}};

assign arb_ctcq_entry_oldest_index[5:0] = ctcq_entry_oldest_index[5:0]
                                        & {6{create_order_source[coq_pop_ptr[4:0]]}};





assign snp_create_clk_en =  snoop_req_create_en
                         || ctc_req_create_en;


gated_clk_cell  x_snp_create_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snpcrtclk         ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_create_clk_en ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);









assign snp_pop_clk_en = snq_biu_cr_valid || ctcq_biu_cr_valid;

gated_clk_cell  x_snp_pop_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snppopclk         ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_pop_clk_en    ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);









assign snp_snq_clk_en = snq_biu_cr_valid;

gated_clk_cell  x_snp_snq_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snpindexclk0      ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_snq_clk_en    ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);









assign snp_ctcq_clk_en = ctcq_biu_cr_valid && !ctcq_biu_2_cmplt;

gated_clk_cell  x_snp_ctcq_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snpindexclk1      ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_ctcq_clk_en   ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);











endmodule
module ct_lsu_snoop_req_arbiter(
  arb_ctcq_ctc_2nd_trans,
  arb_ctcq_ctc_asid_va,
  arb_ctcq_ctc_type,
  arb_ctcq_ctc_va_pa,
  arb_ctcq_entry_oldest_index,
  arb_snq_entry_oldest_index,
  arb_snq_snoop_addr,
  arb_snq_snoop_depd,
  arb_snq_snoop_prot,
  arb_snq_snoop_type,
  biu_lsu_ac_addr,
  biu_lsu_ac_prot,
  biu_lsu_ac_req,
  biu_lsu_ac_snoop,
  biu_lsu_cr_resp_acept,
  biu_lsu_ctc_req,
  cp0_lsu_icg_en,
  cpurst_b,
  ctc_req_create_en,
  ctcq_biu_2_cmplt,
  ctcq_biu_cr_valid,
  cur_ctcq_entry_empty,
  cur_snq_entry_empty,
  forever_cpuclk,
  icc_snq_create_permit,
  lm_snq_stall,
  lsu_biu_ac_empty,
  lsu_biu_ac_ready,
  lsu_ctcq_not_empty,
  lsu_sdb_not_empty,
  lsu_snoop_clk,
  lsu_snq_not_empty,
  pad_yy_icg_scan_en,
  snoop_req_create_en,
  snq_biu_cr_valid,
  vb_snq_depd,
  wmb_snq_depd
);



input   [39:0]  biu_lsu_ac_addr;            
input   [2 :0]  biu_lsu_ac_prot;            
input           biu_lsu_ac_req;             
input   [3 :0]  biu_lsu_ac_snoop;           
input           biu_lsu_cr_resp_acept;      
input           cp0_lsu_icg_en;             
input           cpurst_b;                   
input           ctcq_biu_2_cmplt;           
input           ctcq_biu_cr_valid;          
input           cur_ctcq_entry_empty;       
input           cur_snq_entry_empty;        
input           forever_cpuclk;             
input           icc_snq_create_permit;      
input           lm_snq_stall;               
input           lsu_ctcq_not_empty;         
input           lsu_sdb_not_empty;          
input           lsu_snq_not_empty;          
input           pad_yy_icg_scan_en;         
input           snq_biu_cr_valid;           
input   [1 :0]  vb_snq_depd;                
input   [7 :0]  wmb_snq_depd;               
output          arb_ctcq_ctc_2nd_trans;     
output  [23:0]  arb_ctcq_ctc_asid_va;       
output  [5 :0]  arb_ctcq_ctc_type;          
output  [35:0]  arb_ctcq_ctc_va_pa;         
output  [5 :0]  arb_ctcq_entry_oldest_index; 
output  [5 :0]  arb_snq_entry_oldest_index; 
output  [39:0]  arb_snq_snoop_addr;         
output  [9 :0]  arb_snq_snoop_depd;         
output  [2 :0]  arb_snq_snoop_prot;         
output  [3 :0]  arb_snq_snoop_type;         
output          biu_lsu_ctc_req;            
output          ctc_req_create_en;          
output          lsu_biu_ac_empty;           
output          lsu_biu_ac_ready;           
output          lsu_snoop_clk;              
output          snoop_req_create_en;        


reg     [4 :0]  coq_create_ptr;             
reg     [4 :0]  coq_pop_ptr;                
reg     [17:0]  create_order_source;        
reg     [5 :0]  ctcq_entry_oldest_index;    
reg     [5 :0]  snq_entry_oldest_index;     


wire            arb_ctcq_ctc_2nd_trans;     
wire    [23:0]  arb_ctcq_ctc_asid_va;       
wire    [5 :0]  arb_ctcq_ctc_type;          
wire    [35:0]  arb_ctcq_ctc_va_pa;         
wire    [5 :0]  arb_ctcq_entry_oldest_index; 
wire    [5 :0]  arb_snq_entry_oldest_index; 
wire    [39:0]  arb_snq_snoop_addr;         
wire    [9 :0]  arb_snq_snoop_depd;         
wire    [2 :0]  arb_snq_snoop_prot;         
wire    [3 :0]  arb_snq_snoop_type;         
wire    [39:0]  biu_lsu_ac_addr;            
wire    [2 :0]  biu_lsu_ac_prot;            
wire            biu_lsu_ac_req;             
wire    [3 :0]  biu_lsu_ac_snoop;           
wire            biu_lsu_cr_resp_acept;      
wire            biu_lsu_ctc_req;            
wire            biu_lsu_snp_req;            
wire            coq_create_max;             
wire            coq_pop_max;                
wire            cp0_lsu_icg_en;             
wire            cpurst_b;                   
wire            ctc_req_aft_check;          
wire            ctc_req_create_en;          
wire            ctcq_biu_2_cmplt;           
wire            ctcq_biu_cr_valid;          
wire            cur_ctcq_entry_empty;       
wire            cur_snq_entry_empty;        
wire            forever_cpuclk;             
wire            icc_snq_create_permit;      
wire            lm_snq_stall;               
wire            lsu_biu_ac_empty;           
wire            lsu_biu_ac_ready;           
wire            lsu_ctcq_not_empty;         
wire            lsu_sdb_not_empty;          
wire            lsu_snoop_clk;              
wire            lsu_snoop_clk_en;           
wire            lsu_snq_not_empty;          
wire            pad_yy_icg_scan_en;         
wire            snoop_req_aft_check;        
wire            snoop_req_create_en;        
wire            snp_create_clk_en;          
wire            snp_ctcq_clk_en;            
wire            snp_pop_clk_en;             
wire            snp_snq_clk_en;             
wire            snpcrtclk;                  
wire            snpindexclk0;               
wire            snpindexclk1;               
wire            snppopclk;                  
wire            snq_biu_cr_valid;           
wire    [1 :0]  vb_snq_depd;                
wire    [7 :0]  wmb_snq_depd;               


assign lsu_snoop_clk_en =  biu_lsu_ac_req
                        || lsu_snq_not_empty
                        || lsu_sdb_not_empty
                        || lsu_ctcq_not_empty; 


gated_clk_cell  x_lsu_snoop_clk (
  .clk_in             (forever_cpuclk    ),
  .clk_out            (lsu_snoop_clk     ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (lsu_snoop_clk_en  ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);





















assign snoop_req_create_en = snoop_req_aft_check && lsu_biu_ac_ready;
assign ctc_req_create_en   = ctc_req_aft_check   && lsu_biu_ac_ready;

assign snoop_req_aft_check =   biu_lsu_snp_req
                           &&  icc_snq_create_permit

                           &&  !lm_snq_stall
                           &&  cur_snq_entry_empty;

assign ctc_req_aft_check   =   biu_lsu_ctc_req
                           &&  cur_ctcq_entry_empty;

assign biu_lsu_snp_req  =   biu_lsu_ac_req
                        && !biu_lsu_ctc_req;

assign biu_lsu_ctc_req  =   biu_lsu_ac_req 
                        &&  biu_lsu_ac_snoop[3:0] == 4'b1111;


assign lsu_biu_ac_ready =  ((cur_snq_entry_empty && biu_lsu_snp_req) || (cur_ctcq_entry_empty && biu_lsu_ctc_req))

                        && !lm_snq_stall
                        && icc_snq_create_permit;


assign lsu_biu_ac_empty = !lsu_snoop_clk_en;










assign arb_snq_snoop_depd[9:0] = {wmb_snq_depd[7:0], vb_snq_depd[1:0]};
assign arb_snq_snoop_type[3:0]  = biu_lsu_ac_snoop[3:0];
assign arb_snq_snoop_addr[`PA_WIDTH-1:0] = biu_lsu_ac_addr[`PA_WIDTH-1:0];
assign arb_snq_snoop_prot[2:0]  = biu_lsu_ac_prot[2:0];



















assign arb_ctcq_ctc_type[5:0]     = {biu_lsu_ac_addr[14:12]
                                    ,biu_lsu_ac_addr[6:5]
                                    ,biu_lsu_ac_addr[0]};
assign arb_ctcq_ctc_asid_va[`PA_WIDTH-17:0] = biu_lsu_ac_addr[`PA_WIDTH-1:16];
assign arb_ctcq_ctc_2nd_trans               = biu_lsu_ac_addr[0];
assign arb_ctcq_ctc_va_pa[`PA_WIDTH-5:0]    = biu_lsu_ac_addr[`PA_WIDTH-1:4];














assign coq_create_max = (coq_create_ptr[4:0] == 5'd17);
assign coq_pop_max    = (coq_pop_ptr[4:0] == 5'd17);

parameter COQ_ENTRY = 18;
always @(posedge snpcrtclk or negedge cpurst_b)
begin
  if(~cpurst_b)
    coq_create_ptr[4:0] <= 5'b0;
  else if(snoop_req_create_en || ctc_req_create_en)
  begin
    if(coq_create_max)
      coq_create_ptr[4:0] <= 5'b0;
    else
      coq_create_ptr[4:0] <= coq_create_ptr[4:0] + 5'b1;
  end
end

always @(posedge snppopclk or negedge cpurst_b)
begin
  if(~cpurst_b)
    coq_pop_ptr[4:0] <= 5'b0;
  else if(biu_lsu_cr_resp_acept)
  begin
    if(coq_pop_max)
      coq_pop_ptr[4:0] <= 5'b0;
    else
      coq_pop_ptr[4:0] <= coq_pop_ptr[4:0] + 5'b1;
  end
end
integer i;

always @(posedge snpcrtclk or negedge cpurst_b)
begin
  if(~cpurst_b)
  begin
   for(i=0;i<COQ_ENTRY;i=i+1)
     create_order_source[i] <= 1'b0;
  end
  else
  begin
    for(i=0;i<COQ_ENTRY;i=i+1)
    begin
      if(snoop_req_create_en && (coq_create_ptr[4:0] == i))
        create_order_source[i]  <= 1'b0;
      else if(ctc_req_create_en && (coq_create_ptr[4:0] == i))
        create_order_source[i]  <= 1'b1;
      else
        create_order_source[i]  <= create_order_source[i];
    end
  end
end

always @(posedge snpindexclk0 or negedge cpurst_b)
begin
  if(~cpurst_b)
    snq_entry_oldest_index[5:0] <= 6'b000001;
  else if(biu_lsu_cr_resp_acept && snq_biu_cr_valid)
    snq_entry_oldest_index[5:0] <= {snq_entry_oldest_index[4:0],snq_entry_oldest_index[5]};
end
always @(posedge snpindexclk1 or negedge cpurst_b)
begin
  if(~cpurst_b)
    ctcq_entry_oldest_index[5:0] <= 6'b000001;
  else if(biu_lsu_cr_resp_acept && ctcq_biu_cr_valid && !ctcq_biu_2_cmplt)
    ctcq_entry_oldest_index[5:0] <= {ctcq_entry_oldest_index[4:0],ctcq_entry_oldest_index[5]};
end



assign arb_snq_entry_oldest_index[5:0]  = snq_entry_oldest_index[5:0]
                                        & {6{~create_order_source[coq_pop_ptr[4:0]]}};

assign arb_ctcq_entry_oldest_index[5:0] = ctcq_entry_oldest_index[5:0]
                                        & {6{create_order_source[coq_pop_ptr[4:0]]}};





assign snp_create_clk_en =  snoop_req_create_en
                         || ctc_req_create_en;


gated_clk_cell  x_snp_create_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snpcrtclk         ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_create_clk_en ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);









assign snp_pop_clk_en = snq_biu_cr_valid || ctcq_biu_cr_valid;

gated_clk_cell  x_snp_pop_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snppopclk         ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_pop_clk_en    ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);









assign snp_snq_clk_en = snq_biu_cr_valid;

gated_clk_cell  x_snp_snq_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snpindexclk0      ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_snq_clk_en    ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);









assign snp_ctcq_clk_en = ctcq_biu_cr_valid && !ctcq_biu_2_cmplt;

gated_clk_cell  x_snp_ctcq_gated_cell (
  .clk_in             (lsu_snoop_clk     ),
  .clk_out            (snpindexclk1      ),
  .external_en        (1'b0              ),
  .global_en          (1'b1              ),
  .local_en           (snp_ctcq_clk_en   ),
  .module_en          (cp0_lsu_icg_en    ),
  .pad_yy_icg_scan_en (pad_yy_icg_scan_en)
);











endmodule