// getScore()
// Description: calculate and return score (only white tiles count)
// Return Val: current score
int Grid::getScore(){
    int score = 0;
    for(int i = 0;i < GRID_SIZE;i++){
        if(m_data[i] < WHITE_BASE)  continue;
        assert(_log2(m_data[i]/WHITE_BASE) > -1);
        assert(_log2(m_data[i]/WHITE_BASE) < WHITE_TYPE_NUM);
        score += _pow3[ _log2(m_data[i]/WHITE_BASE) ];
    }
    return score;
}
extern unsigned int descriptor_id_setup_2(
/* creates a descriptor id setup 2 field out of the various field components */
  unsigned int span_a_id,
  unsigned int span_b_id
)
{
  unsigned int field;

  field =                            span_b_id & ~((-1) << _log2(SPANS));
  field = (field << _log2(SPANS)) | (span_a_id & ~((-1) << _log2(SPANS)));
  return field;
}
dhash_tbl_pt new_dhash_tbl(hash_type_t type,hash_func_t hash_func,equal_func_t equal_func){
	dhash_tbl_pt table=(dhash_tbl_pt)malloc(sizeof(dhash_tbl_t));
	memset(table,0,sizeof(dhash_tbl_t));
	resize_directory(table,DEFAULT_DIR_SIZE);
	table->seg_shift=_log2(DEFAULT_SEG_SIZE);
	table->seg_arr[0]=new_slot_segment();
	table->slot_max=DEFAULT_SEG_SIZE-1;
	table->high_mask=DEFAULT_SEG_SIZE-1;
	switch(type){
	case HASH_CUSTOM:
		table->hash=hash_func;
		table->is_equal=equal_func;
		break;
	case HASH_STRING:
		table->hash=string_hash;
		table->is_equal=string_equal;
		break;
	case HASH_INTEGER:
	default:
		table->hash=integer_hash;
		table->is_equal=integer_equal;
		break;
	}
	return table;
}
// setNextTile()
// Description: determine the next random bonus tile or grab a basic tile from grab bag
void Game::setNextTile(){
    int maxTile = m_grid.getMaxTile();
    if(maxTile >= BONUS_THRESHOLD && getRand() % BONUS_RATIO == BONUS_RATIO - 1){
        int n = getRand() % (_log2(maxTile / BONUS_THRESHOLD) + 1);
        m_nextTile = (BONUS_BASE << n);
    }
    else{
        int tileType;
        int nTile = m_grabBag[0] + m_grabBag[1] + m_grabBag[2];
        assert(nTile > 0);
        int randTile = getRand() % nTile;
        if(randTile < m_grabBag[0]){
            m_grabBag[0]--;
            tileType = 1;
        }
        else if(randTile < m_grabBag[0] + m_grabBag[1]){
            m_grabBag[1]--;
            tileType = 2;
        }
        else{
            m_grabBag[2]--;
            tileType = 3;
        }
        if(nTile == 1)
            resetGrabBag();
        m_nextTile = tileType;
    }
}
Exemple #5
0
struct btree *bt_create(bt_cmp_t cmp, int size) {
    struct btree *btr    = NULL;
    int           textra = 0;

    size   -= sizeof(struct btreenode);
    size   -= sizeof(struct btreenode *);

    /*calculate maximum t that will fix in size, and that t >= 2 */
    int n   = size / (sizeof(struct btreenode *) + sizeof(bt_data_t));
    assert(n > 0);
    int t   = (n + 1) / 2;
    assert(t >= 2);
    n       = 2 * t - 1;
    textra += sizeof btr->root + n * (sizeof(struct btreenode *) +
                                      sizeof(bt_data_t));

    btr                     = allocbtree();
    btr->cmp                = cmp;
    btr->keyoff             = sizeof(struct btreenode);
    unsigned int nodeptroff = btr->keyoff + n * sizeof(bt_data_t);
    assert(nodeptroff <= USHRT_MAX);
    btr->nodeptroff         = (unsigned short)nodeptroff;
    assert(n          <= USHRT_MAX);
    assert(t          <= USHRT_MAX);
    btr->t                  = t;
    int nbits               = _log2(n, sizeof(int) * 8) + 1;
    nbits                   = 1 << (_log2(nbits, sizeof(int) * 8) + 1);
    assert(nbits      <= UCHAR_MAX);
    btr->nbits              = nbits;
    assert(textra     <= USHRT_MAX);
    btr->textra             = textra;
    btr->numnodes++;
    btr->root               = allocbtreenode(btr);
    assert(btr->root);

    //RL4 "BT t: %d nbits: %d textra: %d keyoff: %d nodeptroff: %d",
           //btr->t, btr->nbits, btr->textra, btr->keyoff, btr->nodeptroff);
    return btr;
}
Exemple #6
0
// Rescale BLOSUM matrix for query amino acid frequencies with conjugate gradient method. Used in kDP
void Matrix::wn_rescale(Sequence *s) throw (std::exception){
	init_p_query(s);
	parameter_wrapper pwrap;
	pwrap.matrix  = original;
	pwrap.p_query = p_query;
	int code=0;
  	double val_min;
  	const int dim=20;
  	const int max_iterations=40;
	double x[dim];
	for( size_t a=0; a<20; ++a) x[a] = pow(p_query[a]/p_background[a], 0.7121);
	wn_conj_gradient_method(&code, &val_min, x, dim, &_func, &_grad, max_iterations, &pwrap);
	if( code!=WN_SUCCESS && code!=WN_SUBOPTIMAL) 
		throw MyException("wn_conj_gradient_method failed: return-code is '%i'\n", code);
	for (int a=0; a<20; ++a)
		for (int b=0; b<20; ++b) 
		matrix[a][b] = 2.0*_log2(x[a]*original[a][b]*x[b]/p_query[a]/p_query[b]);
	bool bprint=false;
	double za[20] = {0.0f};
	for (int a=0; a<20; ++a){
		if( x[a]<0.0 ) bprint=true;
		for (int b=0; b<20; ++b) za[a] += original[a][b] * x[b];
	}
	double error=0.0;
	for (int a=0; a<20; ++a){
		double tmp = 1.0-(za[a]*x[a])/p_query[a];
		error += tmp*tmp;
	}
	error_sum += error;
	if(bprint) 
		throw MyException("One or more negative scaling factor(s) occurred while rescaling the amino acid substitution matrix for '%s'!", s->get_header());
	
	_init_main_diagonal_scores();
/*
	if(bprint || error >0.01){
		if(bprint) ++negatives;
		printf("Error: %5.5f\n", error);
		fprintf(stderr, "Minimizing factors (x[])\n");
		for( int i=0; i<20; ++i){
			fprintf(stderr, "%2.4f ", x[i]);
		}
		fprintf(stderr, "\n");
		for (int a=0; a<20; ++a){
			fprintf(stderr, "%2.4f ", (za[a]*x[a])/p_query[a]);
		}
		fprintf(stderr, "\n");
		
	}*/
}
Exemple #7
0
void Matrix::reset(){
	for(size_t i=0; i<20; ++i){
		for(size_t j=0; j<20; ++j){
			matrix[i][j] = _log2(original[i][j]/(p_background[i]*p_background[j])) / scale;
//			std::cout << matrix[i][j] << "  ";
		}
//		std::cout << matrix[i][20] << "\n";
	}
/*	std::cout << "\n";
	for(size_t j=0; j<21; ++j){
		std::cout << matrix[20][j] << "  ";
	}
	std::cout << "\n";*/
	_init_main_diagonal_scores();
}
unsigned int descriptor_id_setup_1(
/* creates a descriptor id setup 1 field out of the various field components */
  unsigned int unit_id,
  unsigned int terminal_a_id,
  unsigned int terminal_b_id,
  unsigned int channel_id
)
{
  unsigned int field;

  field =                                channel_id    & ~((-1) << _log2(CHANNELS));
  field = (field << _log2(TERMINALS)) | (terminal_b_id & ~((-1) << _log2(TERMINALS)));
  field = (field << _log2(TERMINALS)) | (terminal_a_id & ~((-1) << _log2(TERMINALS)));
  field = (field << _log2(UNITS))     | (unit_id       & ~((-1) << _log2(UNITS)));
  return field;
}
Exemple #9
0
/**
 * Setup a new FFT object.
 * Note - N must be a power of 2!
 */
FFT::FFT(int _n)
{
	// setup FFT
	n = _n;
	log2n = (int)_log2((unsigned int) n);
	validSpectrumLength = (n / 2) + 1;

	// precompute tables
	COS_LOOKUP_TABLE = new float[n/2];
	SIN_LOOKUP_TABLE = new float[n/2];

	for(int i = 0; i < n/2; i++)
	{
		COS_LOOKUP_TABLE[i] = cosf(i * (2 * M_PI / n));
		SIN_LOOKUP_TABLE[i] = -sinf(i * (2 * M_PI / n));
	}

	imag 	= new float[n];
	zeroPad = new float[n];	// used to zero this.imag without creating new array every time

	for(int i = 0; i < n; i++)
		zeroPad[i] = 0.0f;
}
Exemple #10
0
static int findkindex(struct btree      *btr,
                      struct btreenode  *x,
                      bt_data_t          k,
                      int               *r,
                      struct btIterator *iter) {
    int a, b, i, tr;
    int *rr; /* rr means key is greater than current entry */

    if (r == NULL) rr = &tr;
    else           rr = r;

    if (x->n == 0) return -1;

    i = 0;
    a = x->n - 1;
    while (a > 0) {
        b = _log2(a, (int)btr->nbits);
        int slot = (1 << b) + i;

        bt_data_t k2 =  KEYS(btr, x)[slot];
        if ((*rr = btr->cmp(k, k2)) < 0) {
            a = (1 << b) - 1;
        } else {
            a -= (1 << b);
            i |= (1 << b);
        }
    }
    if ((*rr = btr->cmp(k, KEYS(btr, x)[i])) < 0)  i--;

    //RL7 "findkindex: i: %d r: %d", i, *rr);
    if (iter) {
        iter->bln->in = (i > 0) ? i : 0;
        iter->bln->ik = (i > 0) ? i : 0;
    }

    return i;
}
Exemple #11
0
static inline int32_t _ceil_log2(const uint32_t n) {
  return _log2(n - 1) + 1;
}
void ULM_initializing(){

	int i;
	int j;

	readcnt = 0;
	writecnt = 0;
	erasecnt = 0;
	inter_GC_cnt = 0;
	intra_GC_cnt = 0;
	maxblk_ulm_intra_cnt = 0;
	intra.erase = 0;
	intra.read = 0;
	intra.write = 0;
	inter.erase = 0;
	inter.read = 0;
	inter.write = 0;
	LUN_func.erase = 0;
	LUN_func.read = 0;
	LUN_func.write =0;
	UBN_func.erase = 0;
	UBN_func.read = 0;
	UBN_func.write = 0;
	IO.erase = 0;
	IO.write = 0;
	IO.read = 0;
	
	UBN_link_front = NULL;
	LUN_link_front = NULL;
	UBN_CMT_cnt = 0;
	LUN_CMT_cnt = 0;

	UBN_hit_cnt = 0;
	UBN_miss_cnt = 0;
	LUN_hit_cnt = 0;
	LUN_miss_cnt = 0;

	shortcut_inter_cnt = 0;
	shortcut_intra_cnt = 0;

	//FLASH_SECTOR = GB / SECTOR_SIZE * FLASH_SIZE;
	//FLASH_PAGE = FLASH_SECTOR / SECTOR_per_PAGE;

	BLOCK_per_FLASH = LOGICAL_FLASH_BLOCK + OVERPROVISIONING_FLASH_BLOCK;
	FLASH_PAGE = PAGE_per_BLOCK * BLOCK_per_FLASH;
	FLASH_SECTOR = FLASH_PAGE * SECTOR_per_PAGE;

	//BLOCK_per_FLASH = FLASH_SECTOR / (SECTOR_per_PAGE * PAGE_per_BLOCK);
	PAGE_per_FLASH = BLOCK_per_FLASH * PAGE_per_BLOCK;
	UNIT_per_FLASH = FLASH_SECTOR / (SECTOR_per_PAGE * PAGE_per_UNIT);
	
	LPN2UBN_SIZE = _log2(BLOCK_per_UNIT);  //in bits
	UBN_offset_SIZE = _log2(PAGE_per_BLOCK); //in bits
	UBN_MAP_SIZE = LPN2UBN_SIZE + UBN_offset_SIZE; //in bits


	if(UBN_MAP_SIZE % 8 == 0)
		UBN_MAP_SIZE = UBN_MAP_SIZE / 8; //in bytes
	else
		UBN_MAP_SIZE = UBN_MAP_SIZE / 8 + 1; //in bytes
	
	//UBN MAP size fix to 4bytes
	UBN_MAP_SIZE = 4;

	LUN_MAP_SIZE = _log2(BLOCK_per_FLASH) + _log2(MAX_PB_per_UNIT * PAGE_per_BLOCK); //in bits with one segments
	if(LUN_MAP_SIZE%8 == 0)
		LUN_MAP_SIZE = LUN_MAP_SIZE/8; //in bytes with one segments
	else
		LUN_MAP_SIZE = LUN_MAP_SIZE/8 + 1;//in bytes with one segments
	LUN_MAP_SIZE = MAX_PB_per_UNIT * LUN_MAP_SIZE;
	UBN_ON_PAGE = PAGE_SIZE / UBN_MAP_SIZE;
	LUN_ON_PAGE = 1;
	if(LUN_MAP_SIZE < PAGE_SIZE){
		LUN_PAGE_no = 1;
		LUN_ON_PAGE = PAGE_SIZE/ LUN_MAP_SIZE;
	}//LU map을 한 페이지에 하나씩 넣을 것인가 아니면 여러개 넣을 수 있다면 여러개 넣을것인가
	else if(LUN_MAP_SIZE%PAGE_SIZE == 0)
		LUN_PAGE_no = LUN_MAP_SIZE/PAGE_SIZE;
	else
		LUN_PAGE_no = LUN_MAP_SIZE/PAGE_SIZE + 1;
	
	FLASH_MTB_SIZE = PAGE_per_FLASH * UBN_MAP_SIZE + UNIT_per_FLASH 
		* LUN_MAP_SIZE;
	UBN_MTB_PAGE = PAGE_per_FLASH/UBN_ON_PAGE;
	LUN_MTB_PAGE = UNIT_per_FLASH/LUN_ON_PAGE*LUN_PAGE_no;
	FLASH_MTB_PAGE = UBN_MTB_PAGE + LUN_MTB_PAGE;

	LOGICAL_FLASH_BLOCK = LOGICAL_FLASH_BLOCK -
		(FLASH_MTB_PAGE % PAGE_per_BLOCK ? (FLASH_MTB_PAGE / PAGE_per_BLOCK + 1) : (FLASH_MTB_PAGE / PAGE_per_BLOCK));
	LOGICAL_FLASH_PAGE = LOGICAL_FLASH_BLOCK * PAGE_per_BLOCK;

	//LOGICAL_FLASH_PAGE = (FLASH_PAGE - FLASH_MTB_PAGE)*97/100;
	
	LOGICAL_FLASH_UNIT = LOGICAL_FLASH_PAGE/PAGE_per_UNIT;
	/*
	UBN_CMT_SIZE = CMT_SIZE * UBN_CMT_PCT / 100;
	LUN_CMT_SIZE = CMT_SIZE * LUN_CMT_PCT / 100;
	*/
	LUN_CMT_SIZE = 5 * PAGE_SIZE;
	UBN_CMT_SIZE = CMT_SIZE - LUN_CMT_SIZE;
	//LUN이 맵에 항상 상주하도록 변경
#if 0
	LUN_CMT_SIZE = LUN_MTB_PAGE * PAGE_SIZE;
	UBN_CMT_SIZE = CMT_SIZE - LUN_CMT_SIZE;
#endif
	UBN_tb = (UBN_MAP *)malloc(sizeof(UBN_MAP)*PAGE_per_FLASH);
	LUN_tb = (LUN_MAP *)malloc(sizeof(LUN_MAP)*UNIT_per_FLASH);
	PBN = (PBN_MAP *)malloc(sizeof(PBN_MAP) * BLOCK_per_FLASH);

	for(i=0; i<PAGE_per_FLASH; i++){

		UBN_tb[i].LPN2UBN = -1;
		UBN_tb[i].LPN2offset = -1;
	}

	for(i=0; i<UNIT_per_FLASH; i++){

		LUN_tb[i].UBN = (UBN_ptr *)malloc(sizeof(UBN_ptr)*MAX_PB_per_UNIT);
		LUN_tb[i].AL_top = NULL;
		LUN_tb[i].UL_top = NULL;
		//LUN_tb[i].unit_valid_info = 0;
		LUN_tb[i].unit_invalid_info = 0;
		LUN_tb[i].intragc_cnt= 0;
		LUN_tb[i].intergc_cnt = 0;
		for(j=0; j<MAX_PB_per_UNIT ; j++){
			LUN_tb[i].UBN[j] = (UBN_info *)malloc(sizeof(UBN_info));
			LUN_tb[i].UBN[j]->invalid_info = 0;
			LUN_tb[i].UBN[j]->PBN_num = -1;
			LUN_tb[i].UBN[j]->top = -1;
			LUN_tb[i].UBN[j]->UBN_num = j;
			LUN_tb[i].UBN[j]->valid_info = 0;
		}
		LUN_tb[i].AL_top = LUN_tb[i].UBN[0];
		for(j=0; j<MAX_PB_per_UNIT - 1 ; j++){
			LUN_tb[i].UBN[j]->next = LUN_tb[i].UBN[j+1];		
		}
		LUN_tb[i].UBN[MAX_PB_per_UNIT - 1]->next = NULL;
	}

	FB_stack = (int *)malloc(sizeof(int)*BLOCK_per_FLASH);
	FB_top = -1;
	

	for(i=0; i<BLOCK_per_FLASH; i++){

		FB_stack[i] = i;
		FB_top++;
		PBN[i].PPN2LPN = (int *)malloc(sizeof(int) * PAGE_per_BLOCK);
		PBN[i].valid = (int *)malloc(sizeof(int) * PAGE_per_BLOCK);
		for(j=0; j<PAGE_per_BLOCK ; j++){
			PBN[i].PPN2LPN[j] = -1;
			PBN[i].valid[j] = -1;
		}
	}

	cl_info = (CL_INFO *) malloc(sizeof(CL_INFO) * UNIT_per_FLASH);
	memset(cl_info, 0x00, sizeof(CL_INFO) * UNIT_per_FLASH);

	printf("\ninitialize end\n");
	
}
Exemple #13
0
/* a tristate buffer is used to handle fan-ins
 * The area of an unbalanced htree (rows != columns)
 * depends on how data is traversed.
 * In the following function, if ( no. of rows < no. of columns),
 * then data first traverse in excess hor. links until vertical
 * and horizontal nodes are same.
 * If no. of rows is bigger, then data traverse in
 * a hor. link followed by a ver. link in a repeated
 * fashion (similar to a balanced tree) until there are no
 * hor. links left. After this it goes through the remaining vertical
 * links.
 */
void Htree2::out_htree()
{
  //temp var
  double s1 = 0, s2 = 0, s3 = 0;
  double l_eff = 0;
  Wire *wtemp1 = 0, *wtemp2 = 0, *wtemp3 = 0;
  double len = 0, ht = 0;
  int option = 0;

  int h = (int) _log2(ndwl);
  int v = (int) _log2(ndbl);
  double hdist;
  double vdist;
  if (ndwl == ndbl) {
    hdist = ndwl/2 - 1;
    vdist = hdist;
  }
  else if (ndwl > ndbl) {
    hdist = ndbl/2-1 + (_log2(ndwl/2) - _log2(ndbl/2));
    vdist = pow(2, (_log2(ndwl/2) - _log2(ndbl/2))) * (ndbl/2-1);
  }
  else {
    hdist = ndwl/2-1;
    vdist = ndwl/2-1 + ((ndwl/2)/2)*(_log2(ndbl/2)-_log2(ndwl/2));
  }
  double len_temp;
  double ht_temp;
  if (uca_tree) {
    ht_temp = (mat_height*ndbl /* mat height => bank height */ +
      (add_bits + data_in_bits + data_out_bits+ (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch)/2;
  len_temp = (mat_width*ndwl /* mat width => bank width */ +
      (add_bits + data_in_bits + data_out_bits+ (search_data_in_bits + search_data_out_bits)) * g_tp.wire_outside_mat.pitch * vdist)/2;
  }
  else {
    if (ndwl == ndbl) {
      ht_temp = ((mat_height*ndbl/2) +
          ((add_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch) +
          ((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * hdist)
          )/2;
    }
    else if (ndwl > ndbl) {
      double excess_part = (_log2(ndwl/2) - _log2(ndbl/2));
      ht_temp = ((mat_height*ndbl/2) +
          ((add_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch) +
          (((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * (ndbl/2-1)) +
          (2 *(data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * (1 - pow(0.5, excess_part+1))))
          )/2;
    }
    else {
      ht_temp = ((mat_height*ndbl/2) +
          ((add_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch) +
          ((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * hdist)
          )/2;
    }
    len_temp = (mat_width*ndwl/2 +
        (add_bits + data_in_bits + data_out_bits + (search_data_in_bits + search_data_out_bits)) * g_tp.wire_outside_mat.pitch * vdist)/2;
  }
  area.h = ht_temp * 2;
  area.w = len_temp * 2;
  delay = 0;
  power.readOp.dynamic = 0;
  power.readOp.leakage = 0;
  power.readOp.gate_leakage = 0;
  //cout<<"power.readOp.gate_leakage"<<power.readOp.gate_leakage<<endl;
  len = len_temp;
  ht = ht_temp/2;

  while (v > 0 || h > 0)
  { //finds delay/power of each link in the tree
    if (wtemp1) delete wtemp1;
    if (wtemp2) delete wtemp2;
    if (wtemp3) delete wtemp3;

    if(h > v) {
      //the iteration considers only one horizontal link
      wtemp1 = new Wire(wt, len); // hor
      wtemp2 = new Wire(wt, len/2);  // ver
      len_temp = len;
      len /= 2;
      wtemp3 = 0;
      h--;
      option = 0;
    }
    else if (v>0 && h>0) {
      //considers one horizontal link and one vertical link
      wtemp1 = new Wire(wt, len); // hor
      wtemp2 = new Wire(wt, ht);  // ver
      wtemp3 = new Wire(wt, len/2);  // next hor
      len_temp = len;
      ht_temp = ht;
      len /= 2;
      ht /= 2;
      v--;
      h--;
      option = 1;
    }
    else {
      // considers only one vertical link
      assert(h == 0);
      wtemp1 = new Wire(wt, ht); // hor
      wtemp2 = new Wire(wt, ht/2);  // ver
      ht_temp = ht;
      ht /= 2;
      wtemp3 = 0;
      v--;
      option = 2;
    }
    delay += wtemp1->delay;
    power.readOp.dynamic += wtemp1->power.readOp.dynamic;
    power.searchOp.dynamic += wtemp1->power.readOp.dynamic*init_wire_bw;
    power.readOp.leakage += wtemp1->power.readOp.leakage*wire_bw;
    power.readOp.gate_leakage += wtemp1->power.readOp.gate_leakage*wire_bw;
    //cout<<"power.readOp.gate_leakage"<<power.readOp.gate_leakage<<endl;
    if ((uca_tree == false && option == 2) || search_tree==true)
    {
      wire_bw*=2;
    }

    if (uca_tree == false)
    {
      if (len_temp > wtemp1->repeater_spacing)
      {
        s1 = wtemp1->repeater_size;
        l_eff = wtemp1->repeater_spacing;
      }
      else
      {
        s1 = (len_temp/wtemp1->repeater_spacing) * wtemp1->repeater_size;
        l_eff = len_temp;
      }
      if (ht_temp > wtemp2->repeater_spacing)
      {
        s2 = wtemp2->repeater_size;
      }
      else
      {
        s2 = (len_temp/wtemp2->repeater_spacing) * wtemp2->repeater_size;
      }
      // first level
      output_buffer(s1, s2, l_eff);
    }


    if (option != 1)
    {
      continue;
    }

    // second level
    delay += wtemp2->delay;
    power.readOp.dynamic += wtemp2->power.readOp.dynamic;
    power.searchOp.dynamic += wtemp2->power.readOp.dynamic*init_wire_bw;
    power.readOp.leakage += wtemp2->power.readOp.leakage*wire_bw;
    power.readOp.gate_leakage += wtemp2->power.readOp.gate_leakage*wire_bw;
    //cout<<"power.readOp.gate_leakage"<<power.readOp.gate_leakage<<endl;
    if (uca_tree)
    {
      power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
      power.readOp.gate_leakage += wtemp2->power.readOp.gate_leakage*wire_bw;
    }
    else
    {
      power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
      power.readOp.gate_leakage += wtemp2->power.readOp.gate_leakage*wire_bw;
      wire_bw*=2;

      if (ht_temp > wtemp3->repeater_spacing)
      {
        s3 = wtemp3->repeater_size;
        l_eff = wtemp3->repeater_spacing;
      }
      else
      {
        s3 = (len_temp/wtemp3->repeater_spacing) * wtemp3->repeater_size;
        l_eff = ht_temp;
      }

      output_buffer(s2, s3, l_eff);
    }
    //cout<<"power.readOp.leakage"<<power.readOp.leakage<<endl;
    //cout<<"power.readOp.gate_leakage"<<power.readOp.gate_leakage<<endl;
    //cout<<"wtemp2->power.readOp.gate_leakage"<<wtemp2->power.readOp.gate_leakage<<endl;
  }

  if (wtemp1) delete wtemp1;
  if (wtemp2) delete wtemp2;
  if (wtemp3) delete wtemp3;
}
Exemple #14
0
/* calculates the input h-tree delay/power
 * A nand gate is used at each node to
 * limit the signal
 * The area of an unbalanced htree (rows != columns)
 * depends on how data is traversed.
 * In the following function, if ( no. of rows < no. of columns),
 * then data first traverse in excess hor. links until vertical
 * and horizontal nodes are same.
 * If no. of rows is bigger, then data traverse in
 * a hor. link followed by a ver. link in a repeated
 * fashion (similar to a balanced tree) until there are no
 * hor. links left. After this it goes through the remaining vertical
 * links.
 */
  void
Htree2::in_htree()
{
  //temp var
  double s1 = 0, s2 = 0, s3 = 0;
  double l_eff = 0;
  Wire *wtemp1 = 0, *wtemp2 = 0, *wtemp3 = 0;
  double len = 0, ht = 0;
  int option = 0;

  int h = (int) _log2(ndwl); // horizontal nodes
  int v = (int) _log2(ndbl); // vertical nodes
  double hdist;
  double vdist;
  if (ndwl == ndbl) {
    hdist = ndwl/2 - 1;
    vdist = hdist;
  }
  else if (ndwl > ndbl) { // config with more h nodes than v nodes
    hdist = ndbl/2-1 + (_log2(ndwl/2) - _log2(ndbl/2)); // Data first traverse in h links till h nodes = v nodes
    // beyond this traversal is similar to a balanced htree
    vdist = pow(2, (_log2(ndwl/2) - _log2(ndbl/2))) * (ndbl/2-1);
  }
  else { // v nodes > h nodes
    // data traverse in a h link followed by a v link in a repeated fashion (similar to a balanced tree) until there are no h links left
    hdist = ndwl/2-1;
    vdist = ndwl/2-1 + ((ndwl/2)/2)*(_log2(ndbl/2)-_log2(ndwl/2));
  }

  double len_temp;
  double ht_temp;
  if (uca_tree)
  {
    ht_temp = (mat_height*ndbl /* since uca_tree models interbank tree, mat_height => bank height */ +
      (add_bits + data_in_bits + data_out_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch)/2;
    len_temp = (mat_width*ndwl /* mat width => bank width */ +
        (add_bits + data_in_bits + data_out_bits + (search_data_in_bits + search_data_out_bits))  * g_tp.wire_outside_mat.pitch * vdist)/2;
  }
  else
  {
    if (ndwl == ndbl) {
      ht_temp = ((mat_height*ndbl/2) +
          ((add_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch) +
          ((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * hdist)
          )/2;
    }
    else if (ndwl > ndbl) {
      double excess_part = (_log2(ndwl/2) - _log2(ndbl/2));
      ht_temp = ((mat_height*ndbl/2) +
          ((add_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch) +
          (((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * (ndbl/2-1)) +
          (2 *(data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * (1 - pow(0.5, excess_part+1))))
          )/2;
    }
    else {
      ht_temp = ((mat_height*ndbl/2) +
          ((add_bits + (search_data_in_bits + search_data_out_bits)) * hdist * g_tp.wire_outside_mat.pitch) +
          ((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * hdist)
          )/2;
    }
    len_temp = (mat_width*ndwl/2 +
        (add_bits + data_in_bits + data_out_bits+ (search_data_in_bits + search_data_out_bits)) * g_tp.wire_outside_mat.pitch * vdist)/2;
  }

  area.h   = ht_temp * 2;
  area.w   = len_temp * 2;
  delay = 0;
  power.readOp.dynamic = 0;
  power.readOp.leakage = 0;
  power.searchOp.dynamic =0;
  len = len_temp;
  ht  = ht_temp/2;

  while (v > 0 || h > 0)
  {
    if (wtemp1) delete wtemp1;
    if (wtemp2) delete wtemp2;
    if (wtemp3) delete wtemp3;

    if (h > v)
    {
      //the iteration considers only one horizontal link
      wtemp1 = new Wire(wt, len); // hor
      wtemp2 = new Wire(wt, len/2);  // ver
      len_temp = len;
      len /= 2;
      wtemp3 = 0;
      h--;
      option = 0;
    }
    else if (v>0 && h>0)
    {
      //considers one horizontal link and one vertical link
      wtemp1 = new Wire(wt, len); // hor
      wtemp2 = new Wire(wt, ht);  // ver
      wtemp3 = new Wire(wt, len/2);  // next hor
      len_temp = len;
      ht_temp = ht;
      len /= 2;
      ht  /= 2;
      v--;
      h--;
      option = 1;
    }
    else
    {
      // considers only one vertical link
      assert(h == 0);
      wtemp1 = new Wire(wt, ht); // ver
      wtemp2 = new Wire(wt, ht/2);  // hor
      ht_temp = ht;
      ht /= 2;
      wtemp3 = 0;
      v--;
      option = 2;
    }

    delay += wtemp1->delay;
    power.readOp.dynamic += wtemp1->power.readOp.dynamic;
    power.searchOp.dynamic += wtemp1->power.readOp.dynamic*wire_bw;
    power.readOp.leakage += wtemp1->power.readOp.leakage*wire_bw;
    power.readOp.gate_leakage += wtemp1->power.readOp.gate_leakage*wire_bw;
    if ((uca_tree == false && option == 2) || search_tree==true)
    {
      wire_bw*=2;  // wire bandwidth doubles only for vertical branches
    }

    if (uca_tree == false)
    {
      if (len_temp > wtemp1->repeater_spacing)
      {
        s1 = wtemp1->repeater_size;
        l_eff = wtemp1->repeater_spacing;
      }
      else
      {
        s1 = (len_temp/wtemp1->repeater_spacing) * wtemp1->repeater_size;
        l_eff = len_temp;
      }

      if (ht_temp > wtemp2->repeater_spacing)
      {
        s2 = wtemp2->repeater_size;
      }
      else
      {
        s2 = (len_temp/wtemp2->repeater_spacing) * wtemp2->repeater_size;
      }
      // first level
      input_nand(s1, s2, l_eff);
    }


    if (option != 1)
    {
      continue;
    }

    // second level
    delay += wtemp2->delay;
    power.readOp.dynamic += wtemp2->power.readOp.dynamic;
    power.searchOp.dynamic += wtemp2->power.readOp.dynamic*wire_bw;
    power.readOp.leakage += wtemp2->power.readOp.leakage*wire_bw;
    power.readOp.gate_leakage += wtemp2->power.readOp.gate_leakage*wire_bw;

    if (uca_tree)
    {
      power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
      power.readOp.gate_leakage += wtemp2->power.readOp.gate_leakage*wire_bw;
    }
    else
    {
      power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
      power.readOp.gate_leakage += wtemp2->power.readOp.gate_leakage*wire_bw;
      wire_bw*=2;

      if (ht_temp > wtemp3->repeater_spacing)
      {
        s3    = wtemp3->repeater_size;
        l_eff = wtemp3->repeater_spacing;
      }
      else
      {
        s3    = (len_temp/wtemp3->repeater_spacing) * wtemp3->repeater_size;
        l_eff = ht_temp;
      }

      input_nand(s2, s3, l_eff);
    }
  }

  if (wtemp1) delete wtemp1;
  if (wtemp2) delete wtemp2;
  if (wtemp3) delete wtemp3;
}
//computes the logarithm base k of a positive integer
inline int _logk ( unsigned int n, unsigned int k )
{
    return _log2 ( n ) / _log2 ( k );
}
Exemple #16
0
int genSNT(Grid &myGrid)
{
	int maxTile = myGrid.getMaxTile();
	int n = rand() % (_log2(maxTile / BONUS_THRESHOLD) + 1);
	return (BONUS_BASE << n);
}