abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcAttach.c File Reference
#include "base/abc/abc.h"
#include "base/main/main.h"
#include "map/mio/mio.h"

Go to the source code of this file.

Macros

#define ATTACH_FULL   (~((unsigned)0))
 DECLARATIONS ///. More...
 
#define ATTACH_MASK(n)   ((~((unsigned)0)) >> (32-(n)))
 

Functions

static void Abc_AttachSetupTruthTables (unsigned uTruths[][2])
 
static void Abc_AttachComputeTruth (char *pSop, unsigned uTruthsIn[][2], unsigned *uTruthNode)
 
static Mio_Gate_tAbc_AttachFind (Mio_Gate_t **ppGates, unsigned **puTruthGates, int nGates, unsigned *uTruthNode, int *Perm)
 
static int Abc_AttachCompare (unsigned **puTruthGates, int nGates, unsigned *uTruthNode)
 
static int Abc_NodeAttach (Abc_Obj_t *pNode, Mio_Gate_t **ppGates, unsigned **puTruthGates, int nGates, unsigned uTruths[][2])
 
static void Abc_TruthPermute (char *pPerm, int nVars, unsigned *uTruthNode, unsigned *uTruthPerm)
 
int Abc_NtkAttach (Abc_Ntk_t *pNtk)
 FUNCTION DEFINITIONS ///. More...
 

Variables

static char ** s_pPerms = NULL
 
static int s_nPerms
 

Macro Definition Documentation

#define ATTACH_FULL   (~((unsigned)0))

DECLARATIONS ///.

CFile****************************************************************

FileName [abcAttach.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Attaches the library gates to the current network.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
abcAttach.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 32 of file abcAttach.c.

#define ATTACH_MASK (   n)    ((~((unsigned)0)) >> (32-(n)))

Definition at line 33 of file abcAttach.c.

Function Documentation

int Abc_AttachCompare ( unsigned **  puTruthGates,
int  nGates,
unsigned *  uTruthNode 
)
static

Function*************************************************************

Synopsis [Find the gate by truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 366 of file abcAttach.c.

367 {
368  int i;
369  for ( i = 0; i < nGates; i++ )
370  if ( puTruthGates[i][0] == uTruthNode[0] && puTruthGates[i][1] == uTruthNode[1] )
371  return i;
372  return -1;
373 }
void Abc_AttachComputeTruth ( char *  pSop,
unsigned  uTruthsIn[][2],
unsigned *  uTruthRes 
)
static

Function*************************************************************

Synopsis [Compute the truth table of the node's cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 238 of file abcAttach.c.

239 {
240 // Mvc_Cube_t * pCube;
241  unsigned uSignCube[2];
242  int Value;
243 // int nInputs = pCover->nBits/2;
244  int nInputs = 6;
245  int nFanins = Abc_SopGetVarNum(pSop);
246  char * pCube;
247  int k;
248 
249  // make sure that the number of input truth tables in equal to the number of gate inputs
250  assert( nInputs < 7 );
251 
252  // clean the resulting truth table
253  uTruthRes[0] = 0;
254  uTruthRes[1] = 0;
255  if ( nInputs < 6 )
256  {
257  // consider the case when only one unsigned can be used
258 // Mvc_CoverForEachCube( pCover, pCube )
259  Abc_SopForEachCube( pSop, nFanins, pCube )
260  {
261  uSignCube[0] = ATTACH_FULL;
262 // Mvc_CubeForEachVarValue( pCover, pCube, Var, Value )
263  Abc_CubeForEachVar( pCube, Value, k )
264  {
265  if ( Value == '0' )
266  uSignCube[0] &= ~uTruthsIn[k][0];
267  else if ( Value == '1' )
268  uSignCube[0] &= uTruthsIn[k][0];
269  }
270  uTruthRes[0] |= uSignCube[0];
271  }
272  if ( Abc_SopGetPhase(pSop) == 0 )
273  uTruthRes[0] = ~uTruthRes[0];
274  if ( nInputs < 5 )
275  uTruthRes[0] &= ATTACH_MASK(1<<nInputs);
276  }
277  else
278  {
279  // consider the case when two unsigneds should be used
280 // Mvc_CoverForEachCube( pCover, pCube )
281  Abc_SopForEachCube( pSop, nFanins, pCube )
282  {
283  uSignCube[0] = ATTACH_FULL;
284  uSignCube[1] = ATTACH_FULL;
285 // Mvc_CubeForEachVarValue( pCover, pCube, Var, Value )
286  Abc_CubeForEachVar( pCube, Value, k )
287  {
288  if ( Value == '0' )
289  {
290  uSignCube[0] &= ~uTruthsIn[k][0];
291  uSignCube[1] &= ~uTruthsIn[k][1];
292  }
293  else if ( Value == '1' )
294  {
295  uSignCube[0] &= uTruthsIn[k][0];
296  uSignCube[1] &= uTruthsIn[k][1];
297  }
298  }
299  uTruthRes[0] |= uSignCube[0];
300  uTruthRes[1] |= uSignCube[1];
301  }
302 
303  // complement if the SOP is complemented
304  if ( Abc_SopGetPhase(pSop) == 0 )
305  {
306  uTruthRes[0] = ~uTruthRes[0];
307  uTruthRes[1] = ~uTruthRes[1];
308  }
309  }
310 }
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
#define ATTACH_MASK(n)
Definition: abcAttach.c:33
#define Abc_CubeForEachVar(pCube, Value, i)
Definition: abc.h:529
#define ATTACH_FULL
DECLARATIONS ///.
Definition: abcAttach.c:32
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define assert(ex)
Definition: util_old.h:213
ABC_DLL int Abc_SopGetPhase(char *pSop)
Definition: abcSop.c:556
Mio_Gate_t * Abc_AttachFind ( Mio_Gate_t **  ppGates,
unsigned **  puTruthGates,
int  nGates,
unsigned *  uTruthNode,
int *  Perm 
)
static

Function*************************************************************

Synopsis [Find the gate by truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 323 of file abcAttach.c.

324 {
325  unsigned uTruthPerm[2];
326  int i, v, iNum;
327 
328  // try the gates without permutation
329  if ( (iNum = Abc_AttachCompare( puTruthGates, nGates, uTruthNode )) >= 0 )
330  {
331  for ( v = 0; v < 6; v++ )
332  Perm[v] = v;
333  return ppGates[iNum];
334  }
335  // get permutations
336  if ( s_pPerms == NULL )
337  {
339  s_nPerms = Extra_Factorial( 6 );
340  }
341  // try permutations
342  for ( i = 0; i < s_nPerms; i++ )
343  {
344  Abc_TruthPermute( s_pPerms[i], 6, uTruthNode, uTruthPerm );
345  if ( (iNum = Abc_AttachCompare( puTruthGates, nGates, uTruthPerm )) >= 0 )
346  {
347  for ( v = 0; v < 6; v++ )
348  Perm[v] = (int)s_pPerms[i][v];
349  return ppGates[iNum];
350  }
351  }
352  return NULL;
353 }
static int s_nPerms
Definition: abcAttach.c:43
static int Abc_AttachCompare(unsigned **puTruthGates, int nGates, unsigned *uTruthNode)
Definition: abcAttach.c:366
static char ** s_pPerms
Definition: abcAttach.c:42
char ** Extra_Permutations(int n)
int Extra_Factorial(int n)
static void Abc_TruthPermute(char *pPerm, int nVars, unsigned *uTruthNode, unsigned *uTruthPerm)
Definition: abcAttach.c:386
void Abc_AttachSetupTruthTables ( unsigned  uTruths[][2])
static

Function*************************************************************

Synopsis [Sets up the truth tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 210 of file abcAttach.c.

211 {
212  int m, v;
213  for ( v = 0; v < 5; v++ )
214  uTruths[v][0] = 0;
215  // set up the truth tables
216  for ( m = 0; m < 32; m++ )
217  for ( v = 0; v < 5; v++ )
218  if ( m & (1 << v) )
219  uTruths[v][0] |= (1 << m);
220  // make adjustments for the case of 6 variables
221  for ( v = 0; v < 5; v++ )
222  uTruths[v][1] = uTruths[v][0];
223  uTruths[5][0] = 0;
224  uTruths[5][1] = ATTACH_FULL;
225 }
#define ATTACH_FULL
DECLARATIONS ///.
Definition: abcAttach.c:32
int Abc_NodeAttach ( Abc_Obj_t pNode,
Mio_Gate_t **  ppGates,
unsigned **  puTruthGates,
int  nGates,
unsigned  uTruths[][2] 
)
static

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 173 of file abcAttach.c.

174 {
175  int Perm[10];
176  int pTempInts[10];
177  unsigned uTruthNode[2];
178  Abc_Obj_t * pFanin;
179  Mio_Gate_t * pGate;
180  int nFanins, i;
181 
182  // compute the node's truth table
183  Abc_AttachComputeTruth( (char *)pNode->pData, uTruths, uTruthNode );
184  // find the matching gate and permutation
185  pGate = Abc_AttachFind( ppGates, puTruthGates, nGates, uTruthNode, Perm );
186  if ( pGate == NULL )
187  return 0;
188  // permute the fanins
189  nFanins = Abc_ObjFaninNum(pNode);
190  Abc_ObjForEachFanin( pNode, pFanin, i )
191  pTempInts[i] = pFanin->Id;
192  for ( i = 0; i < nFanins; i++ )
193  pNode->vFanins.pArray[Perm[i]] = pTempInts[i];
194  // set the gate
195  pNode->pCopy = (Abc_Obj_t *)pGate;
196  return 1;
197 }
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
for(p=first;p->value< newval;p=p->next)
static Mio_Gate_t * Abc_AttachFind(Mio_Gate_t **ppGates, unsigned **puTruthGates, int nGates, unsigned *uTruthNode, int *Perm)
Definition: abcAttach.c:323
static void Abc_AttachComputeTruth(char *pSop, unsigned uTruthsIn[][2], unsigned *uTruthNode)
Definition: abcAttach.c:238
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
void * pData
Definition: abc.h:145
int Abc_NtkAttach ( Abc_Ntk_t pNtk)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Attaches gates from the current library to the internal nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 60 of file abcAttach.c.

61 {
62  Mio_Library_t * pGenlib;
63  unsigned ** puTruthGates;
64  unsigned uTruths[6][2];
65  Abc_Obj_t * pNode;
66  Mio_Gate_t ** ppGates;
67  int nGates, nFanins, i;
68 
69  assert( Abc_NtkIsSopLogic(pNtk) );
70 
71  // check that the library is available
72  pGenlib = (Mio_Library_t *)Abc_FrameReadLibGen();
73  if ( pGenlib == NULL )
74  {
75  printf( "The current library is not available.\n" );
76  return 0;
77  }
78 
79  // start the truth tables
80  Abc_AttachSetupTruthTables( uTruths );
81 
82  // collect all the gates
83  ppGates = Mio_CollectRoots( pGenlib, 6, (float)1.0e+20, 1, &nGates, 0 );
84 
85  // derive the gate truth tables
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++ )
91  Mio_DeriveTruthTable( ppGates[i], uTruths, Mio_GateReadPinNum(ppGates[i]), 6, puTruthGates[i] );
92 
93  // assign the gates to pNode->pCopy
94  Abc_NtkCleanCopy( pNtk );
95  Abc_NtkForEachNode( pNtk, pNode, i )
96  {
97  nFanins = Abc_ObjFaninNum(pNode);
98  if ( nFanins == 0 )
99  {
100  if ( Abc_SopIsConst1((char *)pNode->pData) )
101  pNode->pCopy = (Abc_Obj_t *)Mio_LibraryReadConst1(pGenlib);
102  else
103  pNode->pCopy = (Abc_Obj_t *)Mio_LibraryReadConst0(pGenlib);
104  }
105  else if ( nFanins == 1 )
106  {
107  if ( Abc_SopIsBuf((char *)pNode->pData) )
108  pNode->pCopy = (Abc_Obj_t *)Mio_LibraryReadBuf(pGenlib);
109  else
110  pNode->pCopy = (Abc_Obj_t *)Mio_LibraryReadInv(pGenlib);
111  }
112  else if ( nFanins > 6 )
113  {
114  printf( "Cannot attach gate with more than 6 inputs to node %s.\n", Abc_ObjName(pNode) );
115  ABC_FREE( puTruthGates[0] );
116  ABC_FREE( puTruthGates );
117  ABC_FREE( ppGates );
118  return 0;
119  }
120  else if ( !Abc_NodeAttach( pNode, ppGates, puTruthGates, nGates, uTruths ) )
121  {
122  printf( "Could not attach the library gate to node %s.\n", Abc_ObjName(pNode) );
123  ABC_FREE( puTruthGates[0] );
124  ABC_FREE( puTruthGates );
125  ABC_FREE( ppGates );
126  return 0;
127  }
128  }
129  ABC_FREE( puTruthGates[0] );
130  ABC_FREE( puTruthGates );
131  ABC_FREE( ppGates );
132  ABC_FREE( s_pPerms );
133 
134  // perform the final transformation
135  Abc_NtkForEachNode( pNtk, pNode, i )
136  {
137  if ( pNode->pCopy == NULL )
138  {
139  printf( "Some elementary gates (constant, buffer, or inverter) are missing in the library.\n" );
140  return 0;
141  }
142  }
143 
144  // replace SOP representation by the gate representation
145  Abc_NtkForEachNode( pNtk, pNode, i )
146  pNode->pData = pNode->pCopy, pNode->pCopy = NULL;
147  pNtk->ntkFunc = ABC_FUNC_MAP;
148  Extra_MmFlexStop( (Extra_MmFlex_t *)pNtk->pManFunc );
149  pNtk->pManFunc = pGenlib;
150 
151  printf( "Library gates are successfully attached to the nodes.\n" );
152 
153  // make sure that everything is okay
154  if ( !Abc_NtkCheck( pNtk ) )
155  {
156  printf( "Abc_NtkAttach: The network check has failed.\n" );
157  return 0;
158  }
159  return 1;
160 }
Mio_Gate_t * Mio_LibraryReadBuf(Mio_Library_t *pLib)
Definition: mioApi.c:47
ABC_DLL void * Abc_FrameReadLibGen()
Definition: mainFrame.c:56
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static int Abc_NtkIsSopLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:264
static char ** s_pPerms
Definition: abcAttach.c:42
ABC_DLL int Abc_SopIsBuf(char *pSop)
Definition: abcSop.c:708
Mio_Gate_t * Mio_LibraryReadConst1(Mio_Library_t *pLib)
Definition: mioApi.c:50
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition: mioApi.c:151
Abc_Obj_t * pCopy
Definition: abc.h:148
if(last==0)
Definition: sparse_int.h:34
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
ABC_DLL int Abc_SopIsConst1(char *pSop)
Definition: abcSop.c:692
void Mio_DeriveTruthTable(Mio_Gate_t *pGate, unsigned uTruthsIn[][2], int nSigns, int nInputs, unsigned uTruthRes[])
Definition: mioUtils.c:608
static void Abc_AttachSetupTruthTables(unsigned uTruths[][2])
Definition: abcAttach.c:210
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
Mio_Gate_t ** Mio_CollectRoots(Mio_Library_t *pLib, int nInputs, float tDelay, int fSkipInv, int *pnGates, int fVerbose)
Definition: mioUtils.c:302
static int Abc_NodeAttach(Abc_Obj_t *pNode, Mio_Gate_t **ppGates, unsigned **puTruthGates, int nGates, unsigned uTruths[][2])
Definition: abcAttach.c:173
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
Mio_Gate_t * Mio_LibraryReadConst0(Mio_Library_t *pLib)
Definition: mioApi.c:49
Mio_Gate_t * Mio_LibraryReadInv(Mio_Library_t *pLib)
Definition: mioApi.c:48
void Extra_MmFlexStop(Extra_MmFlex_t *p)
void Abc_TruthPermute ( char *  pPerm,
int  nVars,
unsigned *  uTruthNode,
unsigned *  uTruthPerm 
)
static

Function*************************************************************

Synopsis [Permutes the 6-input truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 386 of file abcAttach.c.

387 {
388  int nMints, iMintPerm, iMint, v;
389  uTruthPerm[0] = uTruthPerm[1] = 0;
390  nMints = (1 << nVars);
391  for ( iMint = 0; iMint < nMints; iMint++ )
392  {
393  if ( (uTruthNode[iMint>>5] & (1 << (iMint&31))) == 0 )
394  continue;
395  iMintPerm = 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));
400  }
401 }
static int pPerm[13719]
Definition: rwrTemp.c:32

Variable Documentation

int s_nPerms
static

Definition at line 43 of file abcAttach.c.

char** s_pPerms = NULL
static

Definition at line 42 of file abcAttach.c.