ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
extraUtilEnum.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/vec/vec.h"
#include "misc/vec/vecHsh.h"
#include "bool/kit/kit.h"
Include dependency graph for extraUtilEnum.c:

Go to the source code of this file.

Classes

struct  Abc_EnuMan_t_
 

Macros

#define ABC_ENUM_MAX   16
 

Typedefs

typedef struct Abc_EnuMan_t_ Abc_EnuMan_t
 

Functions

ABC_NAMESPACE_IMPL_START void Abc_GetFirst (int *pnVars, int *pnMints, int *pnFuncs, unsigned *pVars, unsigned *pMints, unsigned *pFuncs)
 DECLARATIONS ///.
 
void Abc_GetSecond (int *pnVars, int *pnMints, int *pnFuncs, unsigned *pVars, unsigned *pMints, unsigned *pFuncs)
 
void Abc_GetThird (int *pnVars, int *pnMints, int *pnFuncs, unsigned *pVars, unsigned *pMints, unsigned *pFuncs)
 
void Abc_EnumPrint_rec (Vec_Int_t *vGates, int i, int nVars)
 
void Abc_EnumPrint (Vec_Int_t *vGates, int i, int nVars)
 
void Abc_EnumerateFunctions (int nDecMax)
 
void Abc_EnumerateFuncs_rec (Abc_EnuMan_t *p, int fNew, int iNode1st)
 
void Abc_EnumerateFuncs (int nVars, int nGates, int fVerbose)
 

Macro Definition Documentation

◆ ABC_ENUM_MAX

#define ABC_ENUM_MAX   16

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 429 of file extraUtilEnum.c.

Typedef Documentation

◆ Abc_EnuMan_t

typedef struct Abc_EnuMan_t_ Abc_EnuMan_t

Definition at line 438 of file extraUtilEnum.c.

Function Documentation

◆ Abc_EnumerateFuncs()

void Abc_EnumerateFuncs ( int nVars,
int nGates,
int fVerbose )

Definition at line 644 of file extraUtilEnum.c.

645{
646 abctime clk = Abc_Clock();
647 Abc_EnuMan_t P, * p = &P;
648 int i;
649 if ( nVars > nGates + 1 )
650 {
651 printf( "The gate count %d is not enough to have functions with %d inputs.\n", nGates, nVars );
652 return;
653 }
654 assert( nVars >= 2 && nVars <= 6 );
655 assert( nGates > 0 && nVars + nGates < ABC_ENUM_MAX );
656 memset( p, 0, sizeof(Abc_EnuMan_t) );
657 p->fVerbose = fVerbose;
658 p->fUseXor = 0;
659 p->nVars = nVars;
660 p->nNodeMax = nVars + nGates;
661 p->nNodes = nVars;
662 p->nTops = nVars;
663 for ( i = 0; i < nVars; i++ )
664 p->pTruths[i] = s_Truths6[i];
665 Abc_EnumerateFuncs_rec( p, 1, 0 );
666 assert( p->nNodes == nVars );
667 assert( p->nTops == nVars );
668 // report statistics
669 printf( "Vars = %d. Gates = %d. Tries = %u. Builds = %u. Finished = %d. ",
670 nVars, nGates, (unsigned)p->nTries, (unsigned)p->nBuilds, (unsigned)p->nFinished );
671 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
672}
ABC_INT64_T abctime
Definition abc_global.h:332
Cube * p
Definition exorList.c:222
void Abc_EnumerateFuncs_rec(Abc_EnuMan_t *p, int fNew, int iNode1st)
struct Abc_EnuMan_t_ Abc_EnuMan_t
#define ABC_ENUM_MAX
#define assert(ex)
Definition util_old.h:213
char * memset()
Here is the call graph for this function:

◆ Abc_EnumerateFuncs_rec()

void Abc_EnumerateFuncs_rec ( Abc_EnuMan_t * p,
int fNew,
int iNode1st )

Definition at line 567 of file extraUtilEnum.c.

568{
569 if ( p->nNodes == p->nNodeMax )
570 {
571 assert( p->nTops == 1 );
572 if ( p->fVerbose )
573 Abc_EnumPrintOne( p );
574 p->nFinished++;
575 return;
576 }
577 {
578 int i, k, c, cLim = 4 + p->fUseXor, n = p->nNodes;
579 int nRefedFans = p->nNodeMax - n + 1 - p->nTops;
580 int high0 = fNew ? iNode1st : p->pFans1[n-1];
581 int high1 = fNew ? n : iNode1st;
582 int low0 = fNew ? 0 : p->pFans0[n-1];
583 int c0 = fNew ? 0 : p->Polar[n-1];
584 int Level = p->pLevel[high0];
585 assert( p->nTops > 0 && p->nTops <= p->nNodeMax - n + 1 );
586 // go through nodes
587 for ( k = high0; k < high1; k++ )
588 {
589 if ( nRefedFans == 0 && p->pRefs[k] > 0 )
590 continue;
591 if ( p->pRefs[k] > 0 )
592 nRefedFans--;
593 assert( nRefedFans >= 0 );
594 // try second fanin
595 for ( i = (k == high0) ? low0 : 0; i < k; i++ )
596 {
597 if ( nRefedFans == 0 && p->pRefs[i] > 0 )
598 continue;
599 if ( Level == 0 && p->pRefs[i] == 0 && p->pRefs[k] == 0 && (i+1 != k || (i > 0 && p->pRefs[i-1] == 0)) ) // NPN
600 continue;
601 if ( p->pLevel[k] == 0 && p->pRefs[k] == 0 && p->pRefs[i] != 0 && k > 0 && p->pRefs[k-1] == 0 ) // NPN
602 continue;
603// if ( p->pLevel[i] == 0 && p->pRefs[i] == 0 && p->pRefs[k] != 0 && i > 0 && p->pRefs[i-1] == 0 ) // NPN
604// continue;
605 // try four polarities
606 for ( c = (k == high0 && i == low0 && !fNew) ? c0 + 1 : 0; c < cLim; c++ )
607 {
608 if ( p->pLevel[i] == 0 && p->pRefs[i] == 0 && (c & 1) == 1 ) // NPN
609 continue;
610 if ( p->pLevel[k] == 0 && p->pRefs[k] == 0 && (c & 2) == 2 ) // NPN
611 continue;
612 p->nTries++;
613 // create node
614 assert( i < k );
615 p->pFans0[n] = i;
616 p->pFans1[n] = k;
617 p->fCompl0[n] = c & 1;
618 p->fCompl1[n] = (c >> 1) & 1;
619 p->Polar[n] = c;
620 if ( c == 4 )
621 p->pTruths[n] = p->pTruths[i] ^ p->pTruths[k];
622 else
623 p->pTruths[n] = ((c & 1) ? ~p->pTruths[i] : p->pTruths[i]) & ((c & 2) ? ~p->pTruths[k] : p->pTruths[k]);
624 if ( Abc_EnumerateFilter(p) )
625 continue;
626 p->nBuilds++;
627 assert( Level == Abc_MaxInt(p->pLevel[i], p->pLevel[k]) );
628 p->pLevel[n] = Level + 1;
629 Abc_EnumRefNode( p, n );
630 Abc_EnumerateFuncs_rec( p, 0, fNew ? n : iNode1st );
631 Abc_EnumDerefNode( p, n );
632 assert( n == p->nNodes );
633 }
634 }
635 if ( p->pRefs[k] > 0 )
636 nRefedFans++;
637 }
638 if ( fNew )
639 return;
640 // start a new level
641 Abc_EnumerateFuncs_rec( p, 1, iNode1st );
642 }
643}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_EnumerateFunctions()

void Abc_EnumerateFunctions ( int nDecMax)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 315 of file extraUtilEnum.c.

316{
317 int nVars;
318 int nMints;
319 int nFuncs;
320 unsigned pVars[100] = {0};
321 unsigned pMints[100] = {0};
322 unsigned pFuncs[100] = {0};
323 unsigned Truth;
324 int FuncDone[100] = {0}, nFuncDone = 0;
325 int GateCount[100] = {0};
326 int i, k, n, a, b, v;
327 abctime clk = Abc_Clock();
328 Vec_Int_t * vGates = Vec_IntAlloc( 100000 );
329 Vec_Int_t * vTruths = Vec_IntAlloc( 100000 );
330// Vec_Int_t * vHash = Vec_IntStartFull( 1 << 16 );
331 word * pHash;
332
333 // extract data
334// Abc_GetFirst( &nVars, &nMints, &nFuncs, pVars, pMints, pFuncs );
335 Abc_GetSecond( &nVars, &nMints, &nFuncs, pVars, pMints, pFuncs );
336// Abc_GetThird( &nVars, &nMints, &nFuncs, pVars, pMints, pFuncs );
337
338 // create hash table
339 assert( nMints == 16 || nMints == 32 );
340 pHash = (word *)ABC_CALLOC( char, 1 << (nMints-3) );
341
342 // create elementary gates
343 for ( k = 0; k < nVars; k++ )
344 {
345// Vec_IntWriteEntry( vHash, pVars[k], k );
346 Abc_DataXorBit( pHash, pVars[k] );
347 Vec_IntPush( vTruths, pVars[k] );
348 Vec_IntPush( vGates, -1 );
349 Vec_IntPush( vGates, -1 );
350 }
351
352 // go through different number of variables
353 GateCount[0] = 0;
354 GateCount[1] = nVars;
355 assert( Vec_IntSize(vTruths) == nVars );
356 for ( n = 0; n < nDecMax && nFuncDone < nFuncs; n++ )
357 {
358 for ( a = 0; a <= n; a++ )
359 for ( b = a; b <= n; b++ )
360 if ( a + b == n )
361 {
362 printf( "Trying %d + %d + 1 = %d\n", a, b, n+1 );
363 for ( i = GateCount[a]; i < GateCount[a+1]; i++ )
364 for ( k = GateCount[b]; k < GateCount[b+1]; k++ )
365 if ( i < k )
366 {
367 Truth = Vec_IntEntry(vTruths, i) & Vec_IntEntry(vTruths, k);
368// if ( Vec_IntEntry(vHash, Truth) == -1 )
369 if ( !Abc_DataHasBit(pHash, Truth) )
370 {
371// Vec_IntWriteEntry( vHash, Truth, Vec_IntSize(vTruths) );
372 Abc_DataXorBit( pHash, Truth );
373 Vec_IntPush( vTruths, Truth );
374 Vec_IntPush( vGates, i );
375 Vec_IntPush( vGates, k );
376
377 for ( v = 0; v < nFuncs; v++ )
378 if ( !FuncDone[v] && Truth == pFuncs[v] )
379 {
380 printf( "Found function %d with %d gates: ", v, n+1 );
381 Abc_EnumPrint( vGates, Vec_IntSize(vTruths)-1, nVars );
382 FuncDone[v] = 1;
383 nFuncDone++;
384 }
385 }
386 Truth = Vec_IntEntry(vTruths, i) | Vec_IntEntry(vTruths, k);
387// if ( Vec_IntEntry(vHash, Truth) == -1 )
388 if ( !Abc_DataHasBit(pHash, Truth) )
389 {
390// Vec_IntWriteEntry( vHash, Truth, Vec_IntSize(vTruths) );
391 Abc_DataXorBit( pHash, Truth );
392 Vec_IntPush( vTruths, Truth );
393 Vec_IntPush( vGates, k );
394 Vec_IntPush( vGates, i );
395
396 for ( v = 0; v < nFuncs; v++ )
397 if ( !FuncDone[v] && Truth == pFuncs[v] )
398 {
399 printf( "Found function %d with %d gates: ", v, n+1 );
400 Abc_EnumPrint( vGates, Vec_IntSize(vTruths)-1, nVars );
401 FuncDone[v] = 1;
402 nFuncDone++;
403 }
404 }
405 }
406 }
407 GateCount[n+2] = Vec_IntSize(vTruths);
408 printf( "Finished %d gates. Truths = %10d. ", n+1, Vec_IntSize(vTruths) );
409 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
410 }
411 ABC_FREE( pHash );
412// Vec_IntFree( vHash );
413 Vec_IntFree( vGates );
414 Vec_IntFree( vTruths );
415}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void Abc_EnumPrint(Vec_Int_t *vGates, int i, int nVars)
void Abc_GetSecond(int *pnVars, int *pnMints, int *pnFuncs, unsigned *pVars, unsigned *pMints, unsigned *pFuncs)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
Here is the call graph for this function:

◆ Abc_EnumPrint()

void Abc_EnumPrint ( Vec_Int_t * vGates,
int i,
int nVars )

Definition at line 283 of file extraUtilEnum.c.

284{
285 assert( 2*i < Vec_IntSize(vGates) );
286 Abc_EnumPrint_rec( vGates, i, nVars );
287 printf( "\n" );
288}
void Abc_EnumPrint_rec(Vec_Int_t *vGates, int i, int nVars)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_EnumPrint_rec()

void Abc_EnumPrint_rec ( Vec_Int_t * vGates,
int i,
int nVars )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 258 of file extraUtilEnum.c.

259{
260 int Fan0 = Vec_IntEntry(vGates, 2*i);
261 int Fan1 = Vec_IntEntry(vGates, 2*i+1);
262 char * pOper = (char*)(Fan0 < Fan1 ? "" : "+");
263 if ( Fan0 > Fan1 )
264 ABC_SWAP( int, Fan0, Fan1 );
265 if ( Fan0 < nVars )
266 printf( "%c", 'a'+Fan0 );
267 else
268 {
269 printf( "(" );
270 Abc_EnumPrint_rec( vGates, Fan0, nVars );
271 printf( ")" );
272 }
273 printf( "%s", pOper );
274 if ( Fan1 < nVars )
275 printf( "%c", 'a'+Fan1 );
276 else
277 {
278 printf( "(" );
279 Abc_EnumPrint_rec( vGates, Fan1, nVars );
280 printf( ")" );
281 }
282}
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_GetFirst()

ABC_NAMESPACE_IMPL_START void Abc_GetFirst ( int * pnVars,
int * pnMints,
int * pnFuncs,
unsigned * pVars,
unsigned * pMints,
unsigned * pFuncs )

DECLARATIONS ///.

CFile****************************************************************

FileName [extraUtilEnum.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Function enumeration.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
extraUtilEnum.c,v 1.0 2003/02/01 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 50 of file extraUtilEnum.c.

51{
52 int nVars = 8;
53 int nMints = 16;
54 int nFuncs = 8;
55 char * pMintStrs[16] = {
56 "1-1-1-1-",
57 "1-1--11-",
58 "1-1-1--1",
59 "1-1--1-1",
60
61 "-11-1-1-",
62 "-11--11-",
63 "-11-1--1",
64 "-11--1-1",
65
66 "1--11-1-",
67 "1--1-11-",
68 "1--11--1",
69 "1--1-1-1",
70
71 "-1-11-1-",
72 "-1-1-11-",
73 "-1-11--1",
74 "-1-1-1-1"
75 };
76 char * pFuncStrs[8] = {
77 "1111101011111010",
78 "0000010100000101",
79 "1111110010101001",
80 "0000001101010110",
81 "1111111111001101",
82 "0000000000110010",
83 "1111111111111110",
84 "0000000000000001",
85 };
86 int i, k;
87 *pnVars = nVars;
88 *pnMints = nMints;
89 *pnFuncs = nFuncs;
90 // extract mints
91 for ( i = 0; i < nMints; i++ )
92 for ( k = 0; k < nVars; k++ )
93 if ( pMintStrs[i][k] == '1' )
94 pMints[i] |= (1 << k), pVars[k] |= (1 << i);
95 // extract funcs
96 for ( i = 0; i < nFuncs; i++ )
97 for ( k = 0; k < nMints; k++ )
98 if ( pFuncStrs[i][k] == '1' )
99 pFuncs[i] |= (1 << k);
100}

◆ Abc_GetSecond()

void Abc_GetSecond ( int * pnVars,
int * pnMints,
int * pnFuncs,
unsigned * pVars,
unsigned * pMints,
unsigned * pFuncs )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 113 of file extraUtilEnum.c.

114{
115 int nVars = 10;
116 int nMints = 32;
117 int nFuncs = 7;
118 char * pMintStrs[32] = {
119 "1-1---1---",
120 "1-1----1--",
121 "1-1-----1-",
122 "1-1------1",
123
124 "1--1--1---",
125 "1--1---1--",
126 "1--1----1-",
127 "1--1-----1",
128
129 "1---1-1---",
130 "1---1--1--",
131 "1---1---1-",
132 "1---1----1",
133
134 "1----11---",
135 "1----1-1--",
136 "1----1--1-",
137 "1----1---1",
138
139
140 "-11---1---",
141 "-11----1--",
142 "-11-----1-",
143 "-11------1",
144
145 "-1-1--1---",
146 "-1-1---1--",
147 "-1-1----1-",
148 "-1-1-----1",
149
150 "-1--1-1---",
151 "-1--1--1--",
152 "-1--1---1-",
153 "-1--1----1",
154
155 "-1---11---",
156 "-1---1-1--",
157 "-1---1--1-",
158 "-1---1---1"
159 };
160 char * pFuncStrs[7] = {
161 "11111110110010001110110010000000",
162 "00000001001101110001001101111111",
163 "10000001001001000001001001001000",
164 "01001000000100101000000100100100",
165 "00100100100000010100100000010010",
166 "00010010010010000010010010000001",
167 "11111111111111111111000000000000"
168 };
169 int i, k;
170 *pnVars = nVars;
171 *pnMints = nMints;
172 *pnFuncs = nFuncs;
173 // extract mints
174 for ( i = 0; i < nMints; i++ )
175 for ( k = 0; k < nVars; k++ )
176 if ( pMintStrs[i][k] == '1' )
177 pMints[i] |= (1 << k), pVars[k] |= (1 << i);
178 // extract funcs
179 for ( i = 0; i < nFuncs; i++ )
180 for ( k = 0; k < nMints; k++ )
181 if ( pFuncStrs[i][k] == '1' )
182 pFuncs[i] |= (1 << k);
183}
Here is the caller graph for this function:

◆ Abc_GetThird()

void Abc_GetThird ( int * pnVars,
int * pnMints,
int * pnFuncs,
unsigned * pVars,
unsigned * pMints,
unsigned * pFuncs )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 196 of file extraUtilEnum.c.

197{
198 int nVars = 8;
199 int nMints = 16;
200 int nFuncs = 7;
201 char * pMintStrs[16] = {
202 "1---1---",
203 "1----1--",
204 "1-----1-",
205 "1------1",
206
207 "-1--1---",
208 "-1---1--",
209 "-1----1-",
210 "-1-----1",
211
212 "--1-1---",
213 "--1--1--",
214 "--1---1-",
215 "--1----1",
216
217 "---11---",
218 "---1-1--",
219 "---1--1-",
220 "---1---1"
221 };
222 char * pFuncStrs[7] = {
223 "1111111011001000",
224 "0000000100110111",
225 "1000000100100100",
226 "0100100000010010",
227 "0010010010000001",
228 "0001001001001000",
229 "1111111111111111"
230 };
231 int i, k;
232 *pnVars = nVars;
233 *pnMints = nMints;
234 *pnFuncs = nFuncs;
235 // extract mints
236 for ( i = 0; i < nMints; i++ )
237 for ( k = 0; k < nVars; k++ )
238 if ( pMintStrs[i][k] == '1' )
239 pMints[i] |= (1 << k), pVars[k] |= (1 << i);
240 // extract funcs
241 for ( i = 0; i < nFuncs; i++ )
242 for ( k = 0; k < nMints; k++ )
243 if ( pFuncStrs[i][k] == '1' )
244 pFuncs[i] |= (1 << k);
245}