summaryrefslogtreecommitdiffstats
path: root/src/misc/tim
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-09-22 17:57:06 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-09-22 17:57:06 -0700
commita50a38155cd4e99e76775c36987e8bc41c61f0c6 (patch)
tree9caf7885e0015e423f7d5c01b16d4d71ff7bf3e2 /src/misc/tim
parent26f3427a1e4cfb908c389b57100166eb2c35434f (diff)
downloadabc-a50a38155cd4e99e76775c36987e8bc41c61f0c6.tar.gz
abc-a50a38155cd4e99e76775c36987e8bc41c61f0c6.tar.bz2
abc-a50a38155cd4e99e76775c36987e8bc41c61f0c6.zip
Integrating time manager into choice computation.
Diffstat (limited to 'src/misc/tim')
-rw-r--r--src/misc/tim/timBox.c6
-rw-r--r--src/misc/tim/timDump.c13
-rw-r--r--src/misc/tim/timInt.h3
-rw-r--r--src/misc/tim/timMan.c107
4 files changed, 76 insertions, 53 deletions
diff --git a/src/misc/tim/timBox.c b/src/misc/tim/timBox.c
index 65b0ae6e..c1176527 100644
--- a/src/misc/tim/timBox.c
+++ b/src/misc/tim/timBox.c
@@ -189,10 +189,14 @@ int Tim_ManBoxOutputNum( Tim_Man_t * p, int iBox )
***********************************************************************/
float * Tim_ManBoxDelayTable( Tim_Man_t * p, int iBox )
{
+ float * pTable;
Tim_Box_t * pBox = (Tim_Box_t *)Vec_PtrEntry( p->vBoxes, iBox );
if ( pBox->iDelayTable < 0 )
return NULL;
- return (float *)Vec_PtrEntry( p->vDelayTables, pBox->iDelayTable );
+ pTable = (float *)Vec_PtrEntry( p->vDelayTables, pBox->iDelayTable );
+ assert( (int)pTable[1] == pBox->nInputs );
+ assert( (int)pTable[2] == pBox->nOutputs );
+ return pTable;
}
////////////////////////////////////////////////////////////////////////
diff --git a/src/misc/tim/timDump.c b/src/misc/tim/timDump.c
index 031ef5fc..eb9a14a9 100644
--- a/src/misc/tim/timDump.c
+++ b/src/misc/tim/timDump.c
@@ -63,6 +63,7 @@ Vec_Str_t * Tim_ManSave( Tim_Man_t * p )
// save number of boxes
Vec_StrPutI_ne( vStr, Tim_ManBoxNum(p) );
// for each box, save num_inputs, num_outputs, and delay table ID
+ if ( Tim_ManBoxNum(p) > 0 )
Tim_ManForEachBox( p, pBox, i )
{
Vec_StrPutI_ne( vStr, Tim_ManBoxInputNum(p, pBox->iBox) );
@@ -72,7 +73,8 @@ Vec_Str_t * Tim_ManSave( Tim_Man_t * p )
// save the number of delay tables
Vec_StrPutI_ne( vStr, Tim_ManDelayTableNum(p) );
// save the delay tables
- Vec_PtrForEachEntry( float *, p->vDelayTables, pDelayTable, i )
+ if ( Tim_ManDelayTableNum(p) > 0 )
+ Tim_ManForEachTable( p, pDelayTable, i )
{
assert( (int)pDelayTable[0] == i );
// save table ID and dimensions (inputs x outputs)
@@ -126,7 +128,8 @@ Tim_Man_t * Tim_ManLoad( Vec_Str_t * p )
// start boxes
nBoxes = Vec_StrGetI_ne( p, &iStr );
assert( pMan->vBoxes == NULL );
- pMan->vBoxes = Vec_PtrAlloc( nBoxes );
+ if ( nBoxes > 0 )
+ pMan->vBoxes = Vec_PtrAlloc( nBoxes );
// create boxes
curPi = nPis;
curPo = 0;
@@ -145,9 +148,9 @@ Tim_Man_t * Tim_ManLoad( Vec_Str_t * p )
// create delay tables
nTables = Vec_StrGetI_ne( p, &iStr );
assert( pMan->vDelayTables == NULL );
- pMan->vDelayTables = Vec_PtrAlloc( nTables );
+ if ( nTables > 0 )
+ pMan->vDelayTables = Vec_PtrAlloc( nTables );
// read delay tables
- assert( Vec_PtrSize(pMan->vDelayTables) == 0 );
for ( i = 0; i < nTables; i++ )
{
// read table ID and dimensions
@@ -167,7 +170,7 @@ Tim_Man_t * Tim_ManLoad( Vec_Str_t * p )
assert( Vec_PtrSize(pMan->vDelayTables) == TableId );
Vec_PtrPush( pMan->vDelayTables, pDelayTable );
}
- assert( Vec_PtrSize(pMan->vDelayTables) == nTables );
+ assert( Tim_ManDelayTableNum(pMan) == nTables );
// Tim_ManPrint( pMan );
return pMan;
}
diff --git a/src/misc/tim/timInt.h b/src/misc/tim/timInt.h
index 9d8b7389..6fe5a94c 100644
--- a/src/misc/tim/timInt.h
+++ b/src/misc/tim/timInt.h
@@ -128,6 +128,9 @@ static inline Tim_Obj_t * Tim_ManBoxOutput( Tim_Man_t * p, Tim_Box_t * pBox, int
#define Tim_ManBoxForEachOutput( p, pBox, pObj, i ) \
for ( i = 0; (i < (pBox)->nOutputs) && ((pObj) = Tim_ManBoxOutput(p, pBox, i)); i++ )
+#define Tim_ManForEachTable( p, pTable, i ) \
+ Vec_PtrForEachEntry( float *, p->vDelayTables, pTable, i )
+
////////////////////////////////////////////////////////////////////////
/// SEQUENTIAL ITERATORS ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/misc/tim/timMan.c b/src/misc/tim/timMan.c
index 5340ad9e..c177a707 100644
--- a/src/misc/tim/timMan.c
+++ b/src/misc/tim/timMan.c
@@ -112,25 +112,32 @@ Tim_Man_t * Tim_ManDup( Tim_Man_t * p, int fUnitDelay )
Tim_ManInitPoRequiredAll( p, (float)TIM_ETERNITY );
}
// duplicate delay tables
- pNew->vDelayTables = Vec_PtrAlloc( Vec_PtrSize(p->vDelayTables) );
- Vec_PtrForEachEntry( float *, p->vDelayTables, pDelayTable, i )
+ if ( Tim_ManDelayTableNum(p) > 0 )
{
- assert( i == (int)pDelayTable[0] );
- nInputs = (int)pDelayTable[1];
- nOutputs = (int)pDelayTable[2];
- pDelayTableNew = ABC_ALLOC( float, 3 + nInputs * nOutputs );
- pDelayTableNew[0] = (int)pDelayTable[0];
- pDelayTableNew[1] = (int)pDelayTable[1];
- pDelayTableNew[2] = (int)pDelayTable[2];
- for ( k = 0; k < nInputs * nOutputs; k++ )
- pDelayTableNew[3+k] = fUnitDelay ? 1.0 : pDelayTable[3+k];
- assert( (int)pDelayTableNew[0] == Vec_PtrSize(pNew->vDelayTables) );
- Vec_PtrPush( pNew->vDelayTables, pDelayTableNew );
+ pNew->vDelayTables = Vec_PtrAlloc( Vec_PtrSize(p->vDelayTables) );
+ Tim_ManForEachTable( p, pDelayTable, i )
+ {
+ assert( i == (int)pDelayTable[0] );
+ nInputs = (int)pDelayTable[1];
+ nOutputs = (int)pDelayTable[2];
+ pDelayTableNew = ABC_ALLOC( float, 3 + nInputs * nOutputs );
+ pDelayTableNew[0] = (int)pDelayTable[0];
+ pDelayTableNew[1] = (int)pDelayTable[1];
+ pDelayTableNew[2] = (int)pDelayTable[2];
+ for ( k = 0; k < nInputs * nOutputs; k++ )
+ pDelayTableNew[3+k] = fUnitDelay ? 1.0 : pDelayTable[3+k];
+ assert( (int)pDelayTableNew[0] == Vec_PtrSize(pNew->vDelayTables) );
+ Vec_PtrPush( pNew->vDelayTables, pDelayTableNew );
+ }
}
// duplicate boxes
- Tim_ManForEachBox( p, pBox, i )
- Tim_ManCreateBox( pNew, pBox->Inouts[0], pBox->nInputs,
- pBox->Inouts[pBox->nInputs], pBox->nOutputs, pBox->iDelayTable );
+ if ( Tim_ManBoxNum(p) > 0 )
+ {
+ pNew->vBoxes = Vec_PtrAlloc( Tim_ManBoxNum(p) );
+ Tim_ManForEachBox( p, pBox, i )
+ Tim_ManCreateBox( pNew, pBox->Inouts[0], pBox->nInputs,
+ pBox->Inouts[pBox->nInputs], pBox->nOutputs, pBox->iDelayTable );
+ }
return pNew;
}
@@ -147,15 +154,8 @@ Tim_Man_t * Tim_ManDup( Tim_Man_t * p, int fUnitDelay )
***********************************************************************/
void Tim_ManStop( Tim_Man_t * p )
{
- float * pTable;
- int i;
- if ( p->vDelayTables )
- {
- Vec_PtrForEachEntry( float *, p->vDelayTables, pTable, i )
- ABC_FREE( pTable );
- Vec_PtrFree( p->vDelayTables );
- }
- Vec_PtrFree( p->vBoxes );
+ Vec_PtrFreeFree( p->vDelayTables );
+ Vec_PtrFreeP( &p->vBoxes );
Mem_FlexStop( p->pMemObj, 0 );
ABC_FREE( p->pCis );
ABC_FREE( p->pCos );
@@ -185,7 +185,7 @@ void Tim_ManPrint( Tim_Man_t * p )
Tim_Box_t * pBox;
Tim_Obj_t * pObj, * pPrev;
float * pTable;
- int i, k;
+ int i, j, k, TableX, TableY;
printf( "TIMING INFORMATION:\n" );
// print CI info
@@ -211,40 +211,48 @@ void Tim_ManPrint( Tim_Man_t * p )
printf( "PO%5d : arr = %5.3f req = %5.3f\n", i, pObj->timeArr, pObj->timeReq );
// print box info
+ if ( Tim_ManBoxNum(p) > 0 )
Tim_ManForEachBox( p, pBox, i )
{
- printf( "*** Box %3d : Ins = %d. Outs = %d.\n", i, pBox->nInputs, pBox->nOutputs );
- printf( "Delay table:\n" );
- pTable = Tim_ManBoxDelayTable( p, pBox->iBox );
- for ( i = 0; i < pBox->nOutputs; i++, printf( "\n" ) )
- for ( k = 0; k < pBox->nInputs; k++ )
- if ( pTable[3+i*pBox->nInputs+k] == -ABC_INFINITY )
- printf( "%5s", "-" );
- else
- printf( "%5.0f", pTable[3+i*pBox->nInputs+k] );
- printf( "\n" );
+ printf( "*** Box %5d : Ins = %4d. Outs = %4d. DelayTable = %4d\n", i, pBox->nInputs, pBox->nOutputs, pBox->iDelayTable );
// print box inputs
pPrev = Tim_ManBoxInput( p, pBox, 0 );
- Tim_ManBoxForEachInput( p, pBox, pObj, i )
+ Tim_ManBoxForEachInput( p, pBox, pObj, k )
if ( pPrev->timeArr != pObj->timeArr || pPrev->timeReq != pObj->timeReq )
break;
- if ( i == Tim_ManBoxInputNum(p, pBox->iBox) )
+ if ( k == Tim_ManBoxInputNum(p, pBox->iBox) )
printf( "Box inputs : arr = %5.3f req = %5.3f\n", pPrev->timeArr, pPrev->timeReq );
else
- Tim_ManBoxForEachInput( p, pBox, pObj, i )
- printf( "box-inp%3d : arr = %5.3f req = %5.3f\n", i, pObj->timeArr, pObj->timeReq );
+ Tim_ManBoxForEachInput( p, pBox, pObj, k )
+ printf( "box-in%4d : arr = %5.3f req = %5.3f\n", k, pObj->timeArr, pObj->timeReq );
// print box outputs
pPrev = Tim_ManBoxOutput( p, pBox, 0 );
- Tim_ManBoxForEachOutput( p, pBox, pObj, i )
+ Tim_ManBoxForEachOutput( p, pBox, pObj, k )
if ( pPrev->timeArr != pObj->timeArr || pPrev->timeReq != pObj->timeReq )
break;
- if ( i == Tim_ManBoxOutputNum(p, pBox->iBox) )
+ if ( k == Tim_ManBoxOutputNum(p, pBox->iBox) )
printf( "Box outputs : arr = %5.3f req = %5.3f\n", pPrev->timeArr, pPrev->timeReq );
else
- Tim_ManBoxForEachOutput( p, pBox, pObj, i )
- printf( "box-out%3d : arr = %5.3f req = %5.3f\n", i, pObj->timeArr, pObj->timeReq );
+ Tim_ManBoxForEachOutput( p, pBox, pObj, k )
+ printf( "box-out%3d : arr = %5.3f req = %5.3f\n", k, pObj->timeArr, pObj->timeReq );
+ }
+
+ // print delay tables
+ if ( Tim_ManDelayTableNum(p) > 0 )
+ Tim_ManForEachTable( p, pTable, i )
+ {
+ printf( "Delay table %d:\n", i );
+ assert( i == (int)pTable[0] );
+ TableX = (int)pTable[1];
+ TableY = (int)pTable[2];
+ for ( j = 0; j < TableY; j++, printf( "\n" ) )
+ for ( k = 0; k < TableX; k++ )
+ if ( pTable[3+j*TableX+k] == -ABC_INFINITY )
+ printf( "%5s", "-" );
+ else
+ printf( "%5.0f", pTable[3+j*TableX+k] );
}
printf( "\n" );
}
@@ -270,20 +278,25 @@ int Tim_ManCoNum( Tim_Man_t * p )
}
int Tim_ManPiNum( Tim_Man_t * p )
{
+ if ( Tim_ManBoxNum(p) == 0 )
+ return Tim_ManCiNum(p);
return Tim_ManBoxOutputFirst(p, 0);
}
int Tim_ManPoNum( Tim_Man_t * p )
{
- int iLastBoxId = Tim_ManBoxNum(p) - 1;
+ int iLastBoxId;
+ if ( Tim_ManBoxNum(p) == 0 )
+ return Tim_ManCoNum(p);
+ iLastBoxId = Tim_ManBoxNum(p) - 1;
return Tim_ManCoNum(p) - (Tim_ManBoxInputFirst(p, iLastBoxId) + Tim_ManBoxInputNum(p, iLastBoxId));
}
int Tim_ManBoxNum( Tim_Man_t * p )
{
- return Vec_PtrSize(p->vBoxes);
+ return p->vBoxes ? Vec_PtrSize(p->vBoxes) : 0;
}
int Tim_ManDelayTableNum( Tim_Man_t * p )
{
- return Vec_PtrSize(p->vDelayTables);
+ return p->vDelayTables ? Vec_PtrSize(p->vDelayTables) : 0;
}
/**Function*************************************************************