ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
dauArray.c
Go to the documentation of this file.
1
20
21#include "dauInt.h"
22
24
28
29typedef struct Dau_Dsd_t_ Dau_Dsd_t;
31{
32 unsigned iVar : 5; // variable
33 unsigned nFans : 5; // fanin count
34 unsigned Depth : 5; // tree depth
35 unsigned Offset : 5; // the diff between this and other node
36 unsigned Data : 5; // user data
37 unsigned Type : 3; // node type
38 unsigned fCompl : 1; // the complemented attribute
39 unsigned fUnused : 1; // this vertice is unused
40};
41
42static inline void Dau_DsdClean( Dau_Dsd_t * p ) { *((int *)p) = 0; }
43
47
49{
50 int Count, Costs[7] = {0, 0, 0, 1, 3, 3, 3};
51 for ( Count = 0; p->Type; p++ )
52 Count += Costs[p->Type];
53 return Count;
54}
55
56/*
57void Dau_DsdMark( Dau_Dsd_t * p, int nSize, int * pMarks )
58{
59 int pStore[DAU_MAX_VAR] = {0};
60 Dau_Dsd_t * q;
61 if ( p->Type == DAU_DSD_CONST || p->Type == DAU_DSD_VAR )
62 return;
63 for ( q = p + nSize - 1; q >= p; q-- )
64 {
65 if ( q->Type == DAU_DSD_VAR )
66 pStore[q->Depth] += pMarks[q->iVar];
67 else
68 {
69 q->Data = pStore[q->Depth+1]; pStore[q->Depth+1] = 0;
70 pStore[q->Depth] += (q->Data == q->nFans);
71 }
72 }
73}
74*/
75
76int Dau_DsdConstruct( char * pDsd, Dau_Dsd_t * pStore )
77{
78 Dau_Dsd_t * pLevel[DAU_MAX_VAR];
79 Dau_Dsd_t * q = pStore;
80 int d = -1, fCompl = 0;
81 if ( Dau_DsdIsConst(pDsd) )
82 {
83 Dau_DsdClean( q );
84 q->Type = DAU_DSD_CONST0;
85 q->fCompl = Dau_DsdIsConst1(pDsd);
86 return 1;
87 }
88 for ( --q; *pDsd; pDsd++ )
89 {
90 if ( *pDsd == '!' )
91 {
92 fCompl ^= 1;
93 continue;
94 }
95 if ( *pDsd == ')' || *pDsd == ']' || *pDsd == '>' || *pDsd == '}' )
96 {
97 assert( fCompl == 0 );
98 if ( --d >= 0 )
99 {
100 pLevel[d]->nFans++;
101 if ( pLevel[d]->Data > pLevel[d+1]->Data )
102 pLevel[d]->Data = pLevel[d+1]->Data;
103 }
104 continue;
105 }
106 Dau_DsdClean( ++q );
107 q->Data = 31;
108 q->fCompl = fCompl;
109 fCompl = 0;
110 if ( *pDsd >= 'a' && *pDsd <= 'z' )
111 {
112 q->Type = DAU_DSD_VAR;
113 q->iVar = *pDsd - 'a';
114 q->Depth = d + 1;
115 if ( d >= 0 )
116 {
117 pLevel[d]->nFans++;
118 if ( pLevel[d]->Data > q->iVar )
119 pLevel[d]->Data = q->iVar;
120 }
121 continue;
122 }
123 if ( *pDsd == '(' )
124 q->Type = DAU_DSD_AND;
125 else if ( *pDsd == '[' )
126 q->Type = DAU_DSD_XOR;
127 else if ( *pDsd == '<' )
128 q->Type = DAU_DSD_MUX;
129 else if ( *pDsd == '{' )
130 q->Type = DAU_DSD_PRIME;
131 else assert( 0 );
132 pLevel[++d] = q;
133 q->Depth = d;
134 }
135 assert( d == -1 );
136 Dau_DsdClean( ++q );
137 return q - pStore;
138}
139
141{
142 char OpenType[7] = {0, 0, 0, '(', '[', '<', '{'};
143 char CloseType[7] = {0, 0, 0, ')', ']', '>', '}'};
144 char pTypes[DAU_MAX_VAR];
145 int d, pVisits[DAU_MAX_VAR];
146 if ( p->Type == DAU_DSD_CONST0 )
147 {
148 printf( "%d\n", p->fCompl );
149 return;
150 }
151 pVisits[0] = 1;
152 for ( d = 0; p->Type; p++ )
153 {
154 if ( p->fCompl )
155 printf( "!" );
156 if ( p->Type == DAU_DSD_VAR )
157 {
158 printf( "%c", 'a' + p->iVar );
159 while ( d > 0 && --pVisits[d] == 0 )
160 printf( "%c", pTypes[d--] );
161 }
162 else
163 {
164 pVisits[++d] = p->nFans;
165 printf( "%c", OpenType[p->Type] );
166 printf( "%c", 'a' + p->Data );
167 printf( "%d", p->Depth );
168 pTypes[d] = CloseType[p->Type];
169 }
170 }
171 assert( d == 0 );
172 printf( "\n" );
173}
174
176{
177 int d, pVisits[DAU_MAX_VAR];
178 if ( p->Type == DAU_DSD_CONST0 )
179 return;
180 pVisits[0] = 1;
181 for ( d = 0; p->Type; p++ )
182 {
183 p->Depth = d;
184 if ( p->Type == DAU_DSD_VAR )
185 while ( d > 0 && --pVisits[d] == 0 )
186 d--;
187 else
188 pVisits[++d] = p->nFans;
189 }
190 assert( d == 0 );
191}
192
194{
195 Dau_Dsd_t * q = p, * pLevel[DAU_MAX_VAR];
196 int d, fChange = 0, pVisits[DAU_MAX_VAR];
197 if ( p->Type == DAU_DSD_CONST0 )
198 return;
199 pVisits[0] = 1;
200 for ( d = 0; p->Type; p++ )
201 {
202 p->Depth = d;
203 if ( p->Type == DAU_DSD_VAR )
204 while ( d > 0 && --pVisits[d] == 0 )
205 d--;
206 else
207 {
208 if ( d > 0 && (pLevel[d-1]->Type == DAU_DSD_XOR && p->Type == DAU_DSD_XOR ||
209 pLevel[d-1]->Type == DAU_DSD_AND && p->Type == DAU_DSD_AND && !p->fCompl) )
210 {
211 pLevel[d-1]->nFans += p->nFans - 1;
212 pVisits[d] += p->nFans - 1;
213 p->fUnused = 1;
214 fChange = 1;
215 }
216 else
217 {
218 pLevel[d++] = p;
219 pVisits[d] = p->nFans;
220 }
221 }
222 }
223 assert( d == 0 );
224 // compact
225 if ( fChange )
226 {
227 for ( p = q; p->Type; p++ )
228 if ( !p->fUnused )
229 *q++ = *p;
230 Dau_DsdClean( q );
231 }
232}
233
235{
236 Dau_Dsd_t pStore[2 * DAU_MAX_VAR];
237// char * pDsd = "[(ab)c(f!(he))]";
238// char * pDsd = "[(abd)cf(f!{she})]";
239 char * pDsd = "[(abd)[cf](f(sg(he)))]";
240// char * pDsd = "[(ab)[cf]]";
241 int i, nSize = Dau_DsdConstruct( pDsd, pStore );
242// Dau_DsdDepth( pStore );
243 Dau_DsdPrint( pStore );
244
245 Dau_DsdRemoveUseless( pStore );
246
247 Dau_DsdPrint( pStore );
248 i = 0;
249}
250
254
255
257
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Dau_DsdPrint(Dau_Dsd_t *p)
Definition dauArray.c:140
void Dau_DsdTest22()
Definition dauArray.c:234
int Dau_DsdCountAnd(Dau_Dsd_t *p)
FUNCTION DEFINITIONS ///.
Definition dauArray.c:48
int Dau_DsdConstruct(char *pDsd, Dau_Dsd_t *pStore)
Definition dauArray.c:76
typedefABC_NAMESPACE_IMPL_START struct Dau_Dsd_t_ Dau_Dsd_t
DECLARATIONS ///.
Definition dauArray.c:29
void Dau_DsdDepth(Dau_Dsd_t *p)
Definition dauArray.c:175
void Dau_DsdRemoveUseless(Dau_Dsd_t *p)
Definition dauArray.c:193
@ DAU_DSD_VAR
Definition dau.h:54
@ DAU_DSD_XOR
Definition dau.h:56
@ DAU_DSD_CONST0
Definition dau.h:53
@ DAU_DSD_PRIME
Definition dau.h:58
@ DAU_DSD_MUX
Definition dau.h:57
@ DAU_DSD_AND
Definition dau.h:55
#define DAU_MAX_VAR
INCLUDES ///.
Definition dau.h:42
Cube * p
Definition exorList.c:222
unsigned Depth
Definition dauArray.c:34
unsigned Data
Definition dauArray.c:36
unsigned fUnused
Definition dauArray.c:39
unsigned Type
Definition dauArray.c:37
unsigned iVar
Definition dauArray.c:32
unsigned nFans
Definition dauArray.c:33
unsigned fCompl
Definition dauArray.c:38
unsigned Offset
Definition dauArray.c:35
#define assert(ex)
Definition util_old.h:213