abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fpgaTruth.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fpgaTruth.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Technology mapping for variable-size-LUT FPGAs.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - August 18, 2004.]
14 
15  Revision [$Id: fpgaTruth.c,v 1.4 2005/01/23 06:59:42 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fpgaInt.h"
20 #include "bdd/cudd/cudd.h"
21 
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// FUNCTION DEFINITIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 /**Function*************************************************************
34 
35  Synopsis [Recursively derives the truth table for the cut.]
36 
37  Description []
38 
39  SideEffects []
40 
41  SeeAlso []
42 
43 ***********************************************************************/
45 {
46  DdNode * bFunc, * bFunc0, * bFunc1;
47  assert( !Fpga_IsComplement(pCut) );
48  // if the cut is visited, return the result
49  if ( pCut->uSign )
50  return (DdNode *)(ABC_PTRUINT_T)pCut->uSign;
51  // compute the functions of the children
52  bFunc0 = Fpga_TruthsCutBdd_rec( dd, Fpga_CutRegular(pCut->pOne), vVisited ); Cudd_Ref( bFunc0 );
53  bFunc0 = Cudd_NotCond( bFunc0, Fpga_CutIsComplement(pCut->pOne) );
54  bFunc1 = Fpga_TruthsCutBdd_rec( dd, Fpga_CutRegular(pCut->pTwo), vVisited ); Cudd_Ref( bFunc1 );
55  bFunc1 = Cudd_NotCond( bFunc1, Fpga_CutIsComplement(pCut->pTwo) );
56  // get the function of the cut
57  bFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( bFunc );
58  bFunc = Cudd_NotCond( bFunc, pCut->Phase );
59  Cudd_RecursiveDeref( dd, bFunc0 );
60  Cudd_RecursiveDeref( dd, bFunc1 );
61  assert( pCut->uSign == 0 );
62  pCut->uSign = (unsigned)(ABC_PTRUINT_T)bFunc;
63  // add this cut to the visited list
64  Fpga_NodeVecPush( vVisited, (Fpga_Node_t *)pCut );
65  return bFunc;
66 }
67 
68 /**Function*************************************************************
69 
70  Synopsis [Derives the truth table for one cut.]
71 
72  Description []
73 
74  SideEffects []
75 
76  SeeAlso []
77 
78 ***********************************************************************/
79 void * Fpga_TruthsCutBdd( void * dd, Fpga_Cut_t * pCut )
80 {
81  Fpga_NodeVec_t * vVisited;
82  DdNode * bFunc;
83  int i;
84  assert( pCut->nLeaves > 1 );
85  // set the leaf variables
86  for ( i = 0; i < pCut->nLeaves; i++ )
87  pCut->ppLeaves[i]->pCuts->uSign = (unsigned)(ABC_PTRUINT_T)Cudd_bddIthVar( (DdManager *)dd, i );
88  // recursively compute the function
89  vVisited = Fpga_NodeVecAlloc( 10 );
90  bFunc = Fpga_TruthsCutBdd_rec( (DdManager *)dd, pCut, vVisited ); Cudd_Ref( bFunc );
91  // clean the intermediate BDDs
92  for ( i = 0; i < pCut->nLeaves; i++ )
93  pCut->ppLeaves[i]->pCuts->uSign = 0;
94  for ( i = 0; i < vVisited->nSize; i++ )
95  {
96  pCut = (Fpga_Cut_t *)vVisited->pArray[i];
97  Cudd_RecursiveDeref( (DdManager *)dd, (DdNode*)(ABC_PTRUINT_T)pCut->uSign );
98  pCut->uSign = 0;
99  }
100 // printf( "%d ", vVisited->nSize );
101  Fpga_NodeVecFree( vVisited );
102  Cudd_Deref( bFunc );
103  return bFunc;
104 }
105 
106 
107 /**Function*************************************************************
108 
109  Synopsis [Recursively derives the truth table for the cut.]
110 
111  Description []
112 
113  SideEffects []
114 
115  SeeAlso []
116 
117 ***********************************************************************/
118 void Fpga_CutVolume_rec( Fpga_Cut_t * pCut, Fpga_NodeVec_t * vVisited )
119 {
120  assert( !Fpga_IsComplement(pCut) );
121  if ( pCut->fMark )
122  return;
123  pCut->fMark = 1;
124  Fpga_CutVolume_rec( Fpga_CutRegular(pCut->pOne), vVisited );
125  Fpga_CutVolume_rec( Fpga_CutRegular(pCut->pTwo), vVisited );
126  Fpga_NodeVecPush( vVisited, (Fpga_Node_t *)pCut );
127 }
128 
129 /**Function*************************************************************
130 
131  Synopsis [Derives the truth table for one cut.]
132 
133  Description []
134 
135  SideEffects []
136 
137  SeeAlso []
138 
139 ***********************************************************************/
141 {
142  Fpga_NodeVec_t * vVisited;
143  int Volume, i;
144  assert( pCut->nLeaves > 1 );
145  // set the leaf variables
146  for ( i = 0; i < pCut->nLeaves; i++ )
147  pCut->ppLeaves[i]->pCuts->fMark = 1;
148  // recursively compute the function
149  vVisited = Fpga_NodeVecAlloc( 10 );
150  Fpga_CutVolume_rec( pCut, vVisited );
151  // clean the marks
152  for ( i = 0; i < pCut->nLeaves; i++ )
153  pCut->ppLeaves[i]->pCuts->fMark = 0;
154  for ( i = 0; i < vVisited->nSize; i++ )
155  {
156  pCut = (Fpga_Cut_t *)vVisited->pArray[i];
157  pCut->fMark = 0;
158  }
159  Volume = vVisited->nSize;
160  printf( "%d ", Volume );
161  Fpga_NodeVecFree( vVisited );
162  return Volume;
163 }
164 
165 ////////////////////////////////////////////////////////////////////////
166 /// END OF FILE ///
167 ////////////////////////////////////////////////////////////////////////
168 
169 
171 
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
void * Fpga_TruthsCutBdd(void *dd, Fpga_Cut_t *pCut)
Definition: fpgaTruth.c:79
#define Fpga_CutRegular(p)
Definition: fpgaInt.h:74
int Fpga_CutVolume(Fpga_Cut_t *pCut)
Definition: fpgaTruth.c:140
Fpga_Cut_t * pTwo
Definition: fpgaInt.h:235
for(p=first;p->value< newval;p=p->next)
Fpga_Cut_t * pCuts
Definition: fpgaInt.h:224
#define Fpga_CutIsComplement(p)
Definition: fpgaInt.h:73
void Fpga_CutVolume_rec(Fpga_Cut_t *pCut, Fpga_NodeVec_t *vVisited)
Definition: fpgaTruth.c:118
Fpga_Node_t * ppLeaves[FPGA_MAX_LEAVES+1]
Definition: fpgaInt.h:237
Fpga_Cut_t * pOne
Definition: fpgaInt.h:234
Fpga_NodeVec_t * Fpga_NodeVecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: fpgaVec.c:45
void Fpga_NodeVecFree(Fpga_NodeVec_t *p)
Definition: fpgaVec.c:68
unsigned uSign
Definition: fpgaInt.h:239
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_NAMESPACE_IMPL_START DdNode * Fpga_TruthsCutBdd_rec(DdManager *dd, Fpga_Cut_t *pCut, Fpga_NodeVec_t *vVisited)
DECLARATIONS ///.
Definition: fpgaTruth.c:44
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
#define assert(ex)
Definition: util_old.h:213
Fpga_Node_t ** pArray
Definition: fpgaInt.h:252
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
#define Fpga_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fpga.h:57
void Fpga_NodeVecPush(Fpga_NodeVec_t *p, Fpga_Node_t *Entry)
Definition: fpgaVec.c:169