ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cutPre22.c File Reference
#include "cutInt.h"
Include dependency graph for cutPre22.c:

Go to the source code of this file.

Classes

struct  Cut_Cell_t_
 
struct  Cut_CMan_t_
 

Macros

#define CUT_CELL_MVAR   9
 DECLARATIONS ///.
 

Typedefs

typedef struct Cut_Cell_t_ Cut_Cell_t
 
typedef struct Cut_CMan_t_ Cut_CMan_t
 

Functions

void Cut_CellLoad ()
 FUNCTION DEFINITIONS ///.
 
void Cut_CellPrecompute ()
 
int Cut_CellIsRunning ()
 
void Cut_CellDumpToFile ()
 
int Cut_CellTruthLookup (unsigned *pTruth, int nVars)
 

Macro Definition Documentation

◆ CUT_CELL_MVAR

#define CUT_CELL_MVAR   9

DECLARATIONS ///.

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

FileName [cutPre22.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Precomputes truth tables for the 2x2 macro cell.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id
cutPre22.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 30 of file cutPre22.c.

Typedef Documentation

◆ Cut_Cell_t

typedef struct Cut_Cell_t_ Cut_Cell_t

Definition at line 32 of file cutPre22.c.

◆ Cut_CMan_t

typedef struct Cut_CMan_t_ Cut_CMan_t

Definition at line 33 of file cutPre22.c.

Function Documentation

◆ Cut_CellDumpToFile()

void Cut_CellDumpToFile ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 835 of file cutPre22.c.

836{
837 FILE * pFile;
838 Cut_CMan_t * p = s_pCMan;
839 Cut_Cell_t * pTemp;
840 char * pFileName = "celllib22.txt";
841 int NumUsed[10][5] = {{0}};
842 int BoxUsed[22][5] = {{0}};
843 int i, k, Counter;
844 abctime clk = Abc_Clock();
845
846 if ( p == NULL )
847 {
848 printf( "Cut_CellDumpToFile: Cell manager is not defined.\n" );
849 return;
850 }
851
852 // count the number of cells used
853 for ( k = CUT_CELL_MVAR; k >= 0; k-- )
854 {
855 for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
856 {
857 if ( pTemp->nUsed == 0 )
858 NumUsed[k][0]++;
859 else if ( pTemp->nUsed < 10 )
860 NumUsed[k][1]++;
861 else if ( pTemp->nUsed < 100 )
862 NumUsed[k][2]++;
863 else if ( pTemp->nUsed < 1000 )
864 NumUsed[k][3]++;
865 else
866 NumUsed[k][4]++;
867
868 for ( i = 0; i < 4; i++ )
869 if ( pTemp->nUsed == 0 )
870 BoxUsed[ (int)pTemp->Box[i] ][0]++;
871 else if ( pTemp->nUsed < 10 )
872 BoxUsed[ (int)pTemp->Box[i] ][1]++;
873 else if ( pTemp->nUsed < 100 )
874 BoxUsed[ (int)pTemp->Box[i] ][2]++;
875 else if ( pTemp->nUsed < 1000 )
876 BoxUsed[ (int)pTemp->Box[i] ][3]++;
877 else
878 BoxUsed[ (int)pTemp->Box[i] ][4]++;
879 }
880 }
881
882 printf( "Functions found = %10d. Functions not found = %10d.\n", p->nCellFound, p->nCellNotFound );
883 for ( k = 0; k <= CUT_CELL_MVAR; k++ )
884 {
885 printf( "%3d : ", k );
886 for ( i = 0; i < 5; i++ )
887 printf( "%8d ", NumUsed[k][i] );
888 printf( "\n" );
889 }
890 printf( "Box usage:\n" );
891 for ( k = 0; k < 22; k++ )
892 {
893 printf( "%3d : ", k );
894 for ( i = 0; i < 5; i++ )
895 printf( "%8d ", BoxUsed[k][i] );
896 printf( " %s", s_NP3Names[k] );
897 printf( "\n" );
898 }
899
900 pFile = fopen( pFileName, "w" );
901 if ( pFile == NULL )
902 {
903 printf( "Cut_CellDumpToFile: Cannout open output file.\n" );
904 return;
905 }
906
907 Counter = 0;
908 for ( k = 0; k <= CUT_CELL_MVAR; k++ )
909 {
910 for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
911 if ( pTemp->nUsed > 0 )
912 {
913 Extra_PrintHexadecimal( pFile, pTemp->uTruth, (k <= 5? 5 : k) );
914 fprintf( pFile, "\n" );
915 Counter++;
916 }
917 fprintf( pFile, "\n" );
918 }
919 fclose( pFile );
920
921 printf( "Library composed of %d functions is written into file \"%s\". ", Counter, pFileName );
922
923 ABC_PRT( "Time", Abc_Clock() - clk );
924}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define CUT_CELL_MVAR
DECLARATIONS ///.
Definition cutExpand.c:30
struct Cut_Cell_t_ Cut_Cell_t
Definition cutPre22.c:32
struct Cut_CMan_t_ Cut_CMan_t
Definition cutPre22.c:33
Cube * p
Definition exorList.c:222
void Extra_PrintHexadecimal(FILE *pFile, unsigned Sign[], int nVars)
Cut_Cell_t * pNextVar
Definition cutPre22.c:38
char Box[4]
Definition cutPre22.c:41
unsigned uTruth[1<<(CUT_CELL_MVAR-5)]
Definition cutPre22.c:49
Here is the call graph for this function:

◆ Cut_CellIsRunning()

int Cut_CellIsRunning ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 819 of file cutPre22.c.

820{
821 return s_pCMan != NULL;
822}

◆ Cut_CellLoad()

void Cut_CellLoad ( )

FUNCTION DEFINITIONS ///.

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

Synopsis [Start the precomputation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 169 of file cutPre22.c.

170{
171 FILE * pFile;
172 char * pFileName = "cells22_daomap_iwls.txt";
173 char pString[1000];
174 Cut_CMan_t * p;
175 Cut_Cell_t * pCell;
176 int Length; //, i;
177 pFile = fopen( pFileName, "r" );
178 if ( pFile == NULL )
179 {
180 printf( "Cannot open file \"%s\".\n", pFileName );
181 return;
182 }
183 // start the manager
184 p = Cut_CManStart();
185 // load truth tables
186 while ( fgets(pString, 1000, pFile) )
187 {
188 Length = strlen(pString);
189 pString[Length--] = 0;
190 if ( Length == 0 )
191 continue;
192 // derive the cell
193 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
194 memset( pCell, 0, sizeof(Cut_Cell_t) );
195 pCell->nVars = Abc_Base2Log(Length*4);
196 pCell->nUsed = 1;
197// Extra_TruthCopy( pCell->uTruth, pTruth, nVars );
198 Extra_ReadHexadecimal( pCell->uTruth, pString, pCell->nVars );
199 Cut_CellSuppMin( pCell );
200/*
201 // set the elementary permutation
202 for ( i = 0; i < (int)pCell->nVars; i++ )
203 pCell->CanonPerm[i] = i;
204 // canonicize
205 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
206*/
207 // add to the table
208 p->nTotal++;
209
210// Extra_PrintHexadecimal( stdout, pCell->uTruth, pCell->nVars ); printf( "\n" );
211// if ( p->nTotal == 500 )
212// break;
213
214 if ( !Cut_CellTableLookup( p, pCell ) ) // new cell
215 p->nGood++;
216 }
217 printf( "Read %d cells from file \"%s\". Added %d cells to the table.\n", p->nTotal, pFileName, p->nGood );
218 fclose( pFile );
219// return p;
220}
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
int Extra_ReadHexadecimal(unsigned Sign[], char *pString, int nVars)
unsigned nVars
Definition cutPre22.c:42
char * memset()
int strlen()
Here is the call graph for this function:

◆ Cut_CellPrecompute()

void Cut_CellPrecompute ( )

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

Synopsis [Precomputes truth tables for the 2x2 macro cell.]

Description []

SideEffects []

SeeAlso []

Definition at line 233 of file cutPre22.c.

234{
235 Cut_CMan_t * p;
236 Cut_Cell_t * pCell, * pTemp;
237 int i1, i2, i3, i, j, k, c;
238 abctime clk = Abc_Clock(); //, clk2 = Abc_Clock();
239
240 p = Cut_CManStart();
241
242 // precompute truth tables
243 for ( i = 0; i < 22; i++ )
244 Cut_CellTruthElem( p->uInputs[0], p->uInputs[1], p->uInputs[2], p->uTemp1[i], 9, i );
245 for ( i = 0; i < 22; i++ )
246 Cut_CellTruthElem( p->uInputs[3], p->uInputs[4], p->uInputs[5], p->uTemp2[i], 9, i );
247 for ( i = 0; i < 22; i++ )
248 Cut_CellTruthElem( p->uInputs[6], p->uInputs[7], p->uInputs[8], p->uTemp3[i], 9, i );
249/*
250 if ( k == 8 && ((i1 == 6 && i2 == 14 && i3 == 20) || (i1 == 20 && i2 == 6 && i3 == 14)) )
251 {
252 Extra_PrintBinary( stdout, &pCell->CanonPhase, pCell->nVars+1 ); printf( " : " );
253 for ( i = 0; i < pCell->nVars; i++ )
254 printf( "%d=%d/%d ", pCell->CanonPerm[i], pCell->Store[2*i], pCell->Store[2*i+1] );
255 Extra_PrintHexadecimal( stdout, pCell->uTruth, pCell->nVars );
256 printf( "\n" );
257 }
258*/
259/*
260 // go through symmetric roots
261 for ( k = 0; k < 5; k++ )
262 for ( i1 = 0; i1 < 22; i1++ )
263 for ( i2 = i1; i2 < 22; i2++ )
264 for ( i3 = i2; i3 < 22; i3++ )
265 {
266 // derive the cell
267 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
268 memset( pCell, 0, sizeof(Cut_Cell_t) );
269 pCell->nVars = 9;
270 pCell->Box[0] = s_NPNe3s[k];
271 pCell->Box[1] = i1;
272 pCell->Box[2] = i2;
273 pCell->Box[3] = i3;
274 // fill in the truth table
275 Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3s[k] );
276 // canonicize
277 Cut_CellCanonicize( pCell );
278
279 // add to the table
280 p->nTotal++;
281 if ( Cut_CellTableLookup( p, pCell ) ) // already exists
282 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
283 else
284 p->nGood++;
285 }
286
287 // go through partially symmetric roots
288 for ( k = 0; k < 4; k++ )
289 for ( i1 = 0; i1 < 22; i1++ )
290 for ( i2 = 0; i2 < 22; i2++ )
291 for ( i3 = i2; i3 < 22; i3++ )
292 {
293 // derive the cell
294 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
295 memset( pCell, 0, sizeof(Cut_Cell_t) );
296 pCell->nVars = 9;
297 pCell->Box[0] = s_NPNe3p[k];
298 pCell->Box[1] = i1;
299 pCell->Box[2] = i2;
300 pCell->Box[3] = i3;
301 // fill in the truth table
302 Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3p[k] );
303 // canonicize
304 Cut_CellCanonicize( pCell );
305
306 // add to the table
307 p->nTotal++;
308 if ( Cut_CellTableLookup( p, pCell ) ) // already exists
309 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
310 else
311 p->nGood++;
312 }
313
314 // go through non-symmetric functions
315 for ( i1 = 0; i1 < 22; i1++ )
316 for ( i2 = 0; i2 < 22; i2++ )
317 for ( i3 = 0; i3 < 22; i3++ )
318 {
319 // derive the cell
320 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
321 memset( pCell, 0, sizeof(Cut_Cell_t) );
322 pCell->nVars = 9;
323 pCell->Box[0] = 17;
324 pCell->Box[1] = i1;
325 pCell->Box[2] = i2;
326 pCell->Box[3] = i3;
327 // fill in the truth table
328 Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, 17 );
329 // canonicize
330 Cut_CellCanonicize( pCell );
331
332 // add to the table
333 p->nTotal++;
334 if ( Cut_CellTableLookup( p, pCell ) ) // already exists
335 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
336 else
337 p->nGood++;
338 }
339*/
340
341 // go through non-symmetric functions
342 for ( k = 0; k < 10; k++ )
343 for ( i1 = 0; i1 < 22; i1++ )
344 for ( i2 = 0; i2 < 22; i2++ )
345 for ( i3 = 0; i3 < 22; i3++ )
346 {
347 // derive the cell
348 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
349 memset( pCell, 0, sizeof(Cut_Cell_t) );
350 pCell->nVars = 9;
351 pCell->Box[0] = s_NPNe3[k];
352 pCell->Box[1] = i1;
353 pCell->Box[2] = i2;
354 pCell->Box[3] = i3;
355 // set the elementary permutation
356 for ( i = 0; i < (int)pCell->nVars; i++ )
357 pCell->CanonPerm[i] = i;
358 // fill in the truth table
359 Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3[k] );
360 // minimize the support
361 Cut_CellSuppMin( pCell );
362
363 // canonicize
364 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
365
366 // add to the table
367 p->nTotal++;
368 if ( Cut_CellTableLookup( p, pCell ) ) // already exists
369 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
370 else
371 {
372 p->nGood++;
373 p->nVarCounts[pCell->nVars]++;
374
375 if ( pCell->nVars )
376 for ( i = 0; i < (int)pCell->nVars-1; i++ )
377 {
378 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] ) // i and i+1 cannot be symmetric
379 continue;
380 // i and i+1 can be symmetric
381 // find the end of this group
382 for ( j = i+1; j < (int)pCell->nVars; j++ )
383 if ( pCell->Store[2*i] != pCell->Store[2*j] )
384 break;
385
386 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
387 p->nSymGroupsE[j-i]++;
388 else
389 p->nSymGroups[j-i]++;
390 i = j - 1;
391 }
392/*
393 if ( pCell->nVars == 3 )
394 {
395 Extra_PrintBinary( stdout, pCell->uTruth, 32 ); printf( "\n" );
396 for ( i = 0; i < (int)pCell->nVars; i++ )
397 printf( "%d=%d/%d ", pCell->CanonPerm[i], pCell->Store[2*i], pCell->Store[2*i+1] );
398 printf( "\n" );
399 }
400*/
401 }
402 }
403
404 printf( "BASIC: Total = %d. Good = %d. Entry = %d. ", (int)p->nTotal, (int)p->nGood, (int)sizeof(Cut_Cell_t) );
405 ABC_PRT( "Time", Abc_Clock() - clk );
406 printf( "Cells: " );
407 for ( i = 0; i <= 9; i++ )
408 printf( "%d=%d ", i, p->nVarCounts[i] );
409 printf( "\nDiffs: " );
410 for ( i = 0; i <= 9; i++ )
411 printf( "%d=%d ", i, p->nSymGroups[i] );
412 printf( "\nEquals: " );
413 for ( i = 0; i <= 9; i++ )
414 printf( "%d=%d ", i, p->nSymGroupsE[i] );
415 printf( "\n" );
416
417 // continue adding new cells using support
418 for ( k = CUT_CELL_MVAR; k > 3; k-- )
419 {
420 for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
421 for ( i1 = 0; i1 < k; i1++ )
422 for ( i2 = i1+1; i2 < k; i2++ )
423 for ( c = 0; c < 3; c++ )
424 {
425 // derive the cell
426 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
427 memset( pCell, 0, sizeof(Cut_Cell_t) );
428 pCell->nVars = pTemp->nVars;
429 pCell->pParent = pTemp;
430 // set the elementary permutation
431 for ( i = 0; i < (int)pCell->nVars; i++ )
432 pCell->CanonPerm[i] = i;
433 // fill in the truth table
434 Extra_TruthCopy( pCell->uTruth, pTemp->uTruth, pTemp->nVars );
435 // create the cross-bar
436 pCell->CrossBar0 = i1;
437 pCell->CrossBar1 = i2;
438 pCell->CrossBarPhase = c;
439 Cut_CellCrossBar( pCell );
440 // minimize the support
441//clk2 = Abc_Clock();
442 Cut_CellSuppMin( pCell );
443//p->timeSupp += Abc_Clock() - clk2;
444 // canonicize
445//clk2 = Abc_Clock();
446 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
447//p->timeCanon += Abc_Clock() - clk2;
448
449 // add to the table
450//clk2 = Abc_Clock();
451 p->nTotal++;
452 if ( Cut_CellTableLookup( p, pCell ) ) // already exists
453 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
454 else
455 {
456 p->nGood++;
457 p->nVarCounts[pCell->nVars]++;
458
459 for ( i = 0; i < (int)pCell->nVars-1; i++ )
460 {
461 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] ) // i and i+1 cannot be symmetric
462 continue;
463 // i and i+1 can be symmetric
464 // find the end of this group
465 for ( j = i+1; j < (int)pCell->nVars; j++ )
466 if ( pCell->Store[2*i] != pCell->Store[2*j] )
467 break;
468
469 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
470 p->nSymGroupsE[j-i]++;
471 else
472 p->nSymGroups[j-i]++;
473 i = j - 1;
474 }
475/*
476 if ( pCell->nVars == 3 )
477 {
478 Extra_PrintBinary( stdout, pCell->uTruth, 32 ); printf( "\n" );
479 for ( i = 0; i < (int)pCell->nVars; i++ )
480 printf( "%d=%d/%d ", pCell->CanonPerm[i], pCell->Store[2*i], pCell->Store[2*i+1] );
481 printf( "\n" );
482 }
483*/
484 }
485//p->timeTable += Abc_Clock() - clk2;
486 }
487
488 printf( "VAR %d: Total = %d. Good = %d. Entry = %d. ", k, p->nTotal, p->nGood, (int)sizeof(Cut_Cell_t) );
489 ABC_PRT( "Time", Abc_Clock() - clk );
490 printf( "Cells: " );
491 for ( i = 0; i <= 9; i++ )
492 printf( "%d=%d ", i, p->nVarCounts[i] );
493 printf( "\nDiffs: " );
494 for ( i = 0; i <= 9; i++ )
495 printf( "%d=%d ", i, p->nSymGroups[i] );
496 printf( "\nEquals: " );
497 for ( i = 0; i <= 9; i++ )
498 printf( "%d=%d ", i, p->nSymGroupsE[i] );
499 printf( "\n" );
500 }
501// printf( "\n" );
502 ABC_PRT( "Supp ", p->timeSupp );
503 ABC_PRT( "Canon", p->timeCanon );
504 ABC_PRT( "Table", p->timeTable );
505// Cut_CManStop( p );
506}
unsigned Extra_TruthSemiCanonicize(unsigned *pInOut, unsigned *pAux, int nVars, char *pCanonPerm, short *pStore)
void Extra_MmFixedEntryRecycle(Extra_MmFixed_t *p, char *pEntry)
unsigned CrossBarPhase
Definition cutPre22.c:45
unsigned CrossBar1
Definition cutPre22.c:44
unsigned CanonPhase
Definition cutPre22.c:46
short Store[2 *CUT_CELL_MVAR]
Definition cutPre22.c:48
Cut_Cell_t * pParent
Definition cutPre22.c:39
char CanonPerm[CUT_CELL_MVAR+3]
Definition cutPre22.c:47
unsigned CrossBar0
Definition cutPre22.c:43
Here is the call graph for this function:

◆ Cut_CellTruthLookup()

int Cut_CellTruthLookup ( unsigned * pTruth,
int nVars )

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

Synopsis [Looks up if the given function exists in the hash table.]

Description [If the function exists, returns 1, meaning that it can be implemented using two levels of 3-input LUTs. If the function does not exist, return 0.]

SideEffects []

SeeAlso []

Definition at line 940 of file cutPre22.c.

941{
942 Cut_CMan_t * p = s_pCMan;
943 Cut_Cell_t * pTemp;
944 Cut_Cell_t Cell, * pCell = &Cell;
945 unsigned Hash;
946 int i;
947
948 // cell manager is not defined
949 if ( p == NULL )
950 {
951 printf( "Cut_CellTruthLookup: Cell manager is not defined.\n" );
952 return 0;
953 }
954
955 // canonicize
956 memset( pCell, 0, sizeof(Cut_Cell_t) );
957 pCell->nVars = nVars;
958 Extra_TruthCopy( pCell->uTruth, pTruth, nVars );
959 Cut_CellSuppMin( pCell );
960 // set the elementary permutation
961 for ( i = 0; i < (int)pCell->nVars; i++ )
962 pCell->CanonPerm[i] = i;
963 // canonicize
964 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
965
966
967 // check if the cell exists
968 Hash = Extra_TruthHash( pCell->uTruth, Extra_TruthWordNum(pCell->nVars) );
969 if ( st__lookup( p->tTable, (char *)(ABC_PTRUINT_T)Hash, (char **)&pTemp ) )
970 {
971 for ( ; pTemp; pTemp = pTemp->pNext )
972 {
973 if ( pTemp->nVars != pCell->nVars )
974 continue;
975 if ( Extra_TruthIsEqual(pTemp->uTruth, pCell->uTruth, pCell->nVars) )
976 {
977 pTemp->nUsed++;
978 p->nCellFound++;
979 return 1;
980 }
981 }
982 }
983 p->nCellNotFound++;
984 return 0;
985}
unsigned Extra_TruthHash(unsigned *pIn, int nWords)
int st__lookup(st__table *table, const char *key, char **value)
Definition st.c:114
Here is the call graph for this function: