abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dauEnum.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [dauEnum.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [DAG-aware unmapping.]
8 
9  Synopsis [Enumeration of decompositions.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: dauEnum.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "dauInt.h"
22 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis []
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 char * Dau_EnumLift( char * pName, int Shift )
46 {
47  static char pBuffer[64];
48  char * pTemp;
49  for ( pTemp = pBuffer; *pName; pTemp++, pName++ )
50  *pTemp = (*pName >= 'a' && *pName <= 'z') ? *pName + Shift : *pName;
51  *pTemp = 0;
52  return pBuffer;
53 }
54 char * Dau_EnumLift2( char * pName, int Shift )
55 {
56  static char pBuffer[64];
57  char * pTemp;
58  for ( pTemp = pBuffer; *pName; pTemp++, pName++ )
59  *pTemp = (*pName >= 'a' && *pName <= 'z') ? *pName + Shift : *pName;
60  *pTemp = 0;
61  return pBuffer;
62 }
63 
64 /**Function*************************************************************
65 
66  Synopsis []
67 
68  Description []
69 
70  SideEffects []
71 
72  SeeAlso []
73 
74 ***********************************************************************/
75 void Dau_EnumCombineTwo( Vec_Ptr_t * vOne, int fStar, int fXor, char * pName1, char * pName2, int Shift2, int fCompl1, int fCompl2 )
76 {
77  static char pBuffer[256];
78  pName2 = Dau_EnumLift( pName2, Shift2 );
79  sprintf( pBuffer, "%s%c%s%s%s%s%c",
80  fStar?"*":"",
81  fXor?'[':'(',
82  fCompl1?"!":"", pName1[0] == '*' ? pName1 + 1 : pName1,
83  fCompl2?"!":"", pName2[0] == '*' ? pName2 + 1 : pName2,
84  fXor?']':')' );
85 // printf( "%s ", pBuffer );
86  Vec_PtrPush( vOne, Abc_UtilStrsav(pBuffer) );
87 }
88 void Dau_EnumCombineThree( Vec_Ptr_t * vOne, int fStar, char * pNameC, char * pName1, char * pName2, int Shift1, int Shift2, int fComplC, int fCompl1, int fCompl2 )
89 {
90  static char pBuffer[256];
91  pName1 = Dau_EnumLift( pName1, Shift1 );
92  pName2 = Dau_EnumLift2( pName2, Shift2 );
93  sprintf( pBuffer, "%s%c%s%s%s%s%s%s%c",
94  fStar?"*":"",
95  '<',
96  fComplC?"!":"", pNameC[0] == '*' ? pNameC + 1 : pNameC,
97  fCompl1?"!":"", pName1[0] == '*' ? pName1 + 1 : pName1,
98  fCompl2?"!":"", pName2[0] == '*' ? pName2 + 1 : pName2,
99  '>' );
100 // printf( "%s ", pBuffer );
101  Vec_PtrPush( vOne, Abc_UtilStrsav(pBuffer) );
102 }
103 
104 /**Function*************************************************************
105 
106  Synopsis []
107 
108  Description []
109 
110  SideEffects []
111 
112  SeeAlso []
113 
114 ***********************************************************************/
115 void Dau_EnumTestDump( Vec_Ptr_t * vSets, char * pFileName )
116 {
117  FILE * pFile;
118  Vec_Ptr_t * vOne;
119  char * pName;
120  int v, k;
121  pFile = fopen( pFileName, "wb" );
122  if ( pFile == NULL )
123  return;
124  Vec_PtrForEachEntry( Vec_Ptr_t *, vSets, vOne, v )
125  {
126  fprintf( pFile, "VARIABLE NUMBER %d:\n", v );
127  Vec_PtrForEachEntry( char *, vOne, pName, k )
128  fprintf( pFile, "%s\n", pName );
129  }
130  fclose( pFile );
131 }
132 
133 /**Function*************************************************************
134 
135  Synopsis []
136 
137  Description []
138 
139  SideEffects []
140 
141  SeeAlso []
142 
143 ***********************************************************************/
145 {
146  int v, k, nVarMax = 10;
147  Vec_Ptr_t * vSets;
148  Vec_Ptr_t * vOne;
149  char * pName;
150  // 0 vars
151  vSets = Vec_PtrAlloc( 16 );
152  Vec_PtrPush( vSets, Vec_PtrAlloc(0) );
153  // 1 vars
154  vOne = Vec_PtrAlloc( 1 );
155  Vec_PtrPush( vOne, Abc_UtilStrsav("*a") );
156  Vec_PtrPush( vSets, vOne );
157  // 2+ vars
158  for ( v = 2; v <= nVarMax; v++ )
159  {
160  Vec_Ptr_t * vSetI, * vSetJ, * vSetK;
161  char * pNameI, * pNameJ, * pNameK;
162  int i, j, k, i1, j1, k1;
163  vOne = Vec_PtrAlloc( 100 );
164  for ( i = 1; i < v; i++ )
165  for ( j = i; j < v; j++ )
166  {
167  if ( i + j != v )
168  continue;
169  vSetI = (Vec_Ptr_t *)Vec_PtrEntry( vSets, i );
170  vSetJ = (Vec_Ptr_t *)Vec_PtrEntry( vSets, j );
171  Vec_PtrForEachEntry( char *, vSetI, pNameI, i1 )
172  Vec_PtrForEachEntry( char *, vSetJ, pNameJ, j1 )
173  {
174  // AND(a,b)
175  Dau_EnumCombineTwo( vOne, 0, 0, pNameI, pNameJ, i, 0, 0 );
176  // AND(!a,b)
177  if ( pNameI[0] != '*' )
178  Dau_EnumCombineTwo( vOne, 0, 0, pNameI, pNameJ, i, 1, 0 );
179  // AND(a,!b)
180  if ( pNameJ[0] != '*' && !(i == j && i1 == j1) )
181  Dau_EnumCombineTwo( vOne, 0, 0, pNameI, pNameJ, i, 0, 1 );
182  // AND(!a,!b)
183  if ( pNameI[0] != '*' && pNameJ[0] != '*' )
184  Dau_EnumCombineTwo( vOne, 0, 0, pNameI, pNameJ, i, 1, 1 );
185  // XOR(a,b)
186  Dau_EnumCombineTwo( vOne, pNameI[0] == '*' || pNameJ[0] == '*', 1, pNameI, pNameJ, i, 0, 0 );
187  }
188  }
189  for ( k = 1; k < v; k++ )
190  for ( i = 1; i < v; i++ )
191  for ( j = i; j < v; j++ )
192  {
193  if ( k + i + j != v )
194  continue;
195  vSetK = (Vec_Ptr_t *)Vec_PtrEntry( vSets, k );
196  vSetI = (Vec_Ptr_t *)Vec_PtrEntry( vSets, i );
197  vSetJ = (Vec_Ptr_t *)Vec_PtrEntry( vSets, j );
198  Vec_PtrForEachEntry( char *, vSetK, pNameK, k1 )
199  Vec_PtrForEachEntry( char *, vSetI, pNameI, i1 )
200  Vec_PtrForEachEntry( char *, vSetJ, pNameJ, j1 )
201  {
202  int fStar = pNameI[0] == '*' && pNameJ[0] == '*';
203 
204  // MUX(c,a,b)
205  Dau_EnumCombineThree( vOne, fStar, pNameK, pNameI, pNameJ, k, k+i, 0, 0, 0 );
206  // MUX(c,!a,b)
207  if ( pNameI[0] != '*' )
208  Dau_EnumCombineThree( vOne, fStar, pNameK, pNameI, pNameJ, k, k+i, 0, 1, 0 );
209  // MUX(c,a,!b)
210  if ( pNameJ[0] != '*' && !(i == j && i1 == j1) )
211  Dau_EnumCombineThree( vOne, fStar, pNameK, pNameI, pNameJ, k, k+i, 0, 0, 1 );
212 
213  if ( pNameK[0] != '*' && !(i == j && i1 == j1) )
214  {
215  // MUX(!c,a,b)
216  Dau_EnumCombineThree( vOne, fStar, pNameK, pNameI, pNameJ, k, k+i, 1, 0, 0 );
217  // MUX(!c,!a,b)
218  if ( pNameI[0] != '*' )
219  Dau_EnumCombineThree( vOne, fStar, pNameK, pNameI, pNameJ, k, k+i, 1, 1, 0 );
220  // MUX(!c,a,!b)
221  if ( pNameJ[0] != '*' )
222  Dau_EnumCombineThree( vOne, fStar, pNameK, pNameI, pNameJ, k, k+i, 1, 0, 1 );
223  }
224  }
225  }
226  Vec_PtrPush( vSets, vOne );
227  }
228  Dau_EnumTestDump( vSets, "_npn/npn/dsd10.txt" );
229 
230  Vec_PtrForEachEntry( Vec_Ptr_t *, vSets, vOne, v )
231  {
232  printf( "VARIABLE NUMBER %d:\n", v );
233  Vec_PtrForEachEntry( char *, vOne, pName, k )
234  printf( "%s\n", pName );
235  if ( v == 4 )
236  break;
237  }
238  Vec_PtrForEachEntry( Vec_Ptr_t *, vSets, vOne, v )
239  {
240  printf( "%d=%d ", v, Vec_PtrSize(vOne) );
241  Vec_PtrFreeFree( vOne );
242  }
243  Vec_PtrFree( vSets );
244  printf( "\n" );
245 }
246 
247 ////////////////////////////////////////////////////////////////////////
248 /// END OF FILE ///
249 ////////////////////////////////////////////////////////////////////////
250 
251 
253 
void Dau_EnumCombineThree(Vec_Ptr_t *vOne, int fStar, char *pNameC, char *pName1, char *pName2, int Shift1, int Shift2, int fComplC, int fCompl1, int fCompl2)
Definition: dauEnum.c:88
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_PtrFreeFree(Vec_Ptr_t *p)
Definition: vecPtr.h:569
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
void Dau_EnumTestDump(Vec_Ptr_t *vSets, char *pFileName)
Definition: dauEnum.c:115
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
ABC_NAMESPACE_IMPL_START char * Dau_EnumLift(char *pName, int Shift)
DECLARATIONS ///.
Definition: dauEnum.c:45
void Dau_EnumTest()
Definition: dauEnum.c:144
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * sprintf()
void Dau_EnumCombineTwo(Vec_Ptr_t *vOne, int fStar, int fXor, char *pName1, char *pName2, int Shift2, int fCompl1, int fCompl2)
Definition: dauEnum.c:75
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
char * Dau_EnumLift2(char *pName, int Shift)
Definition: dauEnum.c:54
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223