ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
bacOper.c
Go to the documentation of this file.
1
20
21#include "bac.h"
22
24
28
32
44int Bac_BoxCreate( Bac_Ntk_t * p, Bac_ObjType_t Type, Vec_Int_t * vFanins, int nInA, int nInB, int nOuts )
45{
46 char pName[100]; int i, iObj, iFanin;
47 assert( BAC_OBJ_BOX < Type && Type < BAC_BOX_UNKNOWN );
48 if ( BAC_BOX_CF <= Type && Type <= BAC_BOX_CZ )
49 {
50 sprintf( pName, "ABCCTo%d", nOuts );
51 assert( 0 == Vec_IntSize(vFanins) );
52 iObj = Bac_BoxAlloc( p, Type, 0, nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
53 }
54 else if ( BAC_BOX_BUF <= Type && Type <= BAC_BOX_INV )
55 {
56 char * pPref[2] = { "ABCBUF", "ABCINV" };
57 assert( nInA == nOuts );
58 assert( nInA == Vec_IntSize(vFanins) );
59 sprintf( pName, "%sa%do%d", pPref[Type - BAC_BOX_BUF], nInA, nOuts );
60 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
61 }
62 else if ( BAC_BOX_AND <= Type && Type <= BAC_BOX_XNOR )
63 {
64 char * pPref[6] = { "ABCAND", "ABCNAND", "ABCOR", "ABCNOR", "ABCXOR", "ABCXNOR" };
65 assert( nInA == nOuts && nInB == nOuts );
66 assert( nInA + nInB == Vec_IntSize(vFanins) );
67 sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_AND], nInA, nInB, nOuts );
68 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
69 }
70 else if ( Type == BAC_BOX_MUX )
71 {
72 char * pPref[1] = { "ABCMUX" };
73 assert( nInA == nOuts && nInB == nOuts );
74 assert( 1 + nInA + nInB == Vec_IntSize(vFanins) );
75 sprintf( pName, "%sc%da%db%do%d", pPref[Type - BAC_BOX_MUX], 1, nInA, nInB, nOuts );
76 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
77 }
78 else if ( Type == BAC_BOX_MAJ )
79 {
80 char * pPref[1] = { "ABCMAJ" };
81 assert( nInA == 1 && nInB == 1 && nOuts == 1 );
82 assert( 3 == Vec_IntSize(vFanins) );
83 sprintf( pName, "%sa%db%dc%do%d", pPref[Type - BAC_BOX_MAJ], 1, 1, 1, 1 );
84 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
85 }
86 else if ( BAC_BOX_RAND <= Type && Type <= BAC_BOX_RXNOR )
87 {
88 char * pPref[6] = { "ABCRAND", "ABCRNAND", "ABCROR", "ABCRNOR", "ABCRXOR", "ABCRXNOR" };
89 assert( nInA == nInB && 1 == nOuts );
90 assert( nInA + nInB == Vec_IntSize(vFanins) );
91 sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_RAND], nInA, nInB, nOuts );
92 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
93 }
94 else if ( Type == BAC_BOX_SEL )
95 {
96 char * pPref[1] = { "ABCSEL" };
97 assert( nInA * nOuts == nInB );
98 assert( nInA + nInB == Vec_IntSize(vFanins) );
99 sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_SEL], nInA, nInB, nOuts );
100 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
101 }
102 else if ( Type == BAC_BOX_PSEL )
103 {
104 char * pPref[1] = { "ABCPSEL" };
105 assert( nInA * nOuts == nInB );
106 assert( 1 + nInA + nInB == Vec_IntSize(vFanins) );
107 sprintf( pName, "%si%da%db%do%d", pPref[Type - BAC_BOX_SEL], 1, nInA, nInB, nOuts );
108 iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
109 }
110 // add fanins
111 Vec_IntForEachEntry( vFanins, iFanin, i )
112 Bac_ObjSetFanin( p, Bac_BoxBi(p, iObj, i), iFanin );
113 return iObj;
114}
115
127int Bac_ObjClpWide( Bac_Ntk_t * p, int iBox )
128{
129 Bac_ObjType_t Type = Bac_ObjType( p, iBox );
130 int nBis = Bac_BoxBiNum(p, iBox);
131 int nBos = Bac_BoxBoNum(p, iBox);
132 int i, k, iObj;
133 assert( nBos > 1 );
134 Vec_IntClear( &p->vArray );
135 if ( BAC_BOX_BUF <= Type && Type <= BAC_BOX_INV )
136 {
137 for ( i = 0; i < nBos; i++ )
138 {
139 Vec_IntFill( &p->vArray2, 1, Bac_BoxFanin(p, iBox, i) );
140 iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, -1, 1 );
141 Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
142 }
143 }
144 else if ( BAC_BOX_AND <= Type && Type <= BAC_BOX_XNOR )
145 {
146 assert( nBis == 2 * nBos );
147 for ( i = 0; i < nBos; i++ )
148 {
149 Vec_IntFillTwo( &p->vArray2, 2, Bac_BoxFanin(p, iBox, i), Bac_BoxFanin(p, iBox, nBos+i) );
150 iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, 1, 1 );
151 Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
152 }
153 }
154 else if ( Type == BAC_BOX_MUX )
155 {
156 assert( nBis - 1 == 2 * nBos );
157 for ( i = 0; i < nBos; i++ )
158 {
159 Vec_IntFill( &p->vArray2, 1, Bac_BoxFanin(p, iBox, 0) );
160 Vec_IntPushTwo( &p->vArray2, Bac_BoxFanin(p, iBox, 1+i), Bac_BoxFanin(p, iBox, 1+nBos+i) );
161 iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, 1, 1 );
162 Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
163 }
164 }
165 else if ( Type == BAC_BOX_NMUX )
166 {
167 int n, nIns = nBis / nBos;
168 assert( nBis % nBos == 0 );
169 for ( n = 1; n < 32; n++ )
170 if ( n + (1 << n) == nIns )
171 break;
172 assert( n > 1 && n < 32 );
173 for ( i = 0; i < nBos; i++ )
174 {
175 Vec_IntClear( &p->vArray2 );
176 for ( k = 0; k < n; k++ )
177 Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, k) );
178 for ( k = 0; k < (1 << n); k++ )
179 Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, n + (1 << n) * i + k) );
180 iObj = Bac_BoxCreate( p, Type, &p->vArray2, n, (1 << n), 1 );
181 Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
182 }
183 }
184 else if ( Type == BAC_BOX_SEL )
185 {
186 }
187 else if ( Type == BAC_BOX_PSEL )
188 {
189 }
190 else if ( Type == BAC_BOX_DFF || Type == BAC_BOX_LATCH )
191 {
192 }
193 else if ( Type == BAC_BOX_DFFRS || Type == BAC_BOX_LATCHRS )
194 {
195 }
196 else assert( 0 );
197 Bac_BoxReplace( p, iBox, Vec_IntArray(&p->vArray), Vec_IntSize(&p->vArray) );
198 return iBox;
199}
200
212int Bac_ObjClpArith( Bac_Ntk_t * p, int iBox )
213{
214 Bac_ObjType_t Type = Bac_ObjType( p, iBox );
215 int i, iObj = -1;
216 int nBis = 0;//Bac_NtkReadRangesPrim( Bac_BoxNtkName(p, iObj), &p->vArray, 0 );
217 assert( nBis == Bac_BoxBiNum(p, iBox) );
218 if ( Type == BAC_BOX_ADD )
219 {
220 int Carry = Bac_BoxFanin(p, iBox, 0);
221 int nBits = Vec_IntEntry(&p->vArray, 1);
222 assert( Vec_IntSize(&p->vArray) == 3 );
223 assert( Vec_IntEntry(&p->vArray, 0) == 1 );
224 assert( Vec_IntEntry(&p->vArray, 2) == nBits );
225 Vec_IntClear( &p->vArray );
226 for ( i = 0; i < nBits; i++ )
227 {
228 Vec_IntFill( &p->vArray2, 1, Carry );
229 Vec_IntPushTwo( &p->vArray2, Bac_BoxFanin(p, iBox, 1+i), Bac_BoxFanin(p, iBox, 1+nBits+i) );
230 iObj = Bac_BoxCreate( p, BAC_BOX_ADD, &p->vArray2, 1, 1, 1 );
231 Carry = Bac_BoxBo(p, iObj, 1);
232 Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
233 }
234 Vec_IntPush( &p->vArray, Carry );
235 }
236 else if ( Type == BAC_BOX_SUB )
237 {
238 int iConst, nBits = Vec_IntEntry(&p->vArray, 0);
239 assert( Vec_IntSize(&p->vArray) == 2 );
240 assert( Vec_IntEntry(&p->vArray, 1) == nBits );
241 // create inverter
242 Vec_IntClear( &p->vArray2 );
243 for ( i = 0; i < nBits; i++ )
244 Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, nBits+i) );
245 iObj = Bac_BoxCreate( p, BAC_BOX_INV, &p->vArray2, nBits, -1, nBits );
246 // create constant
247 Vec_IntClear( &p->vArray2 );
248 iConst = Bac_BoxCreate( p, BAC_BOX_CT, &p->vArray2, -1, -1, 1 );
249 // collect fanins
250 Vec_IntFill( &p->vArray2, 1, iConst+1 );
251 for ( i = 0; i < nBits; i++ )
252 Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, i) );
253 for ( i = 0; i < nBits; i++ )
254 Vec_IntPush( &p->vArray2, Bac_BoxBo(p, iObj, i) );
255 // create adder
256 iObj = Bac_BoxCreate( p, BAC_BOX_ADD, &p->vArray2, nBits, nBits, nBits );
257 // collect fanins
258 Vec_IntClear( &p->vArray );
259 for ( i = 0; i < nBits; i++ )
260 Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, i) );
261 }
262 else if ( Type == BAC_BOX_MUL )
263 {
264 }
265 else if ( Type == BAC_BOX_DIV )
266 {
267 }
268 else if ( Type == BAC_BOX_MOD )
269 {
270 }
271 else if ( Type == BAC_BOX_REM )
272 {
273 }
274 else if ( Type == BAC_BOX_POW )
275 {
276 }
277 else if ( Type == BAC_BOX_MIN )
278 {
279 }
280 else if ( Type == BAC_BOX_ABS )
281 {
282 }
283
284 else if ( Type == BAC_BOX_LTHAN )
285 {
286 }
287 else if ( Type == BAC_BOX_LETHAN )
288 {
289 }
290 else if ( Type == BAC_BOX_METHAN )
291 {
292 }
293 else if ( Type == BAC_BOX_MTHAN )
294 {
295 }
296 else if ( Type == BAC_BOX_EQU )
297 {
298 }
299 else if ( Type == BAC_BOX_NEQU )
300 {
301 }
302
303 else if ( Type == BAC_BOX_SHIL )
304 {
305 }
306 else if ( Type == BAC_BOX_SHIR )
307 {
308 }
309 else if ( Type == BAC_BOX_ROTL )
310 {
311 }
312 else if ( Type == BAC_BOX_ROTR )
313 {
314 }
315 Bac_BoxReplace( p, iBox, Vec_IntArray(&p->vArray), Vec_IntSize(&p->vArray) );
316 return 1;
317}
318
330int Bac_ObjClpMemory( Bac_Ntk_t * p, int iBox )
331{
332 int i, En, iNext, nItems = Bac_BoxBiNum(p, iBox);
333 assert( Bac_ObjType(p, iBox) == BAC_BOX_RAMBOX );
334 assert( Bac_BoxBiNum(p, iBox) == Bac_BoxBoNum(p, iBox) );
335 // for each fanin of RAMBOX, make sure address width is the same
336 Bac_BoxForEachFaninBox( p, iBox, iNext, i )
337 assert( Bac_ObjType(p, iNext) == BAC_BOX_RAMWC );
338
339 // create decoders, selectors and flops
340 for ( i = 0; i < nItems; i++ )
341 {
342 int BoxW = Bac_ObjFanin(p, Bac_BoxBi(p, iBox, i));
343 int BoxR = Bac_ObjFanout(p, Bac_BoxBo(p, iBox, 0));
344 assert( Bac_ObjType(p, BoxW) == BAC_BOX_RAMWC );
345 assert( Bac_ObjType(p, BoxR) == BAC_BOX_RAMR );
346 // create enable
347 Vec_IntFillTwo( &p->vArray2, 2, Bac_BoxFanin(p, BoxW, 1), Bac_BoxFanin(p, BoxR, 0) );
348 En = Bac_BoxCreate( p, BAC_BOX_AND, &p->vArray2, 1, 1, 1 );
349 En = Bac_BoxBo( p, En, 0 );
350 // collect address
351 }
352 // for each fanout of RAMBOX, makes ure address width is the same
353// Bac_BoxForEachFanoutBox( p, iBox, iNext, i )
354// assert( Bac_ObjType(p, iNext) == BAC_BOX_RAMR );
355 // create selectors and connect them
356 return 1;
357}
358
362
363
365
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int Bac_ObjClpArith(Bac_Ntk_t *p, int iBox)
Definition bacOper.c:212
int Bac_ObjClpWide(Bac_Ntk_t *p, int iBox)
Definition bacOper.c:127
ABC_NAMESPACE_IMPL_START int Bac_BoxCreate(Bac_Ntk_t *p, Bac_ObjType_t Type, Vec_Int_t *vFanins, int nInA, int nInB, int nOuts)
DECLARATIONS ///.
Definition bacOper.c:44
int Bac_ObjClpMemory(Bac_Ntk_t *p, int iBox)
Definition bacOper.c:330
struct Bac_Ntk_t_ Bac_Ntk_t
Definition bac.h:141
#define Bac_BoxForEachFaninBox(p, iBox, iFanin, i)
Definition bac.h:389
Bac_ObjType_t
INCLUDES ///.
Definition bac.h:43
@ BAC_BOX_SHIR
Definition bac.h:108
@ BAC_BOX_DFFRS
Definition bac.h:126
@ BAC_BOX_UNKNOWN
Definition bac.h:128
@ BAC_BOX_RAMWC
Definition bac.h:120
@ BAC_BOX_MIN
Definition bac.h:97
@ BAC_BOX_ROTL
Definition bac.h:109
@ BAC_BOX_MUL
Definition bac.h:92
@ BAC_BOX_LATCH
Definition bac.h:123
@ BAC_BOX_XNOR
Definition bac.h:62
@ BAC_BOX_AND
Definition bac.h:57
@ BAC_BOX_RAND
Definition bac.h:68
@ BAC_BOX_INV
Definition bac.h:56
@ BAC_BOX_PSEL
Definition bac.h:84
@ BAC_BOX_SHIL
Definition bac.h:107
@ BAC_BOX_LATCHRS
Definition bac.h:124
@ BAC_BOX_SEL
Definition bac.h:83
@ BAC_BOX_ADD
Definition bac.h:90
@ BAC_BOX_MAJ
Definition bac.h:66
@ BAC_BOX_NMUX
Definition bac.h:82
@ BAC_BOX_CT
Definition bac.h:52
@ BAC_BOX_DIV
Definition bac.h:93
@ BAC_BOX_RXNOR
Definition bac.h:73
@ BAC_BOX_ROTR
Definition bac.h:110
@ BAC_BOX_BUF
Definition bac.h:55
@ BAC_BOX_MTHAN
Definition bac.h:103
@ BAC_BOX_REM
Definition bac.h:95
@ BAC_BOX_CF
Definition bac.h:51
@ BAC_BOX_RAMR
Definition bac.h:118
@ BAC_BOX_MUX
Definition bac.h:65
@ BAC_BOX_DFF
Definition bac.h:125
@ BAC_BOX_RAMBOX
Definition bac.h:121
@ BAC_BOX_LETHAN
Definition bac.h:101
@ BAC_BOX_LTHAN
Definition bac.h:100
@ BAC_BOX_CZ
Definition bac.h:54
@ BAC_BOX_POW
Definition bac.h:96
@ BAC_BOX_NEQU
Definition bac.h:105
@ BAC_BOX_METHAN
Definition bac.h:102
@ BAC_BOX_EQU
Definition bac.h:104
@ BAC_BOX_ABS
Definition bac.h:98
@ BAC_BOX_SUB
Definition bac.h:91
@ BAC_BOX_MOD
Definition bac.h:94
@ BAC_OBJ_BOX
Definition bac.h:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
Definition utilNam.c:453
#define assert(ex)
Definition util_old.h:213
char * sprintf()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54