Ejemplo n.º 1
0
void HwRunRisc(PBT878_VIDEOCHIP pChip)
{
	SetVideo(pChip);

	ULONG dma=ReadReg(pChip, REG_GPIO_DMA_CTL);
	char dma_bits[16+100]; Dec2Bin(16, dma_bits, dma);

	
	// set start address
	WriteReg(pChip, REG_RISC_STRT_ADD, pChip->Scr.pCodePhy);	
	
	// risc enable, fifo enable
	SetBin(dma_bits, 1, "1"); // risc enable
	SetBin(dma_bits, 0, "1"); // fifo enable
	WriteReg(pChip, REG_GPIO_DMA_CTL, Bin2Dec(dma_bits));

	// capture control
	WriteReg(pChip, REG_CAP_CTL, 
		SetBin( 1, "1")  |// capture odd
		SetBin( 0, "1")   // capture even
		);

	// interrupt mask
	WriteReg(pChip,REG_INT_MASK,   
	BIT_RISCI		| // RISCI
	BIT_VSYNC 
	); 
	  
    
	

	
}
Ejemplo n.º 2
0
// for risc testing purpose
void HwInitProgram2(PBT878_SCREEN scr)
{
	
	
	ULONG a=0;
	int l=0;
	PULONG code=(PULONG)scr->pCode;
	PULONG start=(PULONG)scr->pCodePhy;
	PHYSICAL_ADDRESS code_physical=MmGetPhysicalAddress(scr->pCode);
	ULONG start2=code_physical.u.LowPart;
	
	
	int i;
	int h=scr->ulHeight;
	int w=scr->ulWidth;	

	PHYSICAL_ADDRESS frame_physical=MmGetPhysicalAddress(scr->pBuffer);
	ULONG frame=frame_physical.u.LowPart;
  


	// post interrupt
	code[l++]= RISC_JUMP |
		SetBin(24, "1") ; // IRQL
	code[l++]=(ULONG)start2;
	code[l++]=0;      
	code[l++]=0;
	code[l++]=0;  

	
}
Ejemplo n.º 3
0
void QtCalculator::Bin_Selected()
{
  basebutton[0]->setChecked(FALSE);
  basebutton[1]->setChecked(FALSE);
  basebutton[2]->setChecked(FALSE);
  basebutton[3]->setChecked(TRUE);
  SetBin();
}
Ejemplo n.º 4
0
void SetVideo(PBT878_VIDEOCHIP pChip)
{
	ULONG a=0;


	
	
	// "1000" YCrCb 4:2:2 planar YV12
	// "0100" YUY2
	WriteReg(pChip, REG_COLOR_FMT, SetBin(7,"0100") | SetBin(3, "0100") ); // odd, even field
    
        
	char mux[4][10] = {"10", "11","01", "00"};
	// set ntsc
	WriteReg(pChip, REG_IFORM, 
		SetBin(7,  "0") |  // reserved
		SetBin( 6, mux[pChip->nMuxCh%4])| // 10: mux0, 11:mux1, 01:mux2, 00:mux3
		SetBin(4,  "11") | // reserved
		SetBin(2, "001")
	);    
	// "000" AUTOFORMAT
	// "001" NTSC(M)   
	// "010" NTSC JAPAN
     
      
  
	SetCropScale(pChip);
	SetEtc(pChip);   
	
}
Ejemplo n.º 5
0
void HwStopRisc(PBT878_VIDEOCHIP pChip)
{
	

	// interrupt mask disable
	WriteReg(pChip, REG_INT_MASK, 0x0);

	ULONG dma=ReadReg(pChip, REG_GPIO_DMA_CTL);
	char dma_bits[16+100]; Dec2Bin(16, dma_bits, dma);

		
	SetBin(dma_bits, 1, "0"); // risc disable
	SetBin(dma_bits, 0, "0"); // fifo disable
	WriteReg(pChip, REG_GPIO_DMA_CTL, Bin2Dec(dma_bits));

	
	// disable capture
	WriteReg(pChip, REG_CAP_CTL, 0 ); 
	

	

}
Ejemplo n.º 6
0
// YUY2 format
void HwInitProgram(PBT878_SCREEN scr)
{
	
	  
	ULONG a=0;
	int l=0;
	PULONG code=(PULONG)scr->pCode;
	PULONG start=(PULONG)scr->pCodePhy;
	PHYSICAL_ADDRESS code_physical=MmGetPhysicalAddress(scr->pCode);
	ULONG start2=code_physical.u.LowPart;
	
	  
	int i;
	int h=scr->ulHeight;
	int w=scr->ulWidth;	

	PHYSICAL_ADDRESS frame_physical=MmGetPhysicalAddress(scr->pBuffer);
	ULONG frame=frame_physical.u.LowPart;
  


	//////////////////////////////////////////////////////////////////////
	// packed data
	code[l++]=RISC_SYNC | 
		SetBin(15, "1") |// RESYNC
		BIT_VRE; // even field to follow
	code[l++]=0;
		  
	code[l++]=RISC_SYNC | 
			BIT_FM1 // packed data			
		;  
	code[l++]=0;
	// post interrupt

	for (i=0;i<h;i+=2)
	{
		code[l++]= RISC_WRITE |
		SetBin(26, "1") | // SOL
		SetBin(27, "1")  | // EOL
		SetBin(11,0, w*2)  // width
		;

		a=frame+w*i*2; // address
		code[l++]=a;


		  
	}


	code[l++]=RISC_SYNC | 
	SetBin(15, "1") |// RESYNC
	BIT_VRO; // even field to follow
	code[l++]=0;

	/////////////////////////////////////////////////////////////////////		
	code[l++]=RISC_SYNC | 
			BIT_FM1 // packed data			
		;  
	code[l++]=0;
	// post interrupt

	for (i=1;i<h;i+=2)
	{
		code[l++]= RISC_WRITE |
		SetBin(26, "1") | // this instruction is first on this scan line
		SetBin(27, "1")  | // this instruction is last on this scan line
		SetBin(11,0, w*2)  // width
		;

		a=frame+w*i*2; // address
		code[l++]=a;


	}
  
  
	//////////////////////////////////////////////////////////////////////
  	code[l++]= RISC_JUMP | 
	SetBin(24, "1") ; // IRQL
	code[l++]=(ULONG)start2;
	code[l++]=0;
	code[l++]=0;    
	code[l++]=0;     
	code[l++]=0; 



	// packed data
//	code[l++]= RISC_SYNC |BIT_VRO;
//	code[l++]=0;



	
}
Ejemplo n.º 7
0
// total resolution 780 x 525
// output resolution   640 x 480 
void SetCropScale(PBT878_VIDEOCHIP pChip)
{
	ULONG a;
	// set scale
	// 640 x 480
	char hscale[256];
	char hdelay[256];
	char hactive[256];
	char vscale[256];
	char vdelay[256];
	char vactive[256];
	
	/*
	Dec2Bin(16, hscale, 682); // 16 bits
	Dec2Bin(13, vscale, 0); // 13 bits

	Dec2Bin(10, hdelay, 134);
	Dec2Bin(10, hactive, 640);    

	Dec2Bin(10,	vdelay, 32);      
	Dec2Bin(10, vactive, 480);    
  */

	Dec2Bin(16, hscale, 732); // 16 bits
	Dec2Bin(13, vscale, 0); // 13 bits

	Dec2Bin(10, hdelay, 114);
	Dec2Bin(10, hactive, 640);  
  
	Dec2Bin(10,	vdelay, 26);  
	Dec2Bin(10, vactive, 480);  
  	    
    
  
	  
	// msb..
	ULONG crop=
	SetBin(7, vdelay, 9, 8) |
	SetBin(5, vactive, 9, 8) |
	SetBin(3, hdelay, 9, 8) |
	SetBin(1, hactive, 9, 8) ;
	WriteReg(pChip, REG_E_CROP, crop);
	WriteReg(pChip, REG_O_CROP, crop);
	
	ULONG vdelay_lo= SetBin(7, vdelay, 7, 0);
	WriteReg(pChip, REG_E_VDELAY_LO, vdelay_lo);
	WriteReg(pChip, REG_O_VDELAY_LO, vdelay_lo);

	ULONG vactive_lo= SetBin(7, vactive, 7, 0);
	WriteReg(pChip, REG_E_VACTIVE_LO, vactive_lo);
	WriteReg(pChip, REG_O_VACTIVE_LO, vactive_lo);  

	ULONG hdelay_lo= SetBin(7, hdelay, 7, 0);
	WriteReg(pChip, REG_E_HDELAY_LO, hdelay_lo);
	WriteReg(pChip, REG_O_HDELAY_LO, hdelay_lo);

	ULONG hactive_lo= SetBin(7, hactive, 7, 0);  
	WriteReg(pChip, REG_E_HACTIVE_LO, hactive_lo);
	WriteReg(pChip, REG_O_HACTIVE_LO, hactive_lo);

	// horizontal scale    
	WriteReg(pChip, REG_E_HSCALE_LO, SetBin(7, hscale, 7, 0));
	WriteReg(pChip, REG_O_HSCALE_LO, SetBin(7, hscale, 7,0));
	WriteReg(pChip, REG_E_HSCALE_HI, SetBin(7, hscale, 15,8));
	WriteReg(pChip, REG_O_HSCALE_HI, SetBin(7, hscale, 15,8));

	// vertical scale upper bytes
	a=ReadReg(pChip, REG_E_VSCALE_HI);
	SetBin(a, 4, vscale, 12, 8);
	WriteReg(pChip, REG_E_VSCALE_HI, a);

	a=ReadReg(pChip, REG_O_VSCALE_HI);
	SetBin(a, 4, vscale, 12, 8);
	WriteReg(pChip, REG_O_VSCALE_HI, a);

	// vertical scale low bytes
	WriteReg(pChip, REG_E_VSCALE_LO, SetBin(7, vscale, 7, 0));
	WriteReg(pChip, REG_O_VSCALE_LO, SetBin(7, vscale, 7, 0));  


	
}
Ejemplo n.º 8
0
// planar mode  YV12
void HwInitProgramYV12(PBT878_SCREEN scr)
{
	
	
	ULONG a=0;
	int l=0;
	PULONG code=(PULONG)scr->pCode;
	PULONG start=(PULONG)scr->pCodePhy;
	PHYSICAL_ADDRESS code_physical=MmGetPhysicalAddress(scr->pCode);
	ULONG start2=code_physical.u.LowPart;
	
	  
	int i;
	ULONG h=scr->ulHeight;
	ULONG w=scr->ulWidth;	

	PHYSICAL_ADDRESS frame_physical=MmGetPhysicalAddress(scr->pBuffer);
	ULONG frame=frame_physical.u.LowPart;
  


	//////////////////////////////////////////////////////////////////////
	// packed data
	code[l++]=RISC_SYNC | 
		SetBin(15, "1") |// RESYNC
		BIT_VRE; // even field to follow
	code[l++]=0;
		  
	code[l++]=RISC_SYNC | 
			BIT_FM3 // planar
		;  
	code[l++]=0;
	// post interrupt

	ULONG cw=w/2;
	ULONG ch=h/2;
	int j=0;
	for (i=0;i<h;i+=2,j++)
	{
		
		code[l++]= RISC_WRITE123 |
		SetBin(26, "1") | // SOL
		SetBin(27, "1")  | // EOL
		SetBin(11,0, w)  // width, fifo 1 count
		;

		
		code[l++]=  
			SetBin(11,0, cw) | // fifo2 count
			SetBin(27,16, cw) ; // fifo3 count

		a=(frame)+w*i; // address for Y
		code[l++]=a;  
  
		
		a=(frame+ w*w + cw* cw) + cw*j; // address for Cr
		code[l++]=a;

		
		a=(frame+ w*w) + cw*j; // address for Cb
		code[l++]=a;
    
	
		  
	}
   

	code[l++]=RISC_SYNC | 
	SetBin(15, "1") |// RESYNC
	BIT_VRO; // even field to follow
	code[l++]=0;

	/////////////////////////////////////////////////////////////////////		
	code[l++]=RISC_SYNC | 
			BIT_FM3 // planar
		;  
	code[l++]=0;
	// post interrupt
	
	
	for (i=1;i<h;i+=2)
	{
		code[l++]= RISC_WRITE1S23 |
		SetBin(26, "1") | // SOL
		SetBin(27, "1")  | // EOL
		SetBin(11,0, w)  // width
		;
  
		
		code[l++]=
			SetBin(11,0, cw) |
			SetBin(27,16, cw) ;

		a=(frame) + w*i; // address for Y
		code[l++]=a;
         
	
		
	}
  
  
	//////////////////////////////////////////////////////////////////////
  	code[l++]= RISC_JUMP | 
	SetBin(24, "1") ; // IRQL
	code[l++]=(ULONG)start2;
	code[l++]=0;
	code[l++]=0;    
	code[l++]=0;     
	code[l++]=0; 



	// packed data
//	code[l++]= RISC_SYNC |BIT_VRO;
//	code[l++]=0;



	
}
uloop2()
{

CBOXPTR acellptr, bcellptr ; 
BBOXPTR ablckptr , bblckptr ;
int botblk , topblk ;
int flips ;
int axcenter , bxcenter , bycenter ; 
int aorient , borient ;
int bleft , bright ; 
int blk , pairflips ;
int i , r , l , t ;
int abin , bbin ;
int firstTry , fds ;
double temp , fp_ratio , percent_error ;


attempts  = 0 ;
flips     = 0 ;
pairflips = 0 ;
earlyRej  = 0 ;

P_limit = -1 ;
windx = minxspan ;

attmax = 2 * attprcel * numcells ;
binpenCon = 0.0 ;

fds = 0 ;
if( estimate_feeds ) {
    fds = controlf( 1 ) ;
}

while( attempts < attmax ) {

    a = PICK_INT( 1 , numcells ) ;

    acellptr = carray[ a ]  ;
    if( acellptr->cclass == -1 ) {
	continue ;
    }
    ablock   = acellptr->cblock ;
    ablckptr = barray[ ablock ] ;
    axcenter = acellptr->cxcenter ;
    aorient = acellptr->corient ;
    abin = SetBin( axcenter ) ;
    cellaptr = binptr[ablock][abin]->cell ;
    for( i = 1 ; i <= *cellaptr ; i++ ) {
	if( cellaptr[i] == a ) {
	     Apost = i ;
	     break ;
	}
    }


    /* 
     *  select block for cell a to be placed in 
     */
    bblock = 0 ;
    firstTry = 0 ;

    if( (botblk = ablock - DELTA_B) < 1) {
	botblk = 1 ;
    }
    if( (topblk = ablock + DELTA_B) > numblock ) {
	 topblk = numblock ;
    }
    for( i = 1 ; ; i++ ) {
	do {
	    blk = XPICK_INT( botblk , topblk , firstTry ) ; 
	    bblckptr = barray[ blk ] ;

	} while( ablock == blk || 
			ablckptr->bclass != bblckptr->bclass ) ;
	
	bleft = bblckptr->bxcenter + bblckptr->bleft ;
	bright = bblckptr->bxcenter + bblckptr->bright ;
	l = (bleft >= axcenter - windx) ? bleft : (axcenter-windx);
	r = (bright <= axcenter + windx) ? bright : (axcenter+windx);
	if( l > r ) {
	    if( i == 1 ) {
		firstTry = blk ;
		continue ;
	    } else if( i == 3 ) {
		if( r < bleft ) {
		    l = r = bleft ;
		} else {
		    l = r = bright ;
		}
	    } else {
		firstTry = - ablock ;
		continue ;
	    }
	} 
	bblock = blk ;
	bycenter = bblckptr->bycenter ;

	if( bblock == ablock ) {
	    bxcenter = XPICK_INT( l, r, axcenter ) ;
	} else {
	    bxcenter = XPICK_INT( l, r, 0 ) ;
	}
	break ;
    }
    bbin = SetBin( bxcenter ) ;
    cellbptr = binptr[bblock][bbin]->cell ;

    if( *cellbptr == 0 ) {

	if( ablckptr->borient == 1 ) {
	    if( bblckptr->borient == 1 ) {
		if( ucxx1( bxcenter, bycenter)){
		    flips++ ;
		}
	    } else {  /* bblckptr->borient == 2 */
		if( ucxxo1( bxcenter,bycenter,(aorient == 0) ? 1 : 3 )){
		    flips++ ;
		}
	    }
	} else {  /* ablockptr->borient == 2 */	
	    if( bblckptr->borient == 1 ) {
		if( ucxxo1( bxcenter, bycenter,
			    (aorient == 1) ? 0 : 2)){
		    flips++ ;
		}
	    } else {  /*  bblckptr->borient == 2 */
		if( ucxx1( bxcenter, bycenter) ){
		    flips++ ;
		}
	    }
	}
    } else { /*   *cellbptr >= 1   */

	Bpost = PICK_INT( 1 , *cellbptr ) ;
	b = cellbptr[ Bpost ] ;
	bcellptr  = carray[b] ;
	bblock    = bcellptr->cblock   ;
	bblckptr = barray[ bblock ] ;

	if( bcellptr->cclass == -1 || a == b ) {
	    continue ;
	}
	
	borient   = bcellptr->corient  ;
	if( ablckptr->borient == 1 ) {
	    if( bblckptr->borient == 1 ) {
		t = ucxx2( ) ;
		if( t == 1 ) {
		    pairflips++ ;
		}
	    } else {  /* bblock->orient == 2 */
		t = ucxxo2( (aorient == 0) ? 1:3, (borient == 1)
							 ? 0:2 ) ;
		if( t == 1 ) {
		    pairflips++ ;
		}
	    }
	} else { /* ablock->borient == 2 */
	    if( bblckptr->borient == 1 ) {
		t = ucxxo2( (aorient == 1) ? 0:2, (borient == 0)
							    ? 1:3) ;
		if( t == 1 ) {
		    pairflips++ ;
		}
	    } else { /* bblock->borient == 2 */  
		t = ucxx2( ) ;
		if( t == 1 ) {
		    pairflips++ ;
		}
	    }
	}
    }
    attempts++ ;
}


temp = 100.0 * (double)(pairflips + flips) / (double)(attmax) ;
if( pairflips > 0.0001 ) {
    fp_ratio = 100.0 * (double)flips/(double)pairflips ;
} else {
    fp_ratio = 100.0 ;
}

fprintf(fpo,"%3d %3d %4d %8d %7d %5d 0.0 %4.1f %4.1f %4.1f %4.1f",
	iteration+1, (int)T, fds , funccost, penalty, P_limit,
	binpenCon, roLenCon, temp, fp_ratio);
fprintf(fpo," %4.1f\n", 100.0*(double)earlyRej/(double)attmax );
fflush( fpo ) ;

return ;
}
ucxx2( )
{

CBOXPTR acellptr , bcellptr ;
TIBOXPTR atileptr , btileptr ;
TEBOXPTR atermptr , btermptr ;
int error_light_is_on ;
int cost ;
int aorient , borient ;
int a1LoBin, a1HiBin, b1LoBin, b1HiBin ;
int a2LoBin, a2HiBin, b2LoBin, b2HiBin ;
int startxa1 , endxa1 , startxa2 , endxa2 ;
int startxb1 , endxb1 , startxb2 , endxb2 ;
int anbin , bnbin , i ;
int truth ;
double temp ;


acellptr = carray[ a ]    ; 
axcenter = acellptr->cxcenter ; 
aycenter = acellptr->cycenter ; 
aorient  = acellptr->corient  ; 
atileptr = acellptr->tileptr ; 
aleft    = atileptr->left    ; 
aright   = atileptr->right   ; 
atermptr = atileptr->termsptr ; 

bcellptr = carray[ b ]    ; 
bxcenter = bcellptr->cxcenter ; 
bycenter = bcellptr->cycenter ; 
borient  = bcellptr->corient  ; 
btileptr = bcellptr->tileptr ; 
bleft    = btileptr->left    ; 
bright   = btileptr->right   ; 
btermptr = btileptr->termsptr ; 

newbinpenal = binpenal ;
newrowpenal = rowpenal ;
newpenal    = penalty  ;

new_old( bright-bleft-aright+aleft ) ;

find_new_pos() ;

a1LoBin = SetBin( startxa1 = axcenter + aleft  ) ; 
a1HiBin = SetBin( endxa1   = axcenter + aright ) ; 
b1LoBin = SetBin( startxb1 = bxcenter + bleft  ) ; 
b1HiBin = SetBin( endxb1   = bxcenter + bright ) ; 
a2LoBin = SetBin( startxa2 = anxcenter + aleft  ) ; 
a2HiBin = SetBin( endxa2   = anxcenter + aright ) ; 
b2LoBin = SetBin( startxb2 = bnxcenter + bleft  ) ; 
b2HiBin = SetBin( endxb2   = bnxcenter + bright ) ; 

old_assgnto_new2( a1LoBin , a1HiBin , b1LoBin , b1HiBin , 
		  a2LoBin , a2HiBin , b2LoBin , b2HiBin ) ;

sub_penal( startxa1 , endxa1 , ablock , a1LoBin , a1HiBin ) ; 
sub_penal( startxb1 , endxb1 , bblock , b1LoBin , b1HiBin ) ; 
add_penal( startxa2 , endxa2 , bblock , a2LoBin , a2HiBin ) ; 
add_penal( startxb2 , endxb2 , ablock , b2LoBin , b2HiBin ) ; 

binpen_chg = newbinpenal - binpenal ;
rowpen_chg = newrowpenal - rowpenal ;
newpenal = (int)( roLenCon * (double) newrowpenal + 
				binpenCon * (double) newbinpenal ) ;

error_light_is_on = 0 ;
if( newpenal - penalty > P_limit ) {
    if( potential_errors < 100 ) {
	++potential_errors ;
	error_light_is_on = 1 ;
    } else {
	earlyRej++ ;
	return( -1 ) ;
    }
}

if( ablock != bblock ) {
    term_newpos_a( atermptr , anxcenter , bycenter , aorient ) ; 
    term_newpos_b( btermptr , bnxcenter , aycenter , borient ) ; 
} else {
    term_newpos( atermptr , anxcenter , bycenter , aorient ) ; 
    term_newpos( btermptr , bnxcenter , aycenter , borient ) ; 
}

cost = funccost ; 

delta_vert_cost = 0 ;
if( ablock != bblock ) {
    new_dbox_a( atermptr , &cost ) ;
    new_dbox_a( btermptr , &cost ) ;
} else {
    new_dbox( atermptr , &cost ) ;
    new_dbox( btermptr , &cost ) ;
}

wire_chg = cost - funccost ;

truth = acceptt(funccost + penalty - cost - newpenal - delta_vert_cost);

if( truth == 1 ) {

    if( error_light_is_on ) {
	error_count++ ;
    }
    new_assgnto_old2( a1LoBin , a1HiBin , b1LoBin , b1HiBin , 
		      a2LoBin , a2HiBin , b2LoBin , b2HiBin ) ;
    if( ablock != bblock ) {
	dbox_pos_2( atermptr ) ;
	dbox_pos_2( btermptr ) ;
    } else {
	dbox_pos( atermptr ) ;
	dbox_pos( btermptr ) ;
    }
    anbin = SetBin( anxcenter ) ;
    bnbin = SetBin( bnxcenter ) ;
    if( cellaptr != cellbptr ) {
	remv_cell( cellaptr , Apost ) ;
	remv_cell( cellbptr , Bpost ) ;
	add_cell( &binptr[bblock][anbin]->cell , a ) ;
	add_cell( &binptr[ablock][bnbin]->cell , b ) ;
    } else {
	remv_cell( cellaptr , Apost ) ;
	for( i = 1 ; i <= *cellaptr ; i++ ) {
	    if( cellaptr[i] == b ) {
		break ;
	    }
	}
	remv_cell( cellaptr , i ) ;
	add_cell( &binptr[ablock][anbin]->cell , a ) ;
	add_cell( &binptr[ablock][bnbin]->cell , b ) ;
    }
    if( wire_chg < 0 ) {
	temp = (double) - wire_chg ;
	total_wire_chg += temp ;
	sigma_wire_chg += (temp - mean_wire_chg) * 
					(temp - mean_wire_chg) ;
	wire_chgs++ ;
    }
 
    acellptr->cblock   = bblock    ;
    acellptr->cxcenter = anxcenter ; 
    acellptr->cycenter = bycenter  ; 
    bcellptr->cblock   = ablock    ;
    bcellptr->cxcenter = bnxcenter ; 
    bcellptr->cycenter = aycenter  ; 

    funccost = cost ; 
    binpenal = newbinpenal ;
    rowpenal = newrowpenal ;
    penalty  = newpenal ;

    if( ablock != bblock ) {
	barray[ablock]->oldsize = barray[ablock]->newsize ;
	barray[bblock]->oldsize = barray[bblock]->newsize ;
    }
    return( 1 ) ;
} else {
    return( 0 ) ;
}
}
Ejemplo n.º 11
0
findcostf()
{
TIBOXPTR tileptr1 ;
CBOXPTR cellptr1 ;
BINPTR bptr ;
INT left , right ;
INT bin , LoBin , HiBin ;
INT block , cell , blk ;
INT startx , endx ;
INT cost ;
INT k , cbin , row ;

blkleftG = INT_MAX ;
blkriteG = INT_MIN ;
for( block = 1 ; block <= numRowsG ; block++ ) {
    if( barrayG[ block ]->bxcenter + barrayG[ block ]->bleft <
						blkleftG ) {
	blkleftG = barrayG[ block ]->bxcenter +
					barrayG[ block ]->bleft ;
    } 
    if( barrayG[ block ]->bxcenter + 
			barrayG[ block ]->bright > blkriteG ) {
	blkriteG = barrayG[ block ]->bxcenter +
				    barrayG[ block ]->bright ;
    }
}
binOffstG = blkleftG ;
max_blklengthG = blkriteG - blkleftG ;

old_numBinS = numBinsG ;

numBinsG = (INT)( ( blkriteG - binOffstG ) / binWidthG ) ;
if( ( blkriteG - binOffstG ) > ( numBinsG * binWidthG ) ) {
    numBinsG++ ;
}

if( numBinsG > old_numBinS ) {
    for( row = 1 ; row <= numRowsG ; row++ ) {
	bin_configG[row] = (INT *) Ysafe_realloc( bin_configG[row] ,
				(1 + numBinsG) * sizeof(INT) ) ;
	for( bin = old_numBinS + 1 ; bin <= numBinsG ; bin++ ) {
	    bin_configG[row][bin] = 0 ;
	}
    }
}

cost = recompute_wirecost() ;

binpenalG = 0 ;
rowpenalG = 0 ;
penaltyG = 0 ;

for( block = 1 ; block <= numRowsG ; block++ ) {
    for( bin = 0 ; bin <= old_numBinS ; bin++ ) {
	Ysafe_free( binptrG[block][bin]->cell ) ;
	Ysafe_free( binptrG[block][bin] ) ;
    }
    Ysafe_free( binptrG[block] ) ;
}

for( block = 1 ; block <= numRowsG ; block++ ) {

    binptrG[block] = (BINPTR * ) Ysafe_malloc( (numBinsG + 1) *
				      sizeof( BINPTR ) ) ;
    left  = barrayG[ block ]->bleft + barrayG[ block ]->bxcenter ;
    right = barrayG[ block ]->bleft + barrayG[ block ]->bxcenter 
				   + barrayG[ block ]->desire   ;
    /* set barray->oldsize to zero for upcoming calculation */
    barrayG[ block ]->oldsize = 0 ;
    LoBin = SetBin( left ) ;
    HiBin = SetBin( right ) ;
    
    for( bin = 0 ; bin <= numBinsG ; bin++ ) {
	binptrG[block][bin] = (BINBOX *) Ysafe_malloc( 
					    sizeof(BINBOX) ) ; 
	binptrG[block][bin]->cell = (INT *)Ysafe_malloc( 
					    10 * sizeof(INT) );
	bptr = binptrG[block][bin] ;
	bptr->cell[0] = 0 ;
	bptr->right = binOffstG + bin * binWidthG ;
	bptr->left  = bptr->right - binWidthG ;
	if( bin == LoBin ) {
	    bptr->penalty = left - bptr->right ;
	} else if( bin == HiBin ) {
	    bptr->penalty = bptr->left - right ;
	} else if( bin > HiBin || bin < LoBin ) {
	    bptr->penalty = 0 ;
	} else {
	    bptr->penalty = - binWidthG ;
	}
    }
}

installf() ;

for( cell = 1 ; cell <= numcellsG - extra_cellsG ; cell++ ) {

    cellptr1 = carrayG[ cell ] ;
    tileptr1 = cellptr1->tileptr ;
    block = cellptr1->cblock ;

    startx = cellptr1->cxcenter + tileptr1->left  ;
    endx   = cellptr1->cxcenter + tileptr1->right ;

    barrayG[block]->oldsize += endx - startx ;

    cbin  = SetBin( cellptr1->cxcenter ) ;
    LoBin = SetBin( startx ) ;
    HiBin = SetBin( endx ) ;

    k = ++(binptrG[block][cbin]->cell[0]) ;
    if( k % 10 == 0 ) {
	binptrG[block][cbin]->cell = (INT *) Ysafe_realloc(
	      binptrG[block][cbin]->cell, (k + 10) * sizeof( INT ) ) ;
    }
    binptrG[block][cbin]->cell[k] = cell ;
    if( LoBin == HiBin ) {
	binptrG[block][LoBin]->penalty +=  ( endx - startx ) ;
    } else {
	bptr = binptrG[block][LoBin] ;
	bptr->penalty += ( bptr->right - startx ) ;

	bptr = binptrG[block][HiBin] ;
	bptr->penalty +=  ( endx - bptr->left ) ;

	if( LoBin + 1 < HiBin ) {
	    for( bin = LoBin + 1 ; bin <= HiBin - 1 ; bin++ ) {
		binptrG[block][bin]->penalty += binWidthG ;
	    }
	}
    }
}

for( block = 1 ; block <= numRowsG ; block++ ) {
    for( bin = 0 ; bin <= numBinsG ; bin++ ) {
	binpenalG += ABS( binptrG[block][bin]->penalty ) ;
    }
}

for( blk = 1 ; blk <= numRowsG ; blk++ ) {
    rowpenalG += ABS(barrayG[blk]->oldsize - barrayG[blk]->desire) ;
}

penaltyG = (INT)( binpenConG * (DOUBLE) binpenalG + 
				roLenConG * (DOUBLE) rowpenalG ) ;

timingcostG = recompute_timecost() ;

return( cost ) ;
}
Ejemplo n.º 12
0
void uloop()
{

FENCEBOXPTR fence ;
CBOXPTR acellptr, bcellptr ; 
BBOXPTR ablckptr , bblckptr ;
INT flips , rejects , do_single_cell_move , bit_class ;
INT axcenter , bxcenter , bycenter ; 
INT aorient , borient ;
INT blk , pairflips ;
INT i , j , t , count , swaps, index, shift ;
INT abin , bbin , fds , done , single_swap ;
DOUBLE target_row_penalty ;
DOUBLE target_bin_penalty ;
DOUBLE temp , percent_error ;
DOUBLE dCp, delta , gswap_ratio ;
INT m1,m2, trials ;
INT num_accepts , gate_switches , gate_attempts ;
INT last_flips , delta_func , delta_time ;
INT temp_timer, time_to_update ; /* keeps track of when to update T */
DOUBLE iter_time, accept_deviation, calc_acceptance_ratio() ;
DOUBLE num_time, num_func ;
DOUBLE calc_time_factor() ; 
/* 
    commented out variables 
    INT reset_T ;
    DOUBLE old_T ;
*/


attemptsG  = 0 ;
flips     = 0 ;
rejects   = 0 ;
pairflips = 0 ;
earlyRejG  = 0 ;
Rej_errorG = 0 ;

G( reset_heat_index() ) ;
potential_errorsG = 0 ;
error_countG = 0 ;
if( !P_limit_setS || iterationG <= 0 ) {
    P_limitG = 999999;
    if( iterationG > 0 ) {
	P_limit_setS = TRUE ;
    }
} else {
    if( wire_chgsG > 0 ) {
	mean_wire_chgG = total_wire_chgG / (DOUBLE) wire_chgsG ;
	if( iterationG > 1 ) {
	    sigma_wire_chgG = sqrt( sigma_wire_chgG / (DOUBLE) wire_chgsG);
	} else {
	    sigma_wire_chgG = 3.0 * mean_wire_chgG ;
	}
    } else {
	mean_wire_chgG  = 0.0 ;
	sigma_wire_chgG = 0.0 ;
    }
    P_limitG = mean_wire_chgG + 3.0 * sigma_wire_chgG + TG ;
    if (P_limitG > 999999) P_limitG = 999999;
}

sigma_wire_chgG = 0.0 ;
total_wire_chgG = 0.0 ;
wire_chgsG = 0 ;
m1 = m2 = 1;
dCp = 0.0;


fds = reconfig() ;

avg_rowpenalS = 0.0 ;
num_penalS = 0.0 ;
if( iterationG < 0 ) {
    avg_timeG = 0.0 ;
    num_time = 0.0 ;
    avg_funcG = 0.0 ;
    num_func = 0.0 ;
}

/* number of moves before temperature update */
time_to_update = attmaxG / NUMTUPDATES ;
if( time_to_update <= 14 ) {
    time_to_update = 14 ;
}
temp_timer = 0 ; /* initialize timer */
num_accepts = 0 ;
last_flips = 0 ;

gate_switches = 0 ;
gate_attempts = 0 ;

/* ------------------------------------------------------------------------
        The back bone of the program the "while-loop" begins from here ...
   ------------------------------------------------------------------------ */ 
while( attemptsG < attmaxG ) {

    /* ------------- pick up a number at random --------------- */
    aG = PICK_INT( 1 , numcellsG - extra_cellsG ) ;

    /* ------------- get the structure for cell# aG ------------- */
    acellptr = carrayG[ aG ] ;
    ablockG   = acellptr->cblock ;
    axcenter = acellptr->cxcenter ;

/* ------------------------------------------------------------------------
    If two cells have the same swap_group then parts of the cells are
    interchangable. Below we check if the cell#aG belongs to a swap_group
   ------------------------------------------------------------------------ */
    if( acellptr->num_swap_group > 0 ) {
	INT sgroup;
	SGLISTPTR sglistptr;
	i = PICK_INT( 0 , acellptr->num_swap_group - 1 ) ;
	sglistptr = acellptr->swapgroups + i;
	sgroup = sglistptr->swap_group;
	

	trials = 0 ;   /*--- number of max trials (heuristically)=50 ---*/
	do {
	 /* -----------------------------------------------------------------
            pick_position picks up a new position for the cell#aG, it returns
	    the bxcenter and blk where the cell could be moved ...
            -----------------------------------------------------------------*/
	    pick_position(&bxcenter,&blk,axcenter,ablockG,8.0);

	    bbin = SetBin( bxcenter ) ;
	 /* -----------------------------------------------------------------
            the field "cell" in binptrG[blk][bbin]->cell contains a list of 
	    all the cells in that bin. But cell[0] contains the total number
	    of cells in the bin (hard-coded) isn't it ...
	    -----------------------------------------------------------------*/
	    cellbptrG = binptrG[blk][bbin]->cell ;

	    if( *cellbptrG > 0 ) {
		if( Equal_Width_CellsG ){
		    BpostG = 1 ;
		} else {
		    BpostG = PICK_INT( 1 , *cellbptrG ) ;
		}
		bG = cellbptrG[ BpostG ] ;
		bcellptr  = carrayG[bG] ;
	    } else {
		bG = 0 ;
	    }
	    if( bG != 0 && aG != bG ) {
		for (j = 0; j < bcellptr->num_swap_group; j++) {
		    sglistptr = bcellptr->swapgroups + j;
		    if (sglistptr->swap_group == sgroup)
			break;
		}
		if (j < bcellptr->num_swap_group) {
		    break ;
		} else {
		    trials++ ;
		}
	    } else {
		trials++ ;
	    }
	} while( trials <= 50 ) ;

	if( trials <= 50 ) {
	    for( swaps = 1 ; swaps <= 4 ; swaps++ ) {
	      /* -- gate_swap evaluates the proposed gate swaps --*/
		gate_switches += gate_swap( 1, i, j ) ;
		gate_attempts++ ;
	    }
	}

	sglistptr = acellptr->swapgroups + i;

	// If a cell has more than one pin group in the same
	// swap group, then it can permute pin groups within
	// itself.

	if( sglistptr->num_pin_group > 1 ) {
	    for( swaps = 1 ; swaps <= 4 ; swaps++ ) {
		gate_swap( 0, i, j ) ;
	    }
	}
    }
    if( acellptr->cclass < -1 ) { /*---- for rigid cells, continue ----*/
	continue ;
    }

    ablckptr = barrayG[ ablockG ] ;
    aorient = acellptr->corient ;
    abin = SetBin( axcenter ) ;
    cellaptrG = binptrG[ablockG][abin]->cell ;
    if( Equal_Width_CellsG ){
	ApostG = 1 ;
    } else {
	for( i = 1 ; i <= *cellaptrG ; i++ ) {
	    if( cellaptrG[i] == aG ) {
		 ApostG = i ;
		 break ;
	    }
	}
    }

    /* 
     *  select block for cell a to be placed in 
     */
    if( acellptr->fence == NULL ) { /* cclass -1 cells won't enter here */
	bblockG = 0 ;
	for (i=0; i<10; i++) {
	    pick_position(&bxcenter,&blk,axcenter,ablockG,1.0);
	    bblckptr = barrayG[ blk ] ;
	    /* if cell "a" can't legally enter this row, keep looking */
	    if( ablockG == blk || acellptr->cclass == 0 ) {
		/*  cell "a" will remain in the same row, or:  */
		/*  cell "a" can go anywhere it pleases  */
		break ;
	    } else if( acellptr->cclass > 0 ) {  /*  it cannot go anywhere it pleases  */
		bit_class = 1 ;
		index = (bblckptr->bclass - 1) / 32 ;
		shift = bblckptr->bclass - 32 * index ;
		bit_class <<= (shift - 1) ;
		if( bit_class & acellptr->cbclass[index] ) {
		    /*  "a" is allowed in a row with this block_class */
		    break ;
		}  /* else, keep searching for a legal row  */
	    }
	}
    } else {
	/* 
	 *  select block for cell a to be placed in 
	 */
	bblockG = 0 ;
	for (i=0; i<10; i++) {
	    fence = acellptr->fence ;
	    if( fence->next_fence != NULL ) {
		count = 0 ;
		for( ; fence; fence = fence->next_fence){
		    count++ ;
		}
		j = PICK_INT( 1 , count ) ;
		count = 0 ;
		fence = acellptr->fence ;
		for( ; fence; fence = fence->next_fence ) {
		    if( ++count == j ) {
			break ;
		    }
		}
	    }
	    pick_fence_position(&bxcenter,&blk,fence) ;
	    bblckptr = barrayG[ blk ] ;

	    /* if cell "a" can't legally enter this row, keep looking */
	    if( ablockG == blk || acellptr->cclass <= 0 ) {
		/*  cell "a" will remain in the same row, or:  */
		/*  cell "a" can go anywhere it pleases  */
		break ;
	    } else if( acellptr->cclass > 0 ) {  /*  it cannot go anywhere it pleases  */
		bit_class = 1 ;
		index = (bblckptr->bclass - 1) / 32 ;
		shift = bblckptr->bclass - 32 * index ;
		bit_class <<= (shift - 1) ;
		if( bit_class & acellptr->cbclass[index] ) {
		    /*  "a" is allowed in a row with this block_class */
		    break ;
		}  /* else, keep searching for a legal row  */
	    }
	}
    }/* end else -- acellptr->fence != NULL -- cclass -1 cells won't enter here */

    if (i == 10) continue;  /*-- get out of the while-loop --*/

    /*------- Now get the target block's structure and target bin -------*/
    bblockG = blk;
    bycenter = bblckptr->bycenter ;

    bbin = SetBin( bxcenter ) ;
    cellbptrG = binptrG[bblockG][bbin]->cell ;

    if( *cellbptrG > 0 ) {
	count = 0 ;

get_b:  if( Equal_Width_CellsG ){
	    BpostG = 1 ;
	} else {
	    BpostG = PICK_INT( 1 , *cellbptrG ) ;
	}
	bG = cellbptrG[ BpostG ] ;
	if( aG == bG ) {
	    continue ;
	}
	bcellptr  = carrayG[bG] ;

	if( fences_existG ) {
	    done = 0 ;
	    if( (fence = bcellptr->fence) != NULL ) {
		while(1) {
 /*------- make sure cell aG's block is outside the block bG's fence -------*/ 
		    if( ablockG >= fence->min_block && 
					ablockG <= fence->max_block &&
					axcenter >= fence->min_xpos &&
					axcenter <= fence->max_xpos ) {
			done = 1 ;
			break ;
		    } else {
			fence = fence->next_fence ;
			if( fence == NULL ) {
			    if( ++count < *cellbptrG ) {
				goto get_b ;
			    } else {
				break ;
			    }
			}
		    }
		}
		if( !done ) {
		    continue ;
		}
	    }
	}
	if( bcellptr->cclass < -1 ) {
	    do_single_cell_move = 1 ;
	} else if( ablockG != bblockG && bcellptr->cclass > 0 ) {
	    bit_class = 1 ;
	    index = (ablckptr->bclass - 1) / 32 ;
	    shift = ablckptr->bclass - 32 * index ;
	    bit_class <<= (shift - 1) ;
	    if( !(bit_class & bcellptr->cbclass[index]) ) {
		/*  "b" is not allowed in a row with this block_class */
		continue ;
	    }
	    do_single_cell_move = 0 ;
	    borient  = bcellptr->corient ;
	} else {
	    do_single_cell_move = 0 ;
	    borient  = bcellptr->corient ;
	}
    } else {
	do_single_cell_move = 1 ;
    }

    delta_func = funccostG ;
    delta_time = timingcostG ;

    if( do_single_cell_move ) {
	if( Equal_Width_CellsG ) {
	    continue ;
	}
	/*
	reset_T = 0 ;
	if( acellptr->fence != NULL ) {
	    if( ablockG < acellptr->fence->min_block ||
				ablockG > acellptr->fence->max_block ) {
		reset_T = 1 ;
		old_T = T ;
		T = 1000000.0 ;
	    }
	}
	*/
	if( ablckptr->borient == 1 ) {
	    if( bblckptr->borient == 1 ) {
		t = ucxx1( bxcenter, bycenter) ;
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 0) ? 2 : 0 );
		    }
		} else {  /* if( t == 1 ) */
		    flips++ ;
		    acc_cntS ++;
		}
	    } else {  /* bblckptr->borient == 2 */
		t = ucxxo1( bxcenter,bycenter,(aorient == 0) ? 1 : 3 ) ;
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 0) ? 2 : 0 );
		    }
		} else {  /* if( t == 1 ) */
		    flips++ ;
		    acc_cntS ++;
		}
	    }
	} else {  /* ablockGptr->borient == 2 */	
	    if( bblckptr->borient == 1 ) {
		t = ucxxo1( bxcenter, bycenter, (aorient == 1) ? 0 : 2) ;
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 1) ? 3 : 1 );
		    }
		} else {  /* if( t == 1 ) */
		    flips++ ;
		    acc_cntS ++;
		}
	    } else {  /*  bblckptr->borient == 2 */
		t = ucxx1( bxcenter, bycenter) ;
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 1) ? 3 : 1 );
		    }
		} else {  /* if( t == 1 ) */
		    flips++ ;
		    acc_cntS ++;
		}
	    }
	}
	/*
	if( reset_T ) {
	    T = old_T ;
	}
	*/
    } else {
	/*   pairwise interchange */
	if( ablckptr->borient == 1 ) {
	    if( bblckptr->borient == 1 ) {
		t = ucxx2() ;
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 0) ? 2 : 0 );
		    }
		} else {  /* if( t == 1 ) */
		    pairflips++ ;
		    acc_cntS ++;
		}
	    } else {  /* bblockG->orient == 2 */
		t = ucxxo2( (aorient == 0) ? 1:3, (borient == 1) ? 0:2);
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 0) ? 2 : 0 );
		    }
		} else {  /* if( t == 1 ) */
		    pairflips++ ;
		    acc_cntS ++;
		}
	    }
	} else { /* ablockG->borient == 2 */
	    if( bblckptr->borient == 1 ) {
		t = ucxxo2( (aorient == 1) ? 0:2, (borient == 0) ? 1:3);
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 1) ? 3 : 1 );
		    }
		} else {  /* if( t == 1 ) */
		    pairflips++ ;
		    acc_cntS ++;
		}
	    } else { /* bblockG->borient == 2 */  
		t = ucxx2( ) ;
		if( t != 1 ) {
		    rejects++ ;
		    if( rejects % 6 == 0 && acellptr->orflag != 0){
			uc0( aG , (aorient == 1) ? 3 : 1 );
		    }
		} else {  /* if( t == 1 ) */
		    pairflips++ ;
		    acc_cntS ++;
		}
	    }
	}
    }

    num_penalS += 1.0 ;
    avg_rowpenalS = (avg_rowpenalS * (num_penalS - 1.0) + 
			(DOUBLE) rowpenalG) / num_penalS ;
    
    attemptsG++ ;

    /* draw the data */
    G( check_graphics(FALSE) ) ;

    if (iterationG <= 0) {

	if( iterationG == 0 )  continue;
	
	/* calculate a running average of (delta) timing penalty */
	delta_time = abs( delta_time - timingcostG ) ;
	if( delta_time != 0 ) {
	    num_time += 1.0 ;
	    avg_timeG = (avg_timeG * (num_time - 1.0) + 
			    (DOUBLE) delta_time) / num_time ;
	
	    /* calculate a running average of (delta) wirelength penalty */
	    delta_func = abs( delta_func - funccostG ) ;
	    num_func += 1.0 ;
	    avg_funcG = (avg_funcG * (num_func - 1.0) + 
				(DOUBLE) delta_func) / num_func ;
	}


	if (d_costG >= 0){
	    m1 ++;	/* d_cost is the -ve of the actual d_cost */
	} else {
	    dCp -= d_costG;
	    m2 ++;
	}
	temp = (INITRATIO * attemptsG - m1) / m2;
	if (temp <= 0.0) {
	    TG *= 0.9;
	} else {
	    TG = -dCp / (m2 * log(temp));
	}
	continue;		/* initialization phase */
    }

    /* ----------------------------------------------------------------- 
       Update temperature using negative feedback to control the
       acceptance ratio in accordance to curve fit schedule.  
       Calc_acceptance_ratio returns desired acceptance ratio give
       the iterationG.  The damped error term (deviation) is then applied 
       to correct the temperature T.  Update_window_size controls the 
       range limiter.  We avoid updating T during initialization, 
       we use exact schedule to compute starting T.  The temp_timer 
       allows us to update temperature inside the inner loop
       of the annealing algorithm. We use counter to avoid use of mod
       function for speed.
     ------------------------------------------------------------------ */
    num_accepts += pairflips + flips - last_flips ;
    last_flips = pairflips + flips ;

    if( ++temp_timer >= time_to_update || 
			(attemptsG >= attmaxG && temp_timer >= 50) ) {
	ratioG = ((DOUBLE)(num_accepts)) / (DOUBLE) temp_timer ;
	temp_timer = 0 ; /* reset counter */
	num_accepts = 0 ;
	iter_time = (DOUBLE) iterationG +
		    (DOUBLE) attemptsG / (DOUBLE) attmaxG ;
	accept_deviation = 
	    (calc_acceptance_ratio( iter_time ) - ratioG ) ;
	if( (DOUBLE) iterationG < TURNOFFT ) {
	    accept_deviation *= ACCEPTDAMPFACTOR ; 
	} else {
	    accept_deviation *= ACCEPTDAMPFACTOR2 ;
	}
	TG *= 1.0 + accept_deviation ;
	update_window_size( (DOUBLE) iterationG +
			    (DOUBLE) attemptsG / (DOUBLE) attmaxG ) ;
    }


}   /* end of inner loop */

D( "uloop",
    check_cost() ;
) ;