80 if ( Vec_IntSize(vLits) == 0 )
82 while ( Vec_IntSize(vLits) > 1 )
84 int i, k = 0, Lit1, Lit2, LitRes;
88 Vec_IntWriteEntry( vLits, k++, LitRes );
90 if ( Vec_IntSize(vLits) & 1 )
91 Vec_IntWriteEntry( vLits, k++, Vec_IntEntryLast(vLits) );
92 Vec_IntShrink( vLits, k );
94 assert( Vec_IntSize(vLits) == 1 );
95 return Vec_IntEntry(vLits, 0);
112 int s, i1, i2, i3, i4, i5, nBits;
114 assert( kHot >= 1 && kHot <= 5 );
115 vCodes = Vec_VecStart( nStates );
119 for ( i1 = 0; i1 < nStates; i1++ )
120 Vec_VecPushInt( vCodes, i1, i1 );
127 if ( nBits * (nBits-1) / 2 >= nStates )
131 for ( i1 = 0; i1 < nBits; i1++ )
132 for ( i2 = i1 + 1; i2 < nBits; i2++ )
134 Vec_VecPushInt( vCodes, s, i1 );
135 Vec_VecPushInt( vCodes, s, i2 );
136 if ( ++s == nStates )
143 if ( nBits * (nBits-1) * (nBits-2) / 6 >= nStates )
147 for ( i1 = 0; i1 < nBits; i1++ )
148 for ( i2 = i1 + 1; i2 < nBits; i2++ )
149 for ( i3 = i2 + 1; i3 < nBits; i3++ )
151 Vec_VecPushInt( vCodes, s, i1 );
152 Vec_VecPushInt( vCodes, s, i2 );
153 Vec_VecPushInt( vCodes, s, i3 );
154 if ( ++s == nStates )
161 if ( nBits * (nBits-1) * (nBits-2) * (nBits-3) / 24 >= nStates )
165 for ( i1 = 0; i1 < nBits; i1++ )
166 for ( i2 = i1 + 1; i2 < nBits; i2++ )
167 for ( i3 = i2 + 1; i3 < nBits; i3++ )
168 for ( i4 = i3 + 1; i4 < nBits; i4++ )
170 Vec_VecPushInt( vCodes, s, i1 );
171 Vec_VecPushInt( vCodes, s, i2 );
172 Vec_VecPushInt( vCodes, s, i3 );
173 Vec_VecPushInt( vCodes, s, i4 );
174 if ( ++s == nStates )
181 if ( nBits * (nBits-1) * (nBits-2) * (nBits-3) * (nBits-4) / 120 >= nStates )
185 for ( i1 = 0; i1 < nBits; i1++ )
186 for ( i2 = i1 + 1; i2 < nBits; i2++ )
187 for ( i3 = i2 + 1; i3 < nBits; i3++ )
188 for ( i4 = i3 + 1; i4 < nBits; i4++ )
189 for ( i5 = i4 + 1; i5 < nBits; i5++ )
191 Vec_VecPushInt( vCodes, s, i1 );
192 Vec_VecPushInt( vCodes, s, i2 );
193 Vec_VecPushInt( vCodes, s, i3 );
194 Vec_VecPushInt( vCodes, s, i4 );
195 Vec_VecPushInt( vCodes, s, i5 );
196 if ( ++s == nStates )
219 Vec_Vec_t * vLitsNext, * vLitsOuts, * vCodes;
220 int i, b, k, nBits, LitC, Lit;
221 assert( Vec_IntSize(vLines) % 4 == 0 );
225 assert( Vec_VecSize(vCodes) == nStates );
231 p->pName = Abc_UtilStrsav(
"stg" );
232 for ( i = 0; i < nIns + nBits; i++ )
237 vInMints = Vec_IntAlloc( 1 << nIns );
238 for ( i = 0; i < (1 << nIns); i++ )
240 for ( Lit = 1, b = 0; b < nIns; b++ )
242 Vec_IntPush( vInMints, Lit );
246 vCurs = Vec_IntAlloc( nStates );
252 assert( b >= 0 && b < nBits );
255 Vec_IntPush( vCurs, Lit );
259 vLitsNext = Vec_VecStart( nBits );
260 vLitsOuts = Vec_VecStart( nOuts );
261 for ( i = 0; i < Vec_IntSize(vLines); )
263 int iMint = Vec_IntEntry(vLines, i++);
264 int iCur = Vec_IntEntry(vLines, i++);
265 int iNext = Vec_IntEntry(vLines, i++);
266 int iOut = Vec_IntEntry(vLines, i++);
267 assert( iMint >= 0 && iMint < (1<<nIns) );
268 assert( iCur >= 0 && iCur < nStates );
269 assert( iNext >= 0 && iNext < nStates );
270 assert( iOut >= 0 && iOut < (1<<nOuts) );
272 LitC =
Gia_ManHashAnd(
p, Vec_IntEntry(vInMints, iMint), Vec_IntEntry(vCurs, iCur) );
275 vVec = (
Vec_Int_t *)Vec_VecEntryInt( vCodes, iNext );
277 Vec_VecPushInt( vLitsNext, b, LitC );
279 for ( b = 0; b < nOuts; b++ )
280 if ( (iOut >> b) & 1 )
281 Vec_VecPushInt( vLitsOuts, b, LitC );
283 Vec_IntFree( vInMints );
284 Vec_IntFree( vCurs );
285 Vec_VecFree( vCodes );
290 Vec_VecFree( vLitsOuts );
295 Vec_VecFree( vLitsNext );
323 assert( Vec_IntSize(vLines) % 4 == 0 );
327 p->pName = Abc_UtilStrsav(
"stg" );
328 for ( i = 0; i < nIns + nStates; i++ )
333 vInMints = Vec_IntAlloc( 1 << nIns );
334 for ( i = 0; i < (1 << nIns); i++ )
336 for ( Lit = 1, b = 0; b < nIns; b++ )
338 Vec_IntPush( vInMints, Lit );
342 vCurs = Vec_IntAlloc( nStates );
343 for ( i = 0; i < nStates; i++ )
344 Vec_IntPush( vCurs, Abc_Var2Lit( 1+nIns+i, !i ) );
347 vLitsNext = Vec_VecStart( nStates );
348 vLitsOuts = Vec_VecStart( nOuts );
349 for ( i = 0; i < Vec_IntSize(vLines); )
351 int iMint = Vec_IntEntry(vLines, i++);
352 int iCur = Vec_IntEntry(vLines, i++) - 1;
353 int iNext = Vec_IntEntry(vLines, i++) - 1;
354 int iOut = Vec_IntEntry(vLines, i++);
355 assert( iMint >= 0 && iMint < (1<<nIns) );
356 assert( iCur >= 0 && iCur < nStates );
357 assert( iNext >= 0 && iNext < nStates );
358 assert( iOut >= 0 && iOut < (1<<nOuts) );
360 LitC =
Gia_ManHashAnd(
p, Vec_IntEntry(vInMints, iMint), Vec_IntEntry(vCurs, iCur) );
364 Vec_VecPushInt( vLitsNext, iNext, LitC );
366 for ( b = 0; b < nOuts; b++ )
367 if ( (iOut >> b) & 1 )
371 Vec_VecPushInt( vLitsOuts, b, LitC );
374 Vec_IntFree( vInMints );
375 Vec_IntFree( vCurs );
380 Vec_VecFree( vLitsOuts );
385 Vec_VecFree( vLitsNext );
409 int i, nDigits = Abc_Base10Log( nStates );
410 assert( Vec_IntSize(vLines) % 4 == 0 );
411 for ( i = 0; i < Vec_IntSize(vLines); i += 4 )
413 int iMint = Vec_IntEntry(vLines, i );
414 int iCur = Vec_IntEntry(vLines, i+1) - 1;
415 int iNext = Vec_IntEntry(vLines, i+2) - 1;
416 int iOut = Vec_IntEntry(vLines, i+3);
417 assert( iMint >= 0 && iMint < (1<<nIns) );
418 assert( iCur >= 0 && iCur < nStates );
419 assert( iNext >= 0 && iNext < nStates );
420 assert( iOut >= 0 && iOut < (1<<nOuts) );
422 fprintf( pFile,
" %*d", nDigits, Vec_IntEntry(vLines, i+1) );
423 fprintf( pFile,
" %*d ", nDigits, Vec_IntEntry(vLines, i+2) );
425 fprintf( pFile,
"\n" );
445 int Number, nInputs = -1, nOutputs = -1, nStates = 1;
447 if ( !
strcmp(pFileName +
strlen(pFileName) - 3,
"aig") )
449 printf(
"Input file \"%s\" has extension \"%s\".\n", pFileName,
"aig" );
452 pFile = fopen( pFileName,
"rb" );
455 printf(
"Cannot open file \"%s\".\n", pFileName );
458 vLines = Vec_IntAlloc( 1000 );
459 while ( fgets( pBuffer, 1000, pFile ) != NULL )
461 if ( pBuffer[0] ==
'.' || pBuffer[0] ==
'#' )
464 pToken =
strtok( pBuffer,
" \r\n" );
470 Vec_IntPush( vLines, Number );
472 pToken =
strtok( NULL,
" \r\n" );
473 Vec_IntPush( vLines, atoi(pToken) );
474 nStates = Abc_MaxInt( nStates, Vec_IntEntryLast(vLines)+1 );
476 pToken =
strtok( NULL,
" \r\n" );
477 Vec_IntPush( vLines, atoi(pToken) );
479 pToken =
strtok( NULL,
" \r\n" );
480 if ( nOutputs == -1 )
481 nOutputs =
strlen(pToken);
485 Vec_IntPush( vLines, Number );