abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cutOracle.c File Reference
#include "cutInt.h"

Go to the source code of this file.

Data Structures

struct  Cut_OracleStruct_t_
 DECLARATIONS ///. More...
 

Functions

static Cut_Cut_tCut_CutStart (Cut_Oracle_t *p)
 
static Cut_Cut_tCut_CutTriv (Cut_Oracle_t *p, int Node)
 
static Cut_Cut_tCut_CutMerge (Cut_Oracle_t *p, Cut_Cut_t *pCut0, Cut_Cut_t *pCut1)
 
Cut_Oracle_tCut_OracleStart (Cut_Man_t *pMan)
 FUNCTION DEFINITIONS ///. More...
 
void Cut_OracleStop (Cut_Oracle_t *p)
 
void Cut_OracleSetFanoutCounts (Cut_Oracle_t *p, Vec_Int_t *vFanCounts)
 
int Cut_OracleReadDrop (Cut_Oracle_t *p)
 
void Cut_OracleNodeSetTriv (Cut_Oracle_t *p, int Node)
 
Cut_Cut_tCut_OracleComputeCuts (Cut_Oracle_t *p, int Node, int Node0, int Node1, int fCompl0, int fCompl1)
 
void Cut_OracleFreeCuts (Cut_Oracle_t *p, int Node)
 
void Cut_OracleTryDroppingCuts (Cut_Oracle_t *p, int Node)
 

Function Documentation

Cut_Cut_t * Cut_CutMerge ( Cut_Oracle_t p,
Cut_Cut_t pCut0,
Cut_Cut_t pCut1 
)
static

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

Synopsis [Merges two cuts.]

Description []

SideEffects []

SeeAlso []

Definition at line 262 of file cutOracle.c.

263 {
264  Cut_Cut_t * pCut;
265  int Limit, i, k, c;
266  // create the leaves of the new cut
267  pCut = Cut_CutStart( p );
268  Limit = p->pParams->nVarsMax;
269  for ( i = k = c = 0; c < Limit; c++ )
270  {
271  if ( k == (int)pCut1->nLeaves )
272  {
273  if ( i == (int)pCut0->nLeaves )
274  {
275  pCut->nLeaves = c;
276  return pCut;
277  }
278  pCut->pLeaves[c] = pCut0->pLeaves[i++];
279  continue;
280  }
281  if ( i == (int)pCut0->nLeaves )
282  {
283  if ( k == (int)pCut1->nLeaves )
284  {
285  pCut->nLeaves = c;
286  return pCut;
287  }
288  pCut->pLeaves[c] = pCut1->pLeaves[k++];
289  continue;
290  }
291  if ( pCut0->pLeaves[i] < pCut1->pLeaves[k] )
292  {
293  pCut->pLeaves[c] = pCut0->pLeaves[i++];
294  continue;
295  }
296  if ( pCut0->pLeaves[i] > pCut1->pLeaves[k] )
297  {
298  pCut->pLeaves[c] = pCut1->pLeaves[k++];
299  continue;
300  }
301  pCut->pLeaves[c] = pCut0->pLeaves[i++];
302  k++;
303  }
304  assert( i == (int)pCut0->nLeaves && k == (int)pCut1->nLeaves );
305  pCut->nLeaves = c;
306  return pCut;
307 }
Cut_Params_t * pParams
Definition: cutOracle.c:33
static Cut_Cut_t * Cut_CutStart(Cut_Oracle_t *p)
Definition: cutOracle.c:211
int pLeaves[0]
Definition: cut.h:89
unsigned nLeaves
Definition: cut.h:84
#define assert(ex)
Definition: util_old.h:213
Cut_Cut_t * Cut_CutStart ( Cut_Oracle_t p)
static

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

Synopsis [Allocates the cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 211 of file cutOracle.c.

212 {
213  Cut_Cut_t * pCut;
214  // cut allocation
215  pCut = (Cut_Cut_t *)Extra_MmFixedEntryFetch( p->pMmCuts );
216  memset( pCut, 0, sizeof(Cut_Cut_t) );
217  pCut->nVarsMax = p->pParams->nVarsMax;
218  pCut->fSimul = p->fSimul;
219  p->nCuts++;
220  return pCut;
221 }
char * memset()
Extra_MmFixed_t * pMmCuts
Definition: cutOracle.c:45
unsigned fSimul
Definition: cut.h:81
Cut_Params_t * pParams
Definition: cutOracle.c:33
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
unsigned nVarsMax
Definition: cut.h:83
Cut_Cut_t * Cut_CutTriv ( Cut_Oracle_t p,
int  Node 
)
static

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

Synopsis [Creates the trivial cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 234 of file cutOracle.c.

235 {
236  Cut_Cut_t * pCut;
237  pCut = Cut_CutStart( p );
238  pCut->nLeaves = 1;
239  pCut->pLeaves[0] = Node;
240  if ( p->pParams->fTruth )
241  {
242  unsigned * pTruth = Cut_CutReadTruth(pCut);
243  int i;
244  for ( i = 0; i < p->nTruthWords; i++ )
245  pTruth[i] = 0xAAAAAAAA;
246  }
247  p->nCutsTriv++;
248  return pCut;
249 }
static unsigned * Cut_CutReadTruth(Cut_Cut_t *p)
Definition: cut.h:94
Cut_Params_t * pParams
Definition: cutOracle.c:33
static Cut_Cut_t * Cut_CutStart(Cut_Oracle_t *p)
Definition: cutOracle.c:211
int pLeaves[0]
Definition: cut.h:89
unsigned nLeaves
Definition: cut.h:84
Cut_Cut_t* Cut_OracleComputeCuts ( Cut_Oracle_t p,
int  Node,
int  Node0,
int  Node1,
int  fCompl0,
int  fCompl1 
)

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

Synopsis [Reconstruct the cuts of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 320 of file cutOracle.c.

321 {
322  Cut_Cut_t * pList = NULL, ** ppTail = &pList;
323  Cut_Cut_t * pCut, * pCut0, * pCut1, * pList0, * pList1;
324  int iCutStart, nCuts, i, Entry;
325  abctime clk = Abc_Clock();
326 
327  // get the cuts of the children
328  pList0 = (Cut_Cut_t *)Vec_PtrEntry( p->vCutsNew, Node0 );
329  pList1 = (Cut_Cut_t *)Vec_PtrEntry( p->vCutsNew, Node1 );
330  assert( pList0 && pList1 );
331 
332  // get the complemented attribute of the cut
333  p->fSimul = (fCompl0 ^ pList0->fSimul) & (fCompl1 ^ pList1->fSimul);
334 
335  // collect the cuts
336  Vec_PtrClear( p->vCuts0 );
337  Cut_ListForEachCut( pList0, pCut )
338  Vec_PtrPush( p->vCuts0, pCut );
339  Vec_PtrClear( p->vCuts1 );
340  Cut_ListForEachCut( pList1, pCut )
341  Vec_PtrPush( p->vCuts1, pCut );
342 
343  // get the first and last cuts of this node
344  nCuts = Vec_IntEntry(p->vNodeCuts, Node);
345  iCutStart = Vec_IntEntry(p->vNodeStarts, Node);
346 
347  // create trivial cut
348  assert( Vec_IntEntry(p->vCutPairs, iCutStart) == 0 );
349  pCut = Cut_CutTriv( p, Node );
350  *ppTail = pCut;
351  ppTail = &pCut->pNext;
352  // create other cuts
353  for ( i = 1; i < nCuts; i++ )
354  {
355  Entry = Vec_IntEntry( p->vCutPairs, iCutStart + i );
356  pCut0 = (Cut_Cut_t *)Vec_PtrEntry( p->vCuts0, Entry & 0xFFFF );
357  pCut1 = (Cut_Cut_t *)Vec_PtrEntry( p->vCuts1, Entry >> 16 );
358  pCut = Cut_CutMerge( p, pCut0, pCut1 );
359  *ppTail = pCut;
360  ppTail = &pCut->pNext;
361  // compute the truth table
362  if ( p->pParams->fTruth )
363  Cut_TruthComputeOld( pCut, pCut0, pCut1, fCompl0, fCompl1 );
364  }
365  *ppTail = NULL;
366 
367  // write the new cut
368  assert( Vec_PtrEntry( p->vCutsNew, Node ) == NULL );
369  Vec_PtrWriteEntry( p->vCutsNew, Node, pList );
370 p->timeTotal += Abc_Clock() - clk;
371  return pList;
372 }
void Cut_TruthComputeOld(Cut_Cut_t *pCut, Cut_Cut_t *pCut0, Cut_Cut_t *pCut1, int fCompl0, int fCompl1)
Definition: cutTruth.c:126
static Cut_Cut_t * Cut_CutMerge(Cut_Oracle_t *p, Cut_Cut_t *pCut0, Cut_Cut_t *pCut1)
Definition: cutOracle.c:262
unsigned fSimul
Definition: cut.h:81
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static abctime Abc_Clock()
Definition: abc_global.h:279
for(p=first;p->value< newval;p=p->next)
static Cut_Cut_t * Cut_CutTriv(Cut_Oracle_t *p, int Node)
Definition: cutOracle.c:234
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
Vec_Ptr_t * vCutsNew
Definition: cutOracle.c:37
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Cut_ListForEachCut(pList, pCut)
Definition: cutInt.h:104
ABC_INT64_T abctime
Definition: abc_global.h:278
Vec_Ptr_t * vCuts0
Definition: cutOracle.c:38
void Cut_OracleFreeCuts ( Cut_Oracle_t p,
int  Node 
)

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

Synopsis [Deallocates the cuts at the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 385 of file cutOracle.c.

386 {
387  Cut_Cut_t * pList, * pCut, * pCut2;
388  pList = (Cut_Cut_t *)Vec_PtrEntry( p->vCutsNew, Node );
389  if ( pList == NULL )
390  return;
391  Cut_ListForEachCutSafe( pList, pCut, pCut2 )
392  Extra_MmFixedEntryRecycle( p->pMmCuts, (char *)pCut );
393  Vec_PtrWriteEntry( p->vCutsNew, Node, pList );
394 }
#define Cut_ListForEachCutSafe(pList, pCut, pCut2)
Definition: cutInt.h:112
Vec_Ptr_t * vCutsNew
Definition: cutOracle.c:37
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void Extra_MmFixedEntryRecycle(Extra_MmFixed_t *p, char *pEntry)
void Cut_OracleNodeSetTriv ( Cut_Oracle_t p,
int  Node 
)

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

Synopsis [Sets the trivial cut for the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 192 of file cutOracle.c.

193 {
194  assert( Vec_PtrEntry( p->vCutsNew, Node ) == NULL );
195  Vec_PtrWriteEntry( p->vCutsNew, Node, Cut_CutTriv(p, Node) );
196 }
static Cut_Cut_t * Cut_CutTriv(Cut_Oracle_t *p, int Node)
Definition: cutOracle.c:234
Vec_Ptr_t * vCutsNew
Definition: cutOracle.c:37
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define assert(ex)
Definition: util_old.h:213
int Cut_OracleReadDrop ( Cut_Oracle_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 176 of file cutOracle.c.

177 {
178  return p->pParams->fDrop;
179 }
Cut_Params_t * pParams
Definition: cutOracle.c:33
void Cut_OracleSetFanoutCounts ( Cut_Oracle_t p,
Vec_Int_t vFanCounts 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 160 of file cutOracle.c.

161 {
162  p->vFanCounts = vFanCounts;
163 }
Vec_Int_t * vFanCounts
Definition: cutOracle.c:34
Cut_Oracle_t* Cut_OracleStart ( Cut_Man_t pMan)

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the cut oracle.]

Description []

SideEffects []

SeeAlso []

Definition at line 73 of file cutOracle.c.

74 {
75  Cut_Oracle_t * p;
76 
77  assert( pMan->pParams->nVarsMax >= 3 && pMan->pParams->nVarsMax <= CUT_SIZE_MAX );
78  assert( pMan->pParams->fRecord );
79 
80  p = ABC_ALLOC( Cut_Oracle_t, 1 );
81  memset( p, 0, sizeof(Cut_Oracle_t) );
82 
83  // set and correct parameters
84  p->pParams = pMan->pParams;
85 
86  // transfer the recording info
87  p->vNodeCuts = pMan->vNodeCuts; pMan->vNodeCuts = NULL;
88  p->vNodeStarts = pMan->vNodeStarts; pMan->vNodeStarts = NULL;
89  p->vCutPairs = pMan->vCutPairs; pMan->vCutPairs = NULL;
90 
91  // prepare storage for cuts
93  Vec_PtrFill( p->vCutsNew, p->pParams->nIdsMax, NULL );
94  p->vCuts0 = Vec_PtrAlloc( 100 );
95  p->vCuts1 = Vec_PtrAlloc( 100 );
96 
97  // entry size
98  p->EntrySize = sizeof(Cut_Cut_t) + p->pParams->nVarsMax * sizeof(int);
99  if ( p->pParams->fTruth )
100  {
101  if ( p->pParams->nVarsMax > 8 )
102  {
103  p->pParams->fTruth = 0;
104  printf( "Skipping computation of truth table for more than 8 inputs.\n" );
105  }
106  else
107  {
109  p->EntrySize += p->nTruthWords * sizeof(unsigned);
110  }
111  }
112  // memory for cuts
114  return p;
115 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
Extra_MmFixed_t * pMmCuts
Definition: cutOracle.c:45
static int Cut_TruthWords(int nVarsMax)
Definition: cutInt.h:125
Cut_Params_t * pParams
Definition: cutOracle.c:33
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Vec_Int_t * vNodeCuts
Definition: cutOracle.c:41
Vec_Int_t * vNodeStarts
Definition: cutInt.h:76
#define CUT_SIZE_MAX
Definition: cut.h:39
struct Cut_CutStruct_t_ Cut_Cut_t
Definition: cut.h:50
Vec_Int_t * vCutPairs
Definition: cutInt.h:77
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
Vec_Ptr_t * vCutsNew
Definition: cutOracle.c:37
Vec_Int_t * vNodeStarts
Definition: cutOracle.c:42
Vec_Int_t * vCutPairs
Definition: cutOracle.c:43
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Vec_Int_t * vNodeCuts
Definition: cutInt.h:75
Cut_Params_t * pParams
Definition: cutInt.h:51
#define assert(ex)
Definition: util_old.h:213
DECLARATIONS ///.
Definition: cutOracle.c:30
Vec_Ptr_t * vCuts1
Definition: cutOracle.c:39
Vec_Ptr_t * vCuts0
Definition: cutOracle.c:38
void Cut_OracleStop ( Cut_Oracle_t p)

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

Synopsis [Stop the cut oracle.]

Description []

SideEffects []

SeeAlso []

Definition at line 127 of file cutOracle.c.

128 {
129 // if ( p->pParams->fVerbose )
130  {
131  printf( "Cut computation statistics with oracle:\n" );
132  printf( "Current cuts = %8d. (Trivial = %d.)\n", p->nCuts-p->nCutsTriv, p->nCutsTriv );
133  ABC_PRT( "Total time ", p->timeTotal );
134  }
135 
136  if ( p->vCuts0 ) Vec_PtrFree( p->vCuts0 );
137  if ( p->vCuts1 ) Vec_PtrFree( p->vCuts1 );
138  if ( p->vCutsNew ) Vec_PtrFree( p->vCutsNew );
139  if ( p->vFanCounts ) Vec_IntFree( p->vFanCounts );
140 
141  if ( p->vNodeCuts ) Vec_IntFree( p->vNodeCuts );
142  if ( p->vNodeStarts ) Vec_IntFree( p->vNodeStarts );
143  if ( p->vCutPairs ) Vec_IntFree( p->vCutPairs );
144 
146  ABC_FREE( p );
147 }
Extra_MmFixed_t * pMmCuts
Definition: cutOracle.c:45
void Extra_MmFixedStop(Extra_MmFixed_t *p)
Vec_Int_t * vNodeCuts
Definition: cutOracle.c:41
Vec_Ptr_t * vCutsNew
Definition: cutOracle.c:37
Vec_Int_t * vNodeStarts
Definition: cutOracle.c:42
Vec_Int_t * vCutPairs
Definition: cutOracle.c:43
Vec_Int_t * vFanCounts
Definition: cutOracle.c:34
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Vec_Ptr_t * vCuts1
Definition: cutOracle.c:39
Vec_Ptr_t * vCuts0
Definition: cutOracle.c:38
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Cut_OracleTryDroppingCuts ( Cut_Oracle_t p,
int  Node 
)

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

Synopsis [Consider dropping cuts if they are useless by now.]

Description []

SideEffects []

SeeAlso []

Definition at line 407 of file cutOracle.c.

408 {
409  int nFanouts;
410  assert( p->vFanCounts );
411  nFanouts = Vec_IntEntry( p->vFanCounts, Node );
412  assert( nFanouts > 0 );
413  if ( --nFanouts == 0 )
414  Cut_OracleFreeCuts( p, Node );
415  Vec_IntWriteEntry( p->vFanCounts, Node, nFanouts );
416 }
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
Vec_Int_t * vFanCounts
Definition: cutOracle.c:34
#define assert(ex)
Definition: util_old.h:213
void Cut_OracleFreeCuts(Cut_Oracle_t *p, int Node)
Definition: cutOracle.c:385