abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ifDec08.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ifDec08.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [FPGA mapping based on priority cuts.]
8 
9  Synopsis [Performs additional check.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 21, 2006.]
16 
17  Revision [$Id: ifDec08.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "if.h"
22 #include "misc/extra/extra.h"
23 #include "bool/kit/kit.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 // the bit count for the first 256 integer numbers
33 static int BitCount8[256] = {
34  0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
35  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
36  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
37  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
38  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
39  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
40  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
41  3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
42 };
43 // variable swapping code
44 static word PMasks[5][3] = {
45  { ABC_CONST(0x9999999999999999), ABC_CONST(0x2222222222222222), ABC_CONST(0x4444444444444444) },
46  { ABC_CONST(0xC3C3C3C3C3C3C3C3), ABC_CONST(0x0C0C0C0C0C0C0C0C), ABC_CONST(0x3030303030303030) },
47  { ABC_CONST(0xF00FF00FF00FF00F), ABC_CONST(0x00F000F000F000F0), ABC_CONST(0x0F000F000F000F00) },
48  { ABC_CONST(0xFF0000FFFF0000FF), ABC_CONST(0x0000FF000000FF00), ABC_CONST(0x00FF000000FF0000) },
49  { ABC_CONST(0xFFFF00000000FFFF), ABC_CONST(0x00000000FFFF0000), ABC_CONST(0x0000FFFF00000000) }
50 };
51 // elementary truth tables
52 static word Truth6[6] = {
53  ABC_CONST(0xAAAAAAAAAAAAAAAA),
54  ABC_CONST(0xCCCCCCCCCCCCCCCC),
55  ABC_CONST(0xF0F0F0F0F0F0F0F0),
56  ABC_CONST(0xFF00FF00FF00FF00),
57  ABC_CONST(0xFFFF0000FFFF0000),
58  ABC_CONST(0xFFFFFFFF00000000)
59 };
60 static word Truth10[10][16] = {
61  {ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA)},
62  {ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC)},
63  {ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0)},
64  {ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00)},
65  {ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000)},
66  {ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000)},
67  {ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF)},
68  {ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF)},
69  {ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF)},
70  {ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF),ABC_CONST(0xFFFFFFFFFFFFFFFF)}
71 };
72 
73 extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars );
74 extern void Extra_PrintBinary( FILE * pFile, unsigned Sign[], int nBits );
75 
76 ////////////////////////////////////////////////////////////////////////
77 /// FUNCTION DEFINITIONS ///
78 ////////////////////////////////////////////////////////////////////////
79 
80 static inline int If_Dec08WordNum( int nVars )
81 {
82  return nVars <= 6 ? 1 : 1 << (nVars-6);
83 }
84 static void If_Dec08PrintConfigOne( unsigned z )
85 {
86  unsigned t;
87  t = (z & 0xffff) | ((z & 0xffff) << 16);
88  Extra_PrintBinary( stdout, &t, 16 );
89  printf( " " );
90  Kit_DsdPrintFromTruth( &t, 4 );
91  printf( " " );
92  printf( " %d", (z >> 16) & 7 );
93  printf( " %d", (z >> 20) & 7 );
94  printf( " %d", (z >> 24) & 7 );
95  printf( " %d", (z >> 28) & 7 );
96  printf( "\n" );
97 }
98 void If_Dec08PrintConfig( unsigned * pZ )
99 {
100  while ( *pZ )
101  If_Dec08PrintConfigOne( *pZ++ );
102 }
103 static inline void If_Dec08ComposeLut4( int t, word ** pF, word * pR, int nVars )
104 {
105  word pC[16];
106  int m, w, v, nWords;
107  assert( nVars <= 10 );
108  nWords = If_Dec08WordNum( nVars );
109  for ( w = 0; w < nWords; w++ )
110  pR[w] = 0;
111  for ( m = 0; m < 16; m++ )
112  {
113  if ( !((t >> m) & 1) )
114  continue;
115  for ( w = 0; w < nWords; w++ )
116  pC[w] = ~(word)0;
117  for ( v = 0; v < 4; v++ )
118  for ( w = 0; w < nWords; w++ )
119  pC[w] &= ((m >> v) & 1) ? pF[v][w] : ~pF[v][w];
120  for ( w = 0; w < nWords; w++ )
121  pR[w] |= pC[w];
122  }
123 }
124 void If_Dec08Verify( word * pF, int nVars, unsigned * pZ )
125 {
126  word pN[16][16], * pG[4];
127  int i, w, v, k, nWords;
128  unsigned z;
129  nWords = If_Dec08WordNum( nVars );
130  for ( k = 0; k < nVars; k++ )
131  for ( w = 0; w < nWords; w++ )
132  pN[k][w] = Truth10[k][w];
133  for ( i = 0; (z = pZ[i]); i++, k++ )
134  {
135  for ( v = 0; v < 4; v++ )
136  pG[v] = pN[ (z >> (16+(v<<2))) & 7 ];
137  If_Dec08ComposeLut4( (int)(z & 0xffff), pG, pN[k], nVars );
138  }
139  k--;
140  for ( w = 0; w < nWords; w++ )
141  if ( pN[k][w] != pF[w] )
142  {
143  If_Dec08PrintConfig( pZ );
144  Kit_DsdPrintFromTruth( (unsigned*)pF, nVars ); printf( "\n" );
145  Kit_DsdPrintFromTruth( (unsigned*)pN[k], nVars ); printf( "\n" );
146  printf( "Verification failed!\n" );
147  break;
148  }
149 }
150 
151 
152 // count the number of unique cofactors
153 static inline int If_Dec08CofCount2( word * pF, int nVars )
154 {
155  int nShift = (1 << (nVars - 3));
156  word Mask = (((word)1) << nShift) - 1;
157  word iCof0 = pF[0] & Mask;
158  word iCof1 = iCof0, iCof;
159  int i;
160  assert( nVars >= 6 && nVars <= 8 );
161 // if ( nVars == 10 )
162 // Mask = ~(word)0;
163  for ( i = 1; i < 8; i++ )
164  {
165  iCof = (pF[(i * nShift) / 64] >> ((i * nShift) & 63)) & Mask;
166  if ( iCof == iCof0 )
167  continue;
168  if ( iCof1 == iCof0 )
169  iCof1 = iCof;
170  else if ( iCof != iCof1 )
171  return 3;
172  }
173  return 2;
174 }
175 static inline int If_Dec08CofCount( word * pF, int nVars )
176 {
177  int nShift = (1 << (nVars - 3));
178  word Mask = (((word)1) << nShift) - 1;
179  word iCofs[16], iCof;
180  int i, c, nCofs = 1;
181 // if ( nVars == 10 )
182 // Mask = ~(word)0;
183  iCofs[0] = pF[0] & Mask;
184  for ( i = 1; i < 8; i++ )
185  {
186  iCof = (pF[(i * nShift) / 64] >> ((i * nShift) & 63)) & Mask;
187  for ( c = 0; c < nCofs; c++ )
188  if ( iCof == iCofs[c] )
189  break;
190  if ( c == nCofs )
191  iCofs[nCofs++] = iCof;
192  }
193  return nCofs;
194 }
195 
196 
197 // variable permutation for large functions
198 static inline void If_Dec08Copy( word * pOut, word * pIn, int nVars )
199 {
200  int w, nWords = If_Dec08WordNum( nVars );
201  for ( w = 0; w < nWords; w++ )
202  pOut[w] = pIn[w];
203 }
204 static inline void If_Dec08SwapAdjacent( word * pOut, word * pIn, int iVar, int nVars )
205 {
206  int i, k, nWords = If_Dec08WordNum( nVars );
207  assert( iVar < nVars - 1 );
208  if ( iVar < 5 )
209  {
210  int Shift = (1 << iVar);
211  for ( i = 0; i < nWords; i++ )
212  pOut[i] = (pIn[i] & PMasks[iVar][0]) | ((pIn[i] & PMasks[iVar][1]) << Shift) | ((pIn[i] & PMasks[iVar][2]) >> Shift);
213  }
214  else if ( iVar > 5 )
215  {
216  int Step = (1 << (iVar - 6));
217  for ( k = 0; k < nWords; k += 4*Step )
218  {
219  for ( i = 0; i < Step; i++ )
220  pOut[i] = pIn[i];
221  for ( i = 0; i < Step; i++ )
222  pOut[Step+i] = pIn[2*Step+i];
223  for ( i = 0; i < Step; i++ )
224  pOut[2*Step+i] = pIn[Step+i];
225  for ( i = 0; i < Step; i++ )
226  pOut[3*Step+i] = pIn[3*Step+i];
227  pIn += 4*Step;
228  pOut += 4*Step;
229  }
230  }
231  else // if ( iVar == 5 )
232  {
233  for ( i = 0; i < nWords; i += 2 )
234  {
235  pOut[i] = (pIn[i] & ABC_CONST(0x00000000FFFFFFFF)) | ((pIn[i+1] & ABC_CONST(0x00000000FFFFFFFF)) << 32);
236  pOut[i+1] = (pIn[i+1] & ABC_CONST(0xFFFFFFFF00000000)) | ((pIn[i] & ABC_CONST(0xFFFFFFFF00000000)) >> 32);
237  }
238  }
239 }
240 static inline void If_Dec08MoveTo( word * pF, int nVars, int v, int p, int Pla2Var[], int Var2Pla[] )
241 {
242  word pG[16], * pIn = pF, * pOut = pG, * pTemp;
243  int iPlace0, iPlace1, Count = 0;
244  assert( Var2Pla[v] <= p );
245  while ( Var2Pla[v] != p )
246  {
247  iPlace0 = Var2Pla[v];
248  iPlace1 = Var2Pla[v]+1;
249  If_Dec08SwapAdjacent( pOut, pIn, iPlace0, nVars );
250  pTemp = pIn; pIn = pOut, pOut = pTemp;
251  Var2Pla[Pla2Var[iPlace0]]++;
252  Var2Pla[Pla2Var[iPlace1]]--;
253  Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
254  Pla2Var[iPlace1] ^= Pla2Var[iPlace0];
255  Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
256  Count++;
257  }
258  if ( Count & 1 )
259  If_Dec08Copy( pF, pIn, nVars );
260  assert( Pla2Var[p] == v );
261 }
262 /*
263 // derive binary function
264 static inline int If_Dec08DeriveCount2( word * pF, word * pRes, int nVars )
265 {
266  int nShift = (1 << (nVars - 4));
267  word Mask = (((word)1) << nShift) - 1;
268  int i, MaskDec = 0;
269  word iCof0 = pF[0] & Mask;
270  word iCof1 = pF[0] & Mask;
271  word iCof, * pCof0, * pCof1;
272  if ( nVars == 10 )
273  Mask = ~(word)0;
274  for ( i = 1; i < 16; i++ )
275  {
276  iCof = (pF[(i * nShift) / 64] >> ((i * nShift) & 63)) & Mask;
277  if ( *pCof0 != iCof )
278  {
279  *pCof1 = iCof;
280  MaskDec |= (1 << i);
281  }
282  }
283  *pRes = ((iCof1 << nShift) | iCof0);
284  return MaskDec;
285 }
286 static inline word If_DecTruthStretch( word t, int nVars )
287 {
288  assert( nVars > 1 );
289  if ( nVars == 1 )
290  nVars++, t = (t & 0x3) | ((t & 0x3) << 2);
291  if ( nVars == 2 )
292  nVars++, t = (t & 0xF) | ((t & 0xF) << 4);
293  if ( nVars == 3 )
294  nVars++, t = (t & 0xFF) | ((t & 0xFF) << 8);
295  if ( nVars == 4 )
296  nVars++, t = (t & 0xFFFF) | ((t & 0xFFFF) << 16);
297  if ( nVars == 5 )
298  nVars++, t = (t & 0xFFFFFFFF) | ((t & 0xFFFFFFFF) << 32);
299  assert( nVars >= 6 );
300 }
301 */
302 
303 // support minimization
304 static inline int If_DecSuppIsMinBase( int Supp )
305 {
306  return (Supp & (Supp+1)) == 0;
307 }
308 static inline int If_Dec08HasVar( word * t, int nVars, int iVar )
309 {
310  int nWords = If_Dec08WordNum( nVars );
311  assert( iVar < nVars );
312  if ( iVar < 6 )
313  {
314  int i, Shift = (1 << iVar);
315  for ( i = 0; i < nWords; i++ )
316  if ( (t[i] & ~Truth6[iVar]) != ((t[i] & Truth6[iVar]) >> Shift) )
317  return 1;
318  return 0;
319  }
320  else
321  {
322  int i, k, Step = (1 << (iVar - 6));
323  for ( k = 0; k < nWords; k += 2*Step )
324  {
325  for ( i = 0; i < Step; i++ )
326  if ( t[i] != t[Step+i] )
327  return 1;
328  t += 2*Step;
329  }
330  return 0;
331  }
332 }
333 static inline int If_Dec08Support( word * t, int nVars )
334 {
335  int v, Supp = 0;
336  for ( v = 0; v < nVars; v++ )
337  if ( If_Dec08HasVar( t, nVars, v ) )
338  Supp |= (1 << v);
339  return Supp;
340 }
341 
342 // checks
343 void If_Dec08Cofactors( word * pF, int nVars, int iVar, word * pCof0, word * pCof1 )
344 {
345  int nWords = If_Dec08WordNum( nVars );
346  assert( iVar < nVars );
347  if ( iVar < 6 )
348  {
349  int i, Shift = (1 << iVar);
350  for ( i = 0; i < nWords; i++ )
351  {
352  pCof0[i] = (pF[i] & ~Truth6[iVar]) | ((pF[i] & ~Truth6[iVar]) << Shift);
353  pCof1[i] = (pF[i] & Truth6[iVar]) | ((pF[i] & Truth6[iVar]) >> Shift);
354  }
355  return;
356  }
357  else
358  {
359  int i, k, Step = (1 << (iVar - 6));
360  for ( k = 0; k < nWords; k += 2*Step )
361  {
362  for ( i = 0; i < Step; i++ )
363  {
364  pCof0[i] = pCof0[Step+i] = pF[i];
365  pCof1[i] = pCof1[Step+i] = pF[Step+i];
366  }
367  pF += 2*Step;
368  pCof0 += 2*Step;
369  pCof1 += 2*Step;
370  }
371  return;
372  }
373 }
374 static inline int If_Dec08Count16( int Num16 )
375 {
376  assert( Num16 < (1<<16)-1 );
377  return BitCount8[Num16 & 255] + BitCount8[(Num16 >> 8) & 255];
378 }
379 static inline void If_DecVerifyPerm( int Pla2Var[10], int Var2Pla[10], int nVars )
380 {
381  int i;
382  for ( i = 0; i < nVars; i++ )
383  assert( Pla2Var[Var2Pla[i]] == i );
384 }
385 int If_Dec08Perform( word * pF, int nVars, int fDerive )
386 {
387 // static int Cnt = 0;
388  word pCof0[16], pCof1[16];
389  int Pla2Var[10], Var2Pla[10], Count[210], Masks[210];
390  int i, i0,i1,i2, v, x;
391  assert( nVars >= 6 && nVars <= 8 );
392  // start arrays
393  for ( i = 0; i < nVars; i++ )
394  {
395  assert( If_Dec08HasVar( pF, nVars, i ) );
396  Pla2Var[i] = Var2Pla[i] = i;
397  }
398 /*
399  Cnt++;
400 //if ( Cnt == 108 )
401 {
402 printf( "%d\n", Cnt );
403 //Extra_PrintHex( stdout, (unsigned *)pF, nVars );
404 //printf( "\n" );
405 Kit_DsdPrintFromTruth( (unsigned *)pF, nVars );
406 printf( "\n" );
407 printf( "\n" );
408 }
409 */
410  // generate permutations
411  v = 0;
412  for ( i0 = 0; i0 < nVars; i0++ )
413  for ( i1 = i0+1; i1 < nVars; i1++ )
414  for ( i2 = i1+1; i2 < nVars; i2++, v++ )
415  {
416  If_Dec08MoveTo( pF, nVars, i0, nVars-1, Pla2Var, Var2Pla );
417  If_Dec08MoveTo( pF, nVars, i1, nVars-2, Pla2Var, Var2Pla );
418  If_Dec08MoveTo( pF, nVars, i2, nVars-3, Pla2Var, Var2Pla );
419  If_DecVerifyPerm( Pla2Var, Var2Pla, nVars );
420  Count[v] = If_Dec08CofCount( pF, nVars );
421  Masks[v] = (1 << i0) | (1 << i1) | (1 << i2);
422  assert( Count[v] > 1 );
423 //printf( "%d ", Count[v] );
424  if ( Count[v] == 2 || Count[v] > 5 )
425  continue;
426  for ( x = 0; x < 4; x++ )
427  {
428  If_Dec08Cofactors( pF, nVars, nVars-1-x, pCof0, pCof1 );
429  if ( If_Dec08CofCount2(pCof0, nVars) <= 2 && If_Dec08CofCount2(pCof1, nVars) <= 2 )
430  {
431  Count[v] = -Count[v];
432  break;
433  }
434  }
435  }
436 //printf( "\n" );
437  assert( v <= 210 );
438  // check if there are compatible bound sets
439  for ( i0 = 0; i0 < v; i0++ )
440  for ( i1 = i0+1; i1 < v; i1++ )
441  {
442  if ( If_Dec08Count16(Masks[i0] & Masks[i1]) > 8 - nVars )
443  continue;
444  if ( nVars == 8 )
445  {
446  if ( Count[i0] == 2 && Count[i1] == 2 )
447  return 1;
448  }
449  else if ( nVars == 7 )
450  {
451  if ( (Count[i0] == 2 && Count[i1] == 2) ||
452  (Count[i0] == 2 && Count[i1] < 0) ||
453  (Count[i0] < 0 && Count[i1] == 2) )
454  return 1;
455  }
456  else
457  {
458  if ( (Count[i0] == 2 && Count[i1] == 2) ||
459  (Count[i0] == 2 && Count[i1] < 0) ||
460  (Count[i0] < 0 && Count[i1] == 2) ||
461  (Count[i0] < 0 && Count[i1] < 0) )
462  return 1;
463  }
464  }
465 // printf( "not found\n" );
466  return 0;
467 }
468 
469 
470 /**Function*************************************************************
471 
472  Synopsis [Performs additional check.]
473 
474  Description []
475 
476  SideEffects []
477 
478  SeeAlso []
479 
480 ***********************************************************************/
481 int If_CutPerformCheck08( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr )
482 {
483  int nSupp, fDerive = 0;
484  word pF[16];
485  if ( nLeaves <= 5 )
486  return 1;
487  If_Dec08Copy( pF, (word *)pTruth, nVars );
488  nSupp = If_Dec08Support( pF, nLeaves );
489  if ( !nSupp || !If_DecSuppIsMinBase(nSupp) )
490  return 0;
491  if ( If_Dec08Perform( pF, nLeaves, fDerive ) )
492  {
493 // printf( "1" );
494  return 1;
495 // If_Dec08Verify( t, nLeaves, NULL );
496  }
497 // printf( "0" );
498  return 0;
499 }
500 
501 ////////////////////////////////////////////////////////////////////////
502 /// END OF FILE ///
503 ////////////////////////////////////////////////////////////////////////
504 
505 
507 
void If_Dec08PrintConfig(unsigned *pZ)
Definition: ifDec08.c:98
static void If_Dec08Copy(word *pOut, word *pIn, int nVars)
Definition: ifDec08.c:198
static void If_Dec08SwapAdjacent(word *pOut, word *pIn, int iVar, int nVars)
Definition: ifDec08.c:204
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int If_DecSuppIsMinBase(int Supp)
Definition: ifDec08.c:304
static word Truth6[6]
Definition: ifDec08.c:52
static int If_Dec08CofCount2(word *pF, int nVars)
Definition: ifDec08.c:153
static ABC_NAMESPACE_IMPL_START int BitCount8[256]
DECLARATIONS ///.
Definition: ifDec08.c:33
void If_Dec08Cofactors(word *pF, int nVars, int iVar, word *pCof0, word *pCof1)
Definition: ifDec08.c:343
int nWords
Definition: abcNpn.c:127
static void If_Dec08MoveTo(word *pF, int nVars, int v, int p, int Pla2Var[], int Var2Pla[])
Definition: ifDec08.c:240
static word Truth10[10][16]
Definition: ifDec08.c:60
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
int If_CutPerformCheck08(If_Man_t *p, unsigned *pTruth, int nVars, int nLeaves, char *pStr)
Definition: ifDec08.c:481
static int If_Dec08CofCount(word *pF, int nVars)
Definition: ifDec08.c:175
static int If_Dec08Support(word *t, int nVars)
Definition: ifDec08.c:333
Definition: if.h:180
static void If_DecVerifyPerm(int Pla2Var[10], int Var2Pla[10], int nVars)
Definition: ifDec08.c:379
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int If_Dec08Perform(word *pF, int nVars, int fDerive)
Definition: ifDec08.c:385
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int If_Dec08HasVar(word *t, int nVars, int iVar)
Definition: ifDec08.c:308
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206
static void If_Dec08PrintConfigOne(unsigned z)
Definition: ifDec08.c:84
static void If_Dec08ComposeLut4(int t, word **pF, word *pR, int nVars)
Definition: ifDec08.c:103
#define assert(ex)
Definition: util_old.h:213
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
static int If_Dec08WordNum(int nVars)
FUNCTION DEFINITIONS ///.
Definition: ifDec08.c:80
void If_Dec08Verify(word *pF, int nVars, unsigned *pZ)
Definition: ifDec08.c:124
static int If_Dec08Count16(int Num16)
Definition: ifDec08.c:374
static word PMasks[5][3]
Definition: ifDec08.c:44