#ifdef SYSTEMC
/*
 * $Id: Free_List_unit_genMealy_push_spr.cpp 123 2009-06-08 20:43:30Z rosiere $
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Rename_unit/Register_translation_unit/Free_List_unit/include/Free_List_unit.h"

namespace morpheo                    {
namespace behavioural {
namespace core {
namespace multi_ooo_engine {
namespace ooo_engine {
namespace rename_unit {
namespace register_translation_unit {
namespace free_list_unit {


#undef  FUNCTION
#define FUNCTION "Free_List_unit::genMealy_push_spr"
  void Free_List_unit::genMealy_push_spr (void)
  {
    log_begin(Free_List_unit,FUNCTION);
    log_function(Free_List_unit,FUNCTION,_name.c_str());

    if (PORT_READ(in_NRESET))
      {
    bool bank_use [_param->_nb_bank];
    for (uint32_t i=0; i<_param->_nb_bank; i++)
      bank_use [i] = false;

    for (uint32_t i=0; i<_param->_nb_push; i++)
      {
	bool spr_ack = not PORT_READ(in_PUSH_SPR_VAL[i]);

	if (not spr_ack)
	  {
// 	    // num_bank : MSB
// 	    uint32_t bank = PORT_READ(in_PUSH_SPR_NUM_REG[i]) >> _param->_bank_spr_size_slot;
	    // num_bank : LSB
	    uint32_t bank = PORT_READ(in_PUSH_SPR_NUM_REG[i]) & _param->_mask_spr;
	    
	    if (not bank_use [bank])
	      {
		// find
		spr_ack = true;
		internal_PUSH_SPR_BANK [i] = bank;
		bank_use [bank] = true;
	      }
	  }

	internal_PUSH_SPR_ACK [i] = spr_ack;
      }
      }
    else
      {
        for (uint32_t i=0; i<_param->_nb_push; i++)
          internal_PUSH_SPR_ACK [i] = 0;
      }

    for (uint32_t i=0; i<_param->_nb_push; i++)
      PORT_WRITE(out_PUSH_SPR_ACK [i], internal_PUSH_SPR_ACK [i]);

    log_end(Free_List_unit,FUNCTION);
  };

}; // end namespace free_list_unit
}; // end namespace register_translation_unit
}; // end namespace rename_unit
}; // end namespace ooo_engine
}; // end namespace multi_ooo_engine
}; // end namespace core

}; // end namespace behavioural
}; // end namespace morpheo              
#endif
