32#define ATTACH_FULL (~((unsigned)0))
33#define ATTACH_MASK(n) ((~((unsigned)0)) >> (32-(n)))
35static void Abc_AttachSetupTruthTables(
unsigned uTruths[][2] );
36static void Abc_AttachComputeTruth(
char * pSop,
unsigned uTruthsIn[][2],
unsigned * uTruthNode );
37static Mio_Gate_t * Abc_AttachFind(
Mio_Gate_t ** ppGates,
unsigned ** puTruthGates,
int nGates,
unsigned * uTruthNode,
int * Perm );
38static int Abc_AttachCompare(
unsigned ** puTruthGates,
int nGates,
unsigned * uTruthNode );
39static int Abc_NodeAttach(
Abc_Obj_t * pNode,
Mio_Gate_t ** ppGates,
unsigned ** puTruthGates,
int nGates,
unsigned uTruths[][2] );
40static void Abc_TruthPermute(
char * pPerm,
int nVars,
unsigned * uTruthNode,
unsigned * uTruthPerm );
42static char ** s_pPerms = NULL;
63 unsigned ** puTruthGates;
64 unsigned uTruths[6][2];
67 int nGates, nFanins, i;
69 assert( Abc_NtkIsSopLogic(pNtk) );
73 if ( pGenlib == NULL )
75 printf(
"The current library is not available.\n" );
80 Abc_AttachSetupTruthTables( uTruths );
86 puTruthGates =
ABC_ALLOC(
unsigned *, nGates );
87 puTruthGates[0] =
ABC_ALLOC(
unsigned, 2 * nGates );
88 for ( i = 1; i < nGates; i++ )
89 puTruthGates[i] = puTruthGates[i-1] + 2;
90 for ( i = 0; i < nGates; i++ )
97 nFanins = Abc_ObjFaninNum(pNode);
105 else if ( nFanins == 1 )
112 else if ( nFanins > 6 )
114 printf(
"Cannot attach gate with more than 6 inputs to node %s.\n",
Abc_ObjName(pNode) );
120 else if ( !Abc_NodeAttach( pNode, ppGates, puTruthGates, nGates, uTruths ) )
122 printf(
"Could not attach the library gate to node %s.\n",
Abc_ObjName(pNode) );
137 if ( pNode->
pCopy == NULL )
139 printf(
"Some elementary gates (constant, buffer, or inverter) are missing in the library.\n" );
151 printf(
"Library gates are successfully attached to the nodes.\n" );
156 printf(
"Abc_NtkAttach: The network check has failed.\n" );
173int Abc_NodeAttach(
Abc_Obj_t * pNode,
Mio_Gate_t ** ppGates,
unsigned ** puTruthGates,
int nGates,
unsigned uTruths[][2] )
177 unsigned uTruthNode[2];
183 Abc_AttachComputeTruth( (
char *)pNode->
pData, uTruths, uTruthNode );
185 pGate = Abc_AttachFind( ppGates, puTruthGates, nGates, uTruthNode, Perm );
189 nFanins = Abc_ObjFaninNum(pNode);
191 pTempInts[i] = pFanin->
Id;
192 for ( i = 0; i < nFanins; i++ )
193 pNode->
vFanins.pArray[Perm[i]] = pTempInts[i];
210void Abc_AttachSetupTruthTables(
unsigned uTruths[][2] )
213 for ( v = 0; v < 5; v++ )
216 for ( m = 0; m < 32; m++ )
217 for ( v = 0; v < 5; v++ )
219 uTruths[v][0] |= (1 << m);
221 for ( v = 0; v < 5; v++ )
222 uTruths[v][1] = uTruths[v][0];
238void Abc_AttachComputeTruth(
char * pSop,
unsigned uTruthsIn[][2],
unsigned * uTruthRes )
241 unsigned uSignCube[2];
266 uSignCube[0] &= ~uTruthsIn[k][0];
267 else if ( Value ==
'1' )
268 uSignCube[0] &= uTruthsIn[k][0];
270 uTruthRes[0] |= uSignCube[0];
273 uTruthRes[0] = ~uTruthRes[0];
290 uSignCube[0] &= ~uTruthsIn[k][0];
291 uSignCube[1] &= ~uTruthsIn[k][1];
293 else if ( Value ==
'1' )
295 uSignCube[0] &= uTruthsIn[k][0];
296 uSignCube[1] &= uTruthsIn[k][1];
299 uTruthRes[0] |= uSignCube[0];
300 uTruthRes[1] |= uSignCube[1];
306 uTruthRes[0] = ~uTruthRes[0];
307 uTruthRes[1] = ~uTruthRes[1];
323Mio_Gate_t * Abc_AttachFind(
Mio_Gate_t ** ppGates,
unsigned ** puTruthGates,
int nGates,
unsigned * uTruthNode,
int * Perm )
325 unsigned uTruthPerm[2];
329 if ( (iNum = Abc_AttachCompare( puTruthGates, nGates, uTruthNode )) >= 0 )
331 for ( v = 0; v < 6; v++ )
333 return ppGates[iNum];
336 if ( s_pPerms == NULL )
342 for ( i = 0; i < s_nPerms; i++ )
344 Abc_TruthPermute( s_pPerms[i], 6, uTruthNode, uTruthPerm );
345 if ( (iNum = Abc_AttachCompare( puTruthGates, nGates, uTruthPerm )) >= 0 )
347 for ( v = 0; v < 6; v++ )
348 Perm[v] = (
int)s_pPerms[i][v];
349 return ppGates[iNum];
366int Abc_AttachCompare(
unsigned ** puTruthGates,
int nGates,
unsigned * uTruthNode )
369 for ( i = 0; i < nGates; i++ )
370 if ( puTruthGates[i][0] == uTruthNode[0] && puTruthGates[i][1] == uTruthNode[1] )
386void Abc_TruthPermute(
char * pPerm,
int nVars,
unsigned * uTruthNode,
unsigned * uTruthPerm )
388 int nMints, iMintPerm, iMint, v;
389 uTruthPerm[0] = uTruthPerm[1] = 0;
390 nMints = (1 << nVars);
391 for ( iMint = 0; iMint < nMints; iMint++ )
393 if ( (uTruthNode[iMint>>5] & (1 << (iMint&31))) == 0 )
396 for ( v = 0; v < nVars; v++ )
397 if ( iMint & (1 << v) )
398 iMintPerm |= (1 << pPerm[v]);
399 uTruthPerm[iMintPerm>>5] |= (1 << (iMintPerm&31));
int Abc_NtkAttach(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define ATTACH_FULL
DECLARATIONS ///.
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_ObjForEachFanin(pObj, pFanin, i)
ABC_DLL int Abc_SopGetPhase(char *pSop)
#define Abc_CubeForEachVar(pCube, Value, i)
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
struct Abc_Ntk_t_ Abc_Ntk_t
#define Abc_SopForEachCube(pSop, nFanins, pCube)
ABC_DLL int Abc_SopGetVarNum(char *pSop)
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_SopIsBuf(char *pSop)
ABC_DLL int Abc_SopIsConst1(char *pSop)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void * Abc_FrameReadLibGen()
Mio_Gate_t * Mio_LibraryReadConst0(Mio_Library_t *pLib)
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Mio_Gate_t ** Mio_CollectRoots(Mio_Library_t *pLib, int nInputs, float tDelay, int fSkipInv, int *pnGates, int fVerbose)
void Mio_DeriveTruthTable(Mio_Gate_t *pGate, unsigned uTruthsIn[][2], int nSigns, int nInputs, unsigned uTruthRes[])
struct Mio_LibraryStruct_t_ Mio_Library_t
Mio_Gate_t * Mio_LibraryReadConst1(Mio_Library_t *pLib)
Mio_Gate_t * Mio_LibraryReadInv(Mio_Library_t *pLib)
struct Mio_GateStruct_t_ Mio_Gate_t
Mio_Gate_t * Mio_LibraryReadBuf(Mio_Library_t *pLib)