1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/**CFile****************************************************************
FileName [decUtil.c]
PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
Synopsis [Decomposition unitilies.]
Author [MVSIS Group]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - February 1, 2003.]
Revision [$Id: decUtil.c,v 1.1 2003/05/22 19:20:05 alanmi Exp $]
***********************************************************************/
#include "base/abc/abc.h"
#include "dec.h"
#ifdef ABC_USE_CUDD
#include "misc/extra/extraBdd.h"
#endif
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
#ifdef ABC_USE_CUDD
/**Function*************************************************************
Synopsis [Converts graph to BDD.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
DdNode * Dec_GraphDeriveBdd( DdManager * dd, Dec_Graph_t * pGraph )
{
DdNode * bFunc, * bFunc0, * bFunc1;
Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
int i;
// sanity checks
assert( Dec_GraphLeaveNum(pGraph) >= 0 );
assert( Dec_GraphLeaveNum(pGraph) <= pGraph->nSize );
// check for constant function
if ( Dec_GraphIsConst(pGraph) )
return Cudd_NotCond( b1, Dec_GraphIsComplement(pGraph) );
// check for a literal
if ( Dec_GraphIsVar(pGraph) )
return Cudd_NotCond( Cudd_bddIthVar(dd, Dec_GraphVarInt(pGraph)), Dec_GraphIsComplement(pGraph) );
// assign the elementary variables
Dec_GraphForEachLeaf( pGraph, pNode, i )
pNode->pFunc = Cudd_bddIthVar( dd, i );
// compute the function for each internal node
Dec_GraphForEachNode( pGraph, pNode, i )
{
bFunc0 = Cudd_NotCond( Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
bFunc1 = Cudd_NotCond( Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
pNode->pFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( (DdNode *)pNode->pFunc );
}
// deref the intermediate results
bFunc = (DdNode *)pNode->pFunc; Cudd_Ref( bFunc );
Dec_GraphForEachNode( pGraph, pNode, i )
Cudd_RecursiveDeref( dd, (DdNode *)pNode->pFunc );
Cudd_Deref( bFunc );
// complement the result if necessary
return Cudd_NotCond( bFunc, Dec_GraphIsComplement(pGraph) );
}
#endif
/**Function*************************************************************
Synopsis [Derives the truth table.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
unsigned Dec_GraphDeriveTruth( Dec_Graph_t * pGraph )
{
unsigned uTruths[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
unsigned uTruth = 0; // Suppress "might be used uninitialized"
unsigned uTruth0, uTruth1;
Dec_Node_t * pNode;
int i;
// sanity checks
assert( Dec_GraphLeaveNum(pGraph) >= 0 );
assert( Dec_GraphLeaveNum(pGraph) <= pGraph->nSize );
assert( Dec_GraphLeaveNum(pGraph) <= 5 );
// check for constant function
if ( Dec_GraphIsConst(pGraph) )
return Dec_GraphIsComplement(pGraph)? 0 : ~((unsigned)0);
// check for a literal
if ( Dec_GraphIsVar(pGraph) )
return Dec_GraphIsComplement(pGraph)? ~uTruths[Dec_GraphVarInt(pGraph)] : uTruths[Dec_GraphVarInt(pGraph)];
// assign the elementary variables
Dec_GraphForEachLeaf( pGraph, pNode, i )
pNode->pFunc = (void *)(ABC_PTRUINT_T)uTruths[i];
// compute the function for each internal node
Dec_GraphForEachNode( pGraph, pNode, i )
{
uTruth0 = (unsigned)(ABC_PTRUINT_T)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc;
uTruth1 = (unsigned)(ABC_PTRUINT_T)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc;
uTruth0 = pNode->eEdge0.fCompl? ~uTruth0 : uTruth0;
uTruth1 = pNode->eEdge1.fCompl? ~uTruth1 : uTruth1;
uTruth = uTruth0 & uTruth1;
pNode->pFunc = (void *)(ABC_PTRUINT_T)uTruth;
}
// complement the result if necessary
return Dec_GraphIsComplement(pGraph)? ~uTruth : uTruth;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|