Skip to content

Commit 48eda6c

Browse files
committed
Final Commit
1 parent 152b352 commit 48eda6c

File tree

16 files changed

+1070
-45
lines changed

16 files changed

+1070
-45
lines changed

abc/abclib.dsp

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

abc/src/aig/gia/giaMini.c

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ Vec_Str_t * Gia_ManRetimableF( Gia_Man_t * p, int * pRst, int * pSet, int * pEna
12571257
int * pNode = Vec_IntEntryP( vTemps, 3*i );
12581258
pStops[i] = (char)1;
12591259
if ( pFan0[0] != -1 && pFan0[0] == pFan1[0] && pFan0[1] == pFan1[1] && pFan0[2] == pFan1[2] )
1260-
pStops[i] = (char)0, pNode[0] = pFan0[0], pNode[1] = pFan0[1], pNode[2] = pFan0[2];
1260+
pStops[i] = (char)0, pNode[0] = pFan0[0], pNode[1] = pFan0[1], pNode[2] = pFan0[2];
12611261
}
12621262
Vec_IntFree( vTemps );
12631263
return vStops;
@@ -1266,32 +1266,37 @@ Vec_Str_t * Gia_ManRetimableB( Gia_Man_t * p, int * pRst, int * pSet, int * pEna
12661266
{
12671267
Vec_Str_t * vStops = Vec_StrStart( Gia_ManObjNum(p) );
12681268
Vec_Int_t * vTemps = Vec_IntStartFull( 3*Gia_ManObjNum(p) );
1269-
Gia_Obj_t * pObj, * pObjRi, * pObjRo; int i, n;
1269+
Gia_Obj_t * pObj, * pObjRi, * pObjRo; int i, n, iFanout;
12701270
char * pStops = Vec_StrArray(vStops);
12711271
assert( Gia_ManRegNum(p) > 0 );
12721272
Gia_ManForEachRiRo( p, pObjRi, pObjRo, i ) {
1273-
Vec_IntWriteEntry( vTemps, 3*Gia_ObjFaninId0p(p, pObjRi) + 0, pRst[i] );
1274-
Vec_IntWriteEntry( vTemps, 3*Gia_ObjFaninId0p(p, pObjRi) + 1, pSet[i] );
1275-
Vec_IntWriteEntry( vTemps, 3*Gia_ObjFaninId0p(p, pObjRi) + 2, pEna[i] );
1273+
Vec_IntWriteEntry( vTemps, 3*Gia_ObjId(p, pObjRi) + 0, pRst[i] );
1274+
Vec_IntWriteEntry( vTemps, 3*Gia_ObjId(p, pObjRi) + 1, pSet[i] );
1275+
Vec_IntWriteEntry( vTemps, 3*Gia_ObjId(p, pObjRi) + 2, pEna[i] );
12761276
}
1277+
Gia_ManStaticFanoutStart( p );
12771278
Gia_ManForEachAndReverse( p, pObj, i ) {
1278-
int iFans[2] = { Gia_ObjFaninId0(pObj, i), Gia_ObjFaninId1(pObj, i) };
1279-
int * pFans[2] = { Vec_IntEntryP( vTemps, 3*iFans[0] ), Vec_IntEntryP( vTemps, 3*iFans[1] ) };
1279+
int * pFan0 = Vec_IntEntryP( vTemps, 3*Gia_ObjFanoutId(p, i, 0) );
12801280
int * pNode = Vec_IntEntryP( vTemps, 3*i );
1281-
if ( pNode[0] == -1 )
1281+
pStops[i] = (char)1;
1282+
if ( pFan0[0] == -1 )
12821283
continue;
1283-
for ( n = 0; n < 2; n++ )
1284-
if ( pFans[n][0] == -1 )
1285-
pStops[iFans[n]] = (char)1, pFans[n][0] = pNode[0], pFans[n][1] = pNode[1], pFans[n][2] = pNode[2];
1286-
else if ( pFans[n][0] != pNode[0] || pFans[n][1] != pNode[1] || pFans[n][2] != pNode[2] )
1287-
pStops[iFans[n]] = (char)0;
1284+
Gia_ObjForEachFanoutStaticId( p, i, iFanout, n ) {
1285+
int * pFan1 = Vec_IntEntryP( vTemps, 3*iFanout );
1286+
if ( pFan1[0] == -1 || pFan0[0] != pFan1[0] || pFan0[1] != pFan1[1] || pFan0[2] != pFan1[2] )
1287+
break;
1288+
}
1289+
if ( n < Gia_ObjFanoutNum(p, pObj) )
1290+
continue;
1291+
pStops[i] = (char)0, pNode[0] = pFan0[0], pNode[1] = pFan0[1], pNode[2] = pFan0[2];
12881292
}
1289-
pStops[0] = (char)0;
1290-
Gia_ManForEachCi( p, pObj, i )
1291-
pStops[Gia_ObjId(p, pObj)] = (char)0;
1292-
Gia_ManForEachAnd( p, pObj, i )
1293-
pStops[i] = (char)!pStops[i];
1294-
Vec_IntFree( vTemps );
1293+
Gia_ManStaticFanoutStop( p );
1294+
Vec_IntFree( vTemps );
1295+
Gia_ManForEachRiRo( p, pObjRi, pObjRo, i ) {
1296+
if ( Gia_ObjIsAnd(Gia_ManObj(p, Abc_Lit2Var(pRst[i]))) ) pStops[Abc_Lit2Var(pRst[i])] = 1;
1297+
if ( Gia_ObjIsAnd(Gia_ManObj(p, Abc_Lit2Var(pSet[i]))) ) pStops[Abc_Lit2Var(pSet[i])] = 1;
1298+
if ( Gia_ObjIsAnd(Gia_ManObj(p, Abc_Lit2Var(pEna[i]))) ) pStops[Abc_Lit2Var(pEna[i])] = 1;
1299+
}
12951300
return vStops;
12961301
}
12971302

@@ -1306,18 +1311,42 @@ Vec_Str_t * Gia_ManRetimableB( Gia_Man_t * p, int * pRst, int * pSet, int * pEna
13061311
SeeAlso []
13071312
13081313
***********************************************************************/
1309-
void Abc_FrameSetRetimingData( Abc_Frame_t * pAbc, int * pRst, int * pSet, int * pEna )
1314+
void Abc_FrameRemapLits( int * pLits, int nLits, Vec_Int_t * vMap )
1315+
{
1316+
for ( int i = 0; i < nLits; i++ )
1317+
pLits[i] = Abc_Lit2LitL( Vec_IntArray(vMap), pLits[i] );
1318+
}
1319+
void Abc_FrameSetRetimingData( Abc_Frame_t * pAbc, int * pRst, int * pSet, int * pEna, int nRegs )
13101320
{
13111321
Gia_Man_t * pGia;
1322+
int * pRstNew = ABC_CALLOC( int, nRegs );
1323+
int * pSetNew = ABC_CALLOC( int, nRegs );
1324+
int * pEnaNew = ABC_CALLOC( int, nRegs );
13121325
if ( pAbc == NULL )
13131326
printf( "ABC framework is not initialized by calling Abc_Start()\n" );
13141327
pGia = Abc_FrameReadGia( pAbc );
13151328
if ( pGia == NULL )
13161329
printf( "Current network in ABC framework is not defined.\n" );
1330+
else {
1331+
assert( nRegs == Gia_ManRegNum(pGia) );
1332+
memmove( pRstNew, pRst, sizeof(int)*nRegs );
1333+
memmove( pSetNew, pSet, sizeof(int)*nRegs );
1334+
memmove( pEnaNew, pEna, sizeof(int)*nRegs );
1335+
}
1336+
if ( pAbc->vCopyMiniAig == NULL )
1337+
printf( "Mapping of MiniAig nodes is not available.\n" );
1338+
else {
1339+
Abc_FrameRemapLits( pRstNew, nRegs, pAbc->vCopyMiniAig );
1340+
Abc_FrameRemapLits( pSetNew, nRegs, pAbc->vCopyMiniAig );
1341+
Abc_FrameRemapLits( pEnaNew, nRegs, pAbc->vCopyMiniAig );
1342+
}
13171343
assert( pGia->vStopsF == NULL );
13181344
assert( pGia->vStopsB == NULL );
1319-
pGia->vStopsF = Gia_ManRetimableF( pGia, pRst, pSet, pEna );
1320-
pGia->vStopsB = Gia_ManRetimableB( pGia, pRst, pSet, pEna );
1345+
pGia->vStopsF = Gia_ManRetimableF( pGia, pRstNew, pSetNew, pEnaNew );
1346+
pGia->vStopsB = Gia_ManRetimableB( pGia, pRstNew, pSetNew, pEnaNew );
1347+
ABC_FREE( pRstNew );
1348+
ABC_FREE( pSetNew );
1349+
ABC_FREE( pEnaNew );
13211350
}
13221351

13231352
////////////////////////////////////////////////////////////////////////

abc/src/aig/gia/giaUtil.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,119 @@ void Gia_ManPrintArray( Gia_Man_t * p )
31613161
printf( "};\n" );
31623162

31633163
}
3164+
3165+
3166+
/**Function*************************************************************
3167+
3168+
Synopsis []
3169+
3170+
Description []
3171+
3172+
SideEffects []
3173+
3174+
SeeAlso []
3175+
3176+
***********************************************************************/
3177+
int Gia_GetMValue( int i, int nIns, int Mint, unsigned Truth )
3178+
{
3179+
assert( i >= 0 && i < 16 );
3180+
if ( i < nIns )
3181+
return (Mint >> i) & 1;
3182+
if ( i == nIns )
3183+
{
3184+
if ( Mint < (1 << nIns) )
3185+
return (Truth >> Mint) & 1;
3186+
else
3187+
return ((Truth >> (Mint-(1 << nIns))) & 1) == 0;
3188+
}
3189+
else
3190+
return 1;
3191+
}
3192+
void Gia_ManTestProblem()
3193+
{
3194+
unsigned Truth = 0xFE;
3195+
int i, j, k, c, nIns = 3, nAux = 3;
3196+
int nTotal = nIns + 1 + nAux;
3197+
int nPairs = nTotal * (nTotal - 1) / 2;
3198+
int nMints = (1 << (nIns+1));
3199+
int M[64][100] = {{0}};
3200+
float Value[64] = {0};
3201+
float Solution[100] = {0};
3202+
assert( nMints <= 64 );
3203+
assert( nPairs <= 100 );
3204+
// 7 nodes: 3 inputs + 1 output + 3 aux
3205+
// 7*6/2 = 21 pairs
3206+
// 16 minterms
3207+
for ( k = 0; k < nMints; k++ )
3208+
{
3209+
for ( i = c = 0; i < nTotal; i++ )
3210+
for ( j = i+1; j < nTotal; j++ )
3211+
{
3212+
int iVal = Gia_GetMValue( i, nIns, k, Truth );
3213+
int jVal = Gia_GetMValue( j, nIns, k, Truth );
3214+
M[k][c++] = iVal == jVal ? 1 : -1;
3215+
}
3216+
Value[k] = k < (1 << nIns) ? -1 : 1;
3217+
assert( c == nPairs );
3218+
}
3219+
3220+
for ( k = 0; k < nMints; k++ )
3221+
{
3222+
for ( c = 0; c < nPairs; c++ )
3223+
printf( "%2d ", M[k][c] );
3224+
printf( "%3f\n", Value[k] );
3225+
}
3226+
3227+
// solve
3228+
float Delta = 0.02;
3229+
for ( i = 0; i < 100; i++ )
3230+
{
3231+
float Error = 0;
3232+
for ( k = 0; k < nMints; k++ )
3233+
Error += Value[k] > 0 ? Value[k] : -Value[k];
3234+
printf( "Round %3d : Error = %5f ", i, Error );
3235+
for ( c = 0; c < nPairs; c++ )
3236+
printf( "%2f ", Solution[c] );
3237+
printf( "\n" );
3238+
3239+
//if ( Error < 1 )
3240+
// Delta /= 10;
3241+
3242+
for ( c = 0; c < nPairs; c++ )
3243+
{
3244+
int Count = 0;
3245+
for ( k = 0; k < nMints; k++ )
3246+
if ( (M[k][c] > 0 && Value[k] > 0) || (M[k][c] < 0 && Value[k] < 0) )
3247+
Count++;
3248+
else
3249+
Count--;
3250+
if ( Count == 0 )
3251+
continue;
3252+
printf( "Count = %3d ", Count );
3253+
if ( Count > 0 )
3254+
{
3255+
printf( "Increasing %d by %f\n", c, Delta );
3256+
Solution[c] += Delta;
3257+
for ( k = 0; k < nMints; k++ )
3258+
if ( M[k][c] > 0 )
3259+
Value[k] -= Delta;
3260+
else
3261+
Value[k] -= Delta;
3262+
}
3263+
else
3264+
{
3265+
printf( "Reducing %d by %f\n", c, Delta );
3266+
Solution[c] -= Delta;
3267+
for ( k = 0; k < nMints; k++ )
3268+
if ( M[k][c] > 0 )
3269+
Value[k] += Delta;
3270+
else
3271+
Value[k] += Delta;
3272+
}
3273+
}
3274+
}
3275+
}
3276+
31643277
////////////////////////////////////////////////////////////////////////
31653278
/// END OF FILE ///
31663279
////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)