src/opt/cut/cutPre22.c File Reference

#include "cutInt.h"
Include dependency graph for cutPre22.c:

Go to the source code of this file.

Data Structures

struct  Cut_Cell_t_
struct  Cut_CMan_t_

Defines

#define CUT_CELL_MVAR   9

Typedefs

typedef struct Cut_Cell_t_ Cut_Cell_t
typedef struct Cut_CMan_t_ Cut_CMan_t

Functions

static Cut_CMan_tCut_CManStart ()
static void Cut_CManStop (Cut_CMan_t *p)
static void Cut_CellTruthElem (unsigned *InA, unsigned *InB, unsigned *InC, unsigned *pOut, int nVars, int Type)
static void Cut_CellCanonicize (Cut_CMan_t *p, Cut_Cell_t *pCell)
static int Cut_CellTableLookup (Cut_CMan_t *p, Cut_Cell_t *pCell)
static void Cut_CellSuppMin (Cut_Cell_t *pCell)
static void Cut_CellCrossBar (Cut_Cell_t *pCell)
void Cut_CellLoad ()
void Cut_CellPrecompute ()
int Cut_CellIsRunning ()
void Cut_CellDumpToFile ()
int Cut_CellTruthLookup (unsigned *pTruth, int nVars)

Variables

static char * s_NP3 [22]
static char * s_NP3Names [22]
static int s_NP3VarNums [22] = { 0, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
static int s_NPNe3 [10] = { 6, 8, 10, 11, 12, 14, 15, 17, 18, 20 }
static int s_NPNe3s [10] = { 6, 10, 14, 15, 18 }
static int s_NPNe3p [10] = { 8, 11, 12, 20 }
static Cut_CMan_ts_pCMan = NULL

Define Documentation

#define CUT_CELL_MVAR   9

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

] DECLARATIONS ///

Definition at line 27 of file cutPre22.c.


Typedef Documentation

typedef struct Cut_Cell_t_ Cut_Cell_t

Definition at line 29 of file cutPre22.c.

typedef struct Cut_CMan_t_ Cut_CMan_t

Definition at line 30 of file cutPre22.c.


Function Documentation

static void Cut_CellCanonicize ( Cut_CMan_t p,
Cut_Cell_t pCell 
) [static]
void Cut_CellCrossBar ( Cut_Cell_t pCell  )  [static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 592 of file cutPre22.c.

00593 {
00594     static unsigned uTemp0[1<<(CUT_CELL_MVAR-5)];
00595     static unsigned uTemp1[1<<(CUT_CELL_MVAR-5)];
00596     Extra_TruthCopy( uTemp0, pCell->uTruth, pCell->nVars );
00597     Extra_TruthCopy( uTemp1, pCell->uTruth, pCell->nVars );
00598     if ( pCell->CanonPhase == 0 )
00599     {
00600         Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar0 );
00601         Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar1 );
00602         Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar0 );
00603         Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar1 );
00604     }
00605     else if ( pCell->CanonPhase == 1 )
00606     {
00607         Extra_TruthCofactor1( uTemp0, pCell->nVars, pCell->CrossBar0 );
00608         Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar1 );
00609         Extra_TruthCofactor0( uTemp1, pCell->nVars, pCell->CrossBar0 );
00610         Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar1 );
00611     }
00612     else if ( pCell->CanonPhase == 2 )
00613     {
00614         Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar0 );
00615         Extra_TruthCofactor1( uTemp0, pCell->nVars, pCell->CrossBar1 );
00616         Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar0 );
00617         Extra_TruthCofactor0( uTemp1, pCell->nVars, pCell->CrossBar1 );
00618     }
00619     else assert( 0 );
00620     Extra_TruthMux( pCell->uTruth, uTemp0, uTemp1, pCell->nVars, pCell->CrossBar0 );
00621 }

void Cut_CellDumpToFile (  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 831 of file cutPre22.c.

00832 {
00833     FILE * pFile;
00834     Cut_CMan_t * p = s_pCMan;
00835     Cut_Cell_t * pTemp;
00836     char * pFileName = "celllib22.txt";
00837     int NumUsed[10][5] = {{0}};
00838     int BoxUsed[22][5] = {{0}};
00839     int i, k, Counter;
00840     int clk = clock();
00841 
00842     if ( p == NULL )
00843     {
00844         printf( "Cut_CellDumpToFile: Cell manager is not defined.\n" );
00845         return;
00846     }
00847 
00848     // count the number of cells used
00849     for ( k = CUT_CELL_MVAR; k >= 0; k-- )
00850     {
00851         for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
00852         {
00853             if ( pTemp->nUsed == 0 )
00854                 NumUsed[k][0]++;
00855             else if ( pTemp->nUsed < 10 )
00856                 NumUsed[k][1]++;
00857             else if ( pTemp->nUsed < 100 )
00858                 NumUsed[k][2]++;
00859             else if ( pTemp->nUsed < 1000 )
00860                 NumUsed[k][3]++;
00861             else 
00862                 NumUsed[k][4]++;
00863 
00864             for ( i = 0; i < 4; i++ )
00865                 if ( pTemp->nUsed == 0 )
00866                     BoxUsed[ pTemp->Box[i] ][0]++;
00867                 else if ( pTemp->nUsed < 10 )
00868                     BoxUsed[ pTemp->Box[i] ][1]++;
00869                 else if ( pTemp->nUsed < 100 )
00870                     BoxUsed[ pTemp->Box[i] ][2]++;
00871                 else if ( pTemp->nUsed < 1000 )
00872                     BoxUsed[ pTemp->Box[i] ][3]++;
00873                 else 
00874                     BoxUsed[ pTemp->Box[i] ][4]++;
00875         }
00876     }
00877 
00878     printf( "Functions found = %10d.  Functions not found = %10d.\n", p->nCellFound, p->nCellNotFound );
00879     for ( k = 0; k <= CUT_CELL_MVAR; k++ )
00880     {
00881         printf( "%3d  : ", k );
00882         for ( i = 0; i < 5; i++ ) 
00883             printf( "%8d ", NumUsed[k][i] );
00884         printf( "\n" );
00885     }
00886     printf( "Box usage:\n" );
00887     for ( k = 0; k < 22; k++ )
00888     {
00889         printf( "%3d  : ", k );
00890         for ( i = 0; i < 5; i++ ) 
00891             printf( "%8d ", BoxUsed[k][i] );
00892         printf( "  %s", s_NP3Names[k] );
00893         printf( "\n" );
00894     }
00895 
00896     pFile = fopen( pFileName, "w" );
00897     if ( pFile == NULL )
00898     {
00899         printf( "Cut_CellDumpToFile: Cannout open output file.\n" );
00900         return;
00901     }
00902 
00903     Counter = 0;
00904     for ( k = 0; k <= CUT_CELL_MVAR; k++ )
00905     {
00906         for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
00907             if ( pTemp->nUsed > 0 )
00908             {
00909                 Extra_PrintHexadecimal( pFile, pTemp->uTruth, (k <= 5? 5 : k) );
00910                 fprintf( pFile, "\n" );
00911                 Counter++;
00912             }
00913         fprintf( pFile, "\n" );
00914     }
00915     fclose( pFile );
00916 
00917     printf( "Library composed of %d functions is written into file \"%s\".  ", Counter, pFileName );
00918 
00919     PRT( "Time", clock() - clk );
00920 }

int Cut_CellIsRunning (  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 815 of file cutPre22.c.

00816 {
00817     return s_pCMan != NULL;
00818 }

void Cut_CellLoad (  ) 

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

Synopsis [Start the precomputation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 166 of file cutPre22.c.

00167 {
00168     FILE * pFile;
00169     char * pFileName = "cells22_daomap_iwls.txt";
00170     char pString[1000];
00171     Cut_CMan_t * p;
00172     Cut_Cell_t * pCell;
00173     int Length; //, i;
00174     pFile = fopen( pFileName, "r" );
00175     if ( pFile == NULL )
00176     {
00177         printf( "Cannot open file \"%s\".\n", pFileName );
00178         return;
00179     }
00180    // start the manager
00181     p = Cut_CManStart();
00182     // load truth tables
00183     while ( fgets(pString, 1000, pFile) )
00184     {
00185         Length = strlen(pString);
00186         pString[Length--] = 0;
00187         if ( Length == 0 )
00188             continue;
00189         // derive the cell
00190         pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00191         memset( pCell, 0, sizeof(Cut_Cell_t) );
00192         pCell->nVars = Extra_Base2Log(Length*4);
00193         pCell->nUsed = 1;
00194 //        Extra_TruthCopy( pCell->uTruth, pTruth, nVars );
00195         Extra_ReadHexadecimal( pCell->uTruth, pString, pCell->nVars );
00196         Cut_CellSuppMin( pCell );
00197 /*
00198         // set the elementary permutation
00199         for ( i = 0; i < (int)pCell->nVars; i++ )
00200             pCell->CanonPerm[i] = i;
00201         // canonicize
00202         pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00203 */
00204         // add to the table
00205         p->nTotal++;
00206 
00207 //        Extra_PrintHexadecimal( stdout, pCell->uTruth, pCell->nVars ); printf( "\n" );
00208 //        if ( p->nTotal == 500 )
00209 //            break;
00210 
00211         if ( !Cut_CellTableLookup( p, pCell ) ) // new cell
00212             p->nGood++;
00213     }
00214     printf( "Read %d cells from file \"%s\". Added %d cells to the table.\n", p->nTotal, pFileName, p->nGood );
00215     fclose( pFile );
00216 //    return p;
00217 }

void Cut_CellPrecompute (  ) 

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file cutPre22.c.

00231 {
00232     Cut_CMan_t * p;
00233     Cut_Cell_t * pCell, * pTemp;
00234     int i1, i2, i3, i, j, k, c, clk = clock(), clk2 = clock();
00235 
00236     p = Cut_CManStart();
00237 
00238     // precompute truth tables
00239     for ( i = 0; i < 22; i++ )
00240         Cut_CellTruthElem( p->uInputs[0], p->uInputs[1], p->uInputs[2], p->uTemp1[i], 9, i );
00241     for ( i = 0; i < 22; i++ )
00242         Cut_CellTruthElem( p->uInputs[3], p->uInputs[4], p->uInputs[5], p->uTemp2[i], 9, i );
00243     for ( i = 0; i < 22; i++ )
00244         Cut_CellTruthElem( p->uInputs[6], p->uInputs[7], p->uInputs[8], p->uTemp3[i], 9, i );
00245 /*
00246         if ( k == 8 && ((i1 == 6 && i2 == 14 && i3 == 20) || (i1 == 20 && i2 == 6 && i3 == 14)) )
00247         {
00248             Extra_PrintBinary( stdout, &pCell->CanonPhase, pCell->nVars+1 ); printf( " : " );
00249             for ( i = 0; i < pCell->nVars; i++ )
00250                 printf( "%d=%d/%d  ", pCell->CanonPerm[i], pCell->Store[2*i], pCell->Store[2*i+1] );
00251             Extra_PrintHexadecimal( stdout, pCell->uTruth, pCell->nVars );
00252             printf( "\n" );
00253         }
00254 */
00255 /*
00256     // go through symmetric roots
00257     for ( k = 0; k < 5; k++ )
00258     for ( i1 =  0; i1 < 22; i1++ )
00259     for ( i2 = i1; i2 < 22; i2++ )
00260     for ( i3 = i2; i3 < 22; i3++ )
00261     {
00262         // derive the cell
00263         pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00264         memset( pCell, 0, sizeof(Cut_Cell_t) );
00265         pCell->nVars  = 9;
00266         pCell->Box[0] = s_NPNe3s[k];
00267         pCell->Box[1] = i1;
00268         pCell->Box[2] = i2;
00269         pCell->Box[3] = i3;
00270         // fill in the truth table
00271         Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3s[k] );
00272         // canonicize
00273         Cut_CellCanonicize( pCell );
00274 
00275         // add to the table
00276         p->nTotal++;
00277         if ( Cut_CellTableLookup( p, pCell ) ) // already exists
00278             Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00279         else
00280             p->nGood++;
00281     }
00282 
00283     // go through partially symmetric roots
00284     for ( k = 0; k < 4; k++ )
00285     for ( i1 = 0;  i1 < 22; i1++ )
00286     for ( i2 = 0;  i2 < 22; i2++ )
00287     for ( i3 = i2; i3 < 22; i3++ )
00288     {
00289         // derive the cell
00290         pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00291         memset( pCell, 0, sizeof(Cut_Cell_t) );
00292         pCell->nVars  = 9;
00293         pCell->Box[0] = s_NPNe3p[k];
00294         pCell->Box[1] = i1;
00295         pCell->Box[2] = i2;
00296         pCell->Box[3] = i3;
00297         // fill in the truth table
00298         Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3p[k] );
00299         // canonicize
00300         Cut_CellCanonicize( pCell );
00301 
00302         // add to the table
00303         p->nTotal++;
00304         if ( Cut_CellTableLookup( p, pCell ) ) // already exists
00305             Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00306         else
00307             p->nGood++;
00308     }
00309 
00310     // go through non-symmetric functions
00311     for ( i1 = 0; i1 < 22; i1++ )
00312     for ( i2 = 0; i2 < 22; i2++ )
00313     for ( i3 = 0; i3 < 22; i3++ )
00314     {
00315         // derive the cell
00316         pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00317         memset( pCell, 0, sizeof(Cut_Cell_t) );
00318         pCell->nVars  = 9;
00319         pCell->Box[0] = 17;
00320         pCell->Box[1] = i1;
00321         pCell->Box[2] = i2;
00322         pCell->Box[3] = i3;
00323         // fill in the truth table
00324         Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, 17 );
00325         // canonicize
00326         Cut_CellCanonicize( pCell );
00327 
00328         // add to the table
00329         p->nTotal++;
00330         if ( Cut_CellTableLookup( p, pCell ) ) // already exists
00331             Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00332         else
00333             p->nGood++;
00334     }
00335 */
00336 
00337     // go through non-symmetric functions
00338     for ( k = 0; k < 10; k++ )
00339     for ( i1 = 0; i1 < 22; i1++ )
00340     for ( i2 = 0; i2 < 22; i2++ )
00341     for ( i3 = 0; i3 < 22; i3++ )
00342     {
00343         // derive the cell
00344         pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00345         memset( pCell, 0, sizeof(Cut_Cell_t) );
00346         pCell->nVars  = 9;
00347         pCell->Box[0] = s_NPNe3[k];
00348         pCell->Box[1] = i1;
00349         pCell->Box[2] = i2;
00350         pCell->Box[3] = i3;
00351         // set the elementary permutation
00352         for ( i = 0; i < (int)pCell->nVars; i++ )
00353             pCell->CanonPerm[i] = i;
00354         // fill in the truth table
00355         Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3[k] );
00356         // minimize the support
00357         Cut_CellSuppMin( pCell );
00358 
00359         // canonicize
00360         pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00361 
00362         // add to the table
00363         p->nTotal++;
00364         if ( Cut_CellTableLookup( p, pCell ) ) // already exists
00365             Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00366         else
00367         {
00368             p->nGood++;
00369             p->nVarCounts[pCell->nVars]++;
00370 
00371             if ( pCell->nVars )
00372             for ( i = 0; i < (int)pCell->nVars-1; i++ )
00373             {
00374                 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] ) // i and i+1 cannot be symmetric
00375                     continue;
00376                 // i and i+1 can be symmetric
00377                 // find the end of this group
00378                 for ( j = i+1; j < (int)pCell->nVars; j++ )
00379                     if ( pCell->Store[2*i] != pCell->Store[2*j] ) 
00380                         break;
00381 
00382                 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
00383                     p->nSymGroupsE[j-i]++;
00384                 else
00385                     p->nSymGroups[j-i]++;
00386                 i = j - 1;
00387             }
00388 /*
00389             if ( pCell->nVars == 3 )
00390             {
00391                 Extra_PrintBinary( stdout, pCell->uTruth, 32 ); printf( "\n" );
00392                 for ( i = 0; i < (int)pCell->nVars; i++ )
00393                     printf( "%d=%d/%d  ", pCell->CanonPerm[i], pCell->Store[2*i], pCell->Store[2*i+1] );
00394                 printf( "\n" );
00395             }
00396 */
00397         }
00398     }
00399 
00400     printf( "BASIC: Total = %d. Good = %d. Entry = %d. ", p->nTotal, p->nGood, sizeof(Cut_Cell_t) );
00401     PRT( "Time", clock() - clk );
00402     printf( "Cells:  " );
00403     for ( i = 0; i <= 9; i++ )
00404         printf( "%d=%d ", i, p->nVarCounts[i] );
00405     printf( "\nDiffs:  " );
00406     for ( i = 0; i <= 9; i++ )
00407         printf( "%d=%d ", i, p->nSymGroups[i] );
00408     printf( "\nEquals: " );
00409     for ( i = 0; i <= 9; i++ )
00410         printf( "%d=%d ", i, p->nSymGroupsE[i] );
00411     printf( "\n" );
00412 
00413     // continue adding new cells using support
00414     for ( k = CUT_CELL_MVAR; k > 3; k-- )
00415     {
00416         for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
00417         for ( i1 = 0; i1 < k; i1++ )
00418         for ( i2 = i1+1; i2 < k; i2++ )
00419         for ( c = 0; c < 3; c++ )
00420         {
00421             // derive the cell
00422             pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00423             memset( pCell, 0, sizeof(Cut_Cell_t) );
00424             pCell->nVars   = pTemp->nVars;
00425             pCell->pParent = pTemp;
00426             // set the elementary permutation
00427             for ( i = 0; i < (int)pCell->nVars; i++ )
00428                 pCell->CanonPerm[i] = i;
00429             // fill in the truth table
00430             Extra_TruthCopy( pCell->uTruth, pTemp->uTruth, pTemp->nVars );
00431             // create the cross-bar
00432             pCell->CrossBar0 = i1;
00433             pCell->CrossBar1 = i2;
00434             pCell->CrossBarPhase = c;
00435             Cut_CellCrossBar( pCell );
00436             // minimize the support
00437 //clk2 = clock();
00438             Cut_CellSuppMin( pCell );
00439 //p->timeSupp += clock() - clk2;
00440             // canonicize
00441 //clk2 = clock();
00442             pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00443 //p->timeCanon += clock() - clk2;
00444 
00445             // add to the table
00446 //clk2 = clock();
00447             p->nTotal++;
00448             if ( Cut_CellTableLookup( p, pCell ) ) // already exists
00449                 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00450             else
00451             {
00452                 p->nGood++;
00453                 p->nVarCounts[pCell->nVars]++;
00454 
00455                 for ( i = 0; i < (int)pCell->nVars-1; i++ )
00456                 {
00457                     if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] ) // i and i+1 cannot be symmetric
00458                         continue;
00459                     // i and i+1 can be symmetric
00460                     // find the end of this group
00461                     for ( j = i+1; j < (int)pCell->nVars; j++ )
00462                         if ( pCell->Store[2*i] != pCell->Store[2*j] ) 
00463                             break;
00464 
00465                     if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
00466                         p->nSymGroupsE[j-i]++;
00467                     else
00468                         p->nSymGroups[j-i]++;
00469                     i = j - 1;
00470                 }
00471 /*
00472                 if ( pCell->nVars == 3 )
00473                 {
00474                     Extra_PrintBinary( stdout, pCell->uTruth, 32 ); printf( "\n" );
00475                     for ( i = 0; i < (int)pCell->nVars; i++ )
00476                         printf( "%d=%d/%d  ", pCell->CanonPerm[i], pCell->Store[2*i], pCell->Store[2*i+1] );
00477                     printf( "\n" );
00478                 }
00479 */
00480             }
00481 //p->timeTable += clock() - clk2;
00482         }
00483 
00484         printf( "VAR %d: Total = %d. Good = %d. Entry = %d. ", k, p->nTotal, p->nGood, sizeof(Cut_Cell_t) );
00485         PRT( "Time", clock() - clk );
00486         printf( "Cells:  " );
00487         for ( i = 0; i <= 9; i++ )
00488             printf( "%d=%d ", i, p->nVarCounts[i] );
00489         printf( "\nDiffs:  " );
00490         for ( i = 0; i <= 9; i++ )
00491             printf( "%d=%d ", i, p->nSymGroups[i] );
00492         printf( "\nEquals: " );
00493         for ( i = 0; i <= 9; i++ )
00494             printf( "%d=%d ", i, p->nSymGroupsE[i] );
00495         printf( "\n" );
00496     }
00497 //    printf( "\n" );
00498     PRT( "Supp ", p->timeSupp );
00499     PRT( "Canon", p->timeCanon );
00500     PRT( "Table", p->timeTable );
00501 //    Cut_CManStop( p );
00502 }

void Cut_CellSuppMin ( Cut_Cell_t pCell  )  [static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 549 of file cutPre22.c.

00550 {
00551     static unsigned uTemp[1<<(CUT_CELL_MVAR-5)];
00552     unsigned * pIn, * pOut, * pTemp;
00553     int i, k, Counter, Temp;
00554 
00555     // go backward through the support variables and remove redundant
00556     for ( k = pCell->nVars - 1; k >= 0; k-- )
00557         if ( !Extra_TruthVarInSupport(pCell->uTruth, pCell->nVars, k) )
00558         {
00559             // shift all the variables above this one
00560             Counter = 0;
00561             pIn = pCell->uTruth; pOut = uTemp;
00562             for ( i = k; i < (int)pCell->nVars - 1; i++ )
00563             {
00564                 Extra_TruthSwapAdjacentVars( pOut, pIn, pCell->nVars, i );
00565                 pTemp = pIn; pIn = pOut; pOut = pTemp;
00566                 // swap the support vars
00567                 Temp = pCell->CanonPerm[i]; 
00568                 pCell->CanonPerm[i] = pCell->CanonPerm[i+1];
00569                 pCell->CanonPerm[i+1] = Temp;
00570                 Counter++;
00571             }
00572             // return the function back into its place
00573             if ( Counter & 1 )
00574                 Extra_TruthCopy( pOut, pIn, pCell->nVars );
00575             // remove one variable
00576             pCell->nVars--;
00577 //            Extra_PrintBinary( stdout, pCell->uTruth, (1<<pCell->nVars) ); printf( "\n" );
00578         }
00579 }

int Cut_CellTableLookup ( Cut_CMan_t p,
Cut_Cell_t pCell 
) [static]

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

Synopsis [Check the table.]

Description [Returns 1 if such a truth table already exists.]

SideEffects []

SeeAlso []

Definition at line 515 of file cutPre22.c.

00516 {
00517     Cut_Cell_t ** pSlot, * pTemp;
00518     unsigned Hash;
00519     Hash = Extra_TruthHash( pCell->uTruth, Extra_TruthWordNum( pCell->nVars ) );
00520     if ( !st_find_or_add( p->tTable, (char *)Hash, (char ***)&pSlot ) )
00521         *pSlot = NULL;
00522     for ( pTemp = *pSlot; pTemp; pTemp = pTemp->pNext )
00523     {
00524         if ( pTemp->nVars != pCell->nVars )
00525             continue;
00526         if ( Extra_TruthIsEqual(pTemp->uTruth, pCell->uTruth, pCell->nVars) )
00527             return 1;
00528     }
00529     // the entry is new
00530     pCell->pNext = *pSlot;
00531     *pSlot = pCell;
00532     // add it to the variable support list
00533     pCell->pNextVar = p->pSameVar[pCell->nVars];
00534     p->pSameVar[pCell->nVars] = pCell;
00535     return 0;
00536 }

void Cut_CellTruthElem ( unsigned *  InA,
unsigned *  InB,
unsigned *  InC,
unsigned *  pOut,
int  nVars,
int  Type 
) [static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 634 of file cutPre22.c.

00635 {
00636     int nWords = Extra_TruthWordNum( nVars );
00637     int i;
00638 
00639     assert( Type < 22 );
00640     switch ( Type )
00641     {
00642     // " 0\n",                         // 00   const 0
00643     case 0:
00644         for ( i = 0; i < nWords; i++ )
00645             pOut[i] = 0;
00646         return;
00647     // " 1\n",                         // 01   const 1
00648     case 1:
00649         for ( i = 0; i < nWords; i++ )
00650             pOut[i] = 0xFFFFFFFF;
00651         return;
00652     // "1 1\n",                        // 02   a
00653     case 2:
00654         for ( i = 0; i < nWords; i++ )
00655             pOut[i] = InA[i];
00656         return;
00657     // "11 1\n",                       // 03   ab
00658     case 3:
00659         for ( i = 0; i < nWords; i++ )
00660             pOut[i] = InA[i] & InB[i];
00661         return;
00662     // "11 0\n",                       // 04   (ab)'
00663     case 4:
00664         for ( i = 0; i < nWords; i++ )
00665             pOut[i] = ~(InA[i] & InB[i]);
00666         return;
00667     // "10 1\n01 1\n",                 // 05   a<+>b
00668     case 5:
00669         for ( i = 0; i < nWords; i++ )
00670             pOut[i] = InA[i] ^ InB[i];
00671         return;
00672     // "111 1\n",                      // 06 + abc
00673     case 6:
00674         for ( i = 0; i < nWords; i++ )
00675             pOut[i] = InA[i] & InB[i] & InC[i];
00676         return;
00677     // "111 0\n",                      // 07   (abc)'
00678     case 7:
00679         for ( i = 0; i < nWords; i++ )
00680             pOut[i] = ~(InA[i] & InB[i] & InC[i]);
00681         return;
00682     // "11- 1\n1-1 1\n",               // 08 + a(b+c)
00683     case 8:
00684         for ( i = 0; i < nWords; i++ )
00685             pOut[i] = InA[i] & (InB[i] | InC[i]);
00686         return;
00687     // "11- 0\n1-1 0\n",               // 09   (a(b+c))'
00688     case 9:
00689         for ( i = 0; i < nWords; i++ )
00690             pOut[i] = ~(InA[i] & (InB[i] | InC[i]));
00691         return;
00692     // "111 1\n100 1\n010 1\n001 1\n", // 10 + a<+>b<+>c
00693     case 10:
00694         for ( i = 0; i < nWords; i++ )
00695             pOut[i] = InA[i] ^ InB[i] ^ InC[i];
00696         return;
00697     // "10- 0\n1-0 0\n011 0\n",        // 11 + a<+>bc
00698     case 11:
00699         for ( i = 0; i < nWords; i++ )
00700             pOut[i] = InA[i] ^ (InB[i] & InC[i]);
00701         return;
00702     // "101 1\n110 1\n",               // 12 + a(b<+>c)
00703     case 12:
00704         for ( i = 0; i < nWords; i++ )
00705             pOut[i] = InA[i] & (InB[i] ^ InC[i]);
00706         return;
00707     // "101 0\n110 0\n",               // 13   (a(b<+>c))'
00708     case 13:
00709         for ( i = 0; i < nWords; i++ )
00710             pOut[i] = ~(InA[i] & (InB[i] ^ InC[i]));
00711         return;
00712     // "11- 1\n1-1 1\n-11 1\n",        // 14 + ab+bc+ac
00713     case 14:
00714         for ( i = 0; i < nWords; i++ )
00715             pOut[i] = (InA[i] & InB[i]) | (InB[i] & InC[i]) | (InA[i] & InC[i]);
00716         return;
00717     // "111 1\n000 1\n",               // 15 + abc+a'b'c'
00718     case 15:
00719         for ( i = 0; i < nWords; i++ )
00720             pOut[i] = (InA[i] & InB[i] & InC[i]) | (~InA[i] & ~InB[i] & ~InC[i]);
00721         return;
00722     // "111 0\n000 0\n",               // 16   (abc+a'b'c')'
00723     case 16:
00724         for ( i = 0; i < nWords; i++ )
00725             pOut[i] = ~((InA[i] & InB[i] & InC[i]) | (~InA[i] & ~InB[i] & ~InC[i]));
00726         return;
00727     // "11- 1\n-11 1\n0-1 1\n",        // 17 + ab+bc+a'c
00728     case 17:
00729         for ( i = 0; i < nWords; i++ )
00730             pOut[i] = (InA[i] & InB[i]) | (InB[i] & InC[i]) | (~InA[i] & InC[i]);
00731         return;
00732     // "011 1\n101 1\n110 1\n",        // 18 + a'bc+ab'c+abc'
00733     case 18:
00734         for ( i = 0; i < nWords; i++ )
00735             pOut[i] = (~InA[i] & InB[i] & InC[i]) | (InA[i] & ~InB[i] & InC[i]) | (InA[i] & InB[i] & ~InC[i]);
00736         return;
00737     // "011 0\n101 0\n110 0\n",        // 19   (a'bc+ab'c+abc')'
00738     case 19:
00739         for ( i = 0; i < nWords; i++ )
00740             pOut[i] = ~((~InA[i] & InB[i] & InC[i]) | (InA[i] & ~InB[i] & InC[i]) | (InA[i] & InB[i] & ~InC[i]));
00741         return;
00742     // "100 1\n-11 1\n",               // 20 + ab'c'+bc
00743     case 20:
00744         for ( i = 0; i < nWords; i++ )
00745             pOut[i] = (InA[i] & ~InB[i] & ~InC[i]) | (InB[i] & InC[i]);
00746         return;
00747     // "100 0\n-11 0\n"                // 21   (ab'c'+bc)'
00748     case 21:
00749         for ( i = 0; i < nWords; i++ )
00750             pOut[i] = ~((InA[i] & ~InB[i] & ~InC[i]) | (InB[i] & InC[i]));
00751         return;
00752     }
00753 }

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 936 of file cutPre22.c.

00937 {
00938     Cut_CMan_t * p = s_pCMan;
00939     Cut_Cell_t * pTemp;
00940     Cut_Cell_t Cell, * pCell = &Cell;
00941     unsigned Hash;
00942     int i;
00943 
00944     // cell manager is not defined
00945     if ( p == NULL )
00946     {
00947         printf( "Cut_CellTruthLookup: Cell manager is not defined.\n" );
00948         return 0;
00949     }
00950 
00951     // canonicize
00952     memset( pCell, 0, sizeof(Cut_Cell_t) );
00953     pCell->nVars = nVars;
00954     Extra_TruthCopy( pCell->uTruth, pTruth, nVars );
00955     Cut_CellSuppMin( pCell );
00956     // set the elementary permutation
00957     for ( i = 0; i < (int)pCell->nVars; i++ )
00958         pCell->CanonPerm[i] = i;
00959     // canonicize
00960     pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00961 
00962 
00963     // check if the cell exists
00964     Hash = Extra_TruthHash( pCell->uTruth, Extra_TruthWordNum(pCell->nVars) );
00965     if ( st_lookup( p->tTable, (char *)Hash, (char **)&pTemp ) )
00966     {
00967         for ( ; pTemp; pTemp = pTemp->pNext )
00968         {
00969             if ( pTemp->nVars != pCell->nVars )
00970                 continue;
00971             if ( Extra_TruthIsEqual(pTemp->uTruth, pCell->uTruth, pCell->nVars) )
00972             {
00973                 pTemp->nUsed++;
00974                 p->nCellFound++;
00975                 return 1;
00976             }
00977         }
00978     }
00979     p->nCellNotFound++;
00980     return 0;
00981 }

Cut_CMan_t * Cut_CManStart (  )  [static]

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

Synopsis [Start the precomputation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 767 of file cutPre22.c.

00768 {
00769     Cut_CMan_t * p;
00770     int i, k;
00771     // start the manager
00772     assert( sizeof(unsigned) == 4 );
00773     p = ALLOC( Cut_CMan_t, 1 );
00774     memset( p, 0, sizeof(Cut_CMan_t) );
00775     // start the table and the memory manager
00776     p->tTable = st_init_table(st_ptrcmp,st_ptrhash);
00777     p->pMem = Extra_MmFixedStart( sizeof(Cut_Cell_t) );
00778     // set elementary truth tables
00779     for ( k = 0; k < CUT_CELL_MVAR; k++ )
00780         for ( i = 0; i < (1<<CUT_CELL_MVAR); i++ )
00781             if ( i & (1 << k) )
00782                 p->uInputs[k][i>>5] |= (1 << (i&31));
00783     s_pCMan = p;
00784     return p;
00785 }

void Cut_CManStop ( Cut_CMan_t p  )  [static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 798 of file cutPre22.c.

00799 {
00800     st_free_table( p->tTable );
00801     Extra_MmFixedStop( p->pMem );
00802     free( p );
00803 }


Variable Documentation

char* s_NP3[22] [static]
Initial value:
 {
    " 0\n",                          
    " 1\n",                          
    "1 1\n",                         
    "11 1\n",                        
    "11 0\n",                        
    "10 1\n01 1\n",                  
    "111 1\n",                       
    "111 0\n",                       
    "11- 1\n1-1 1\n",                
    "11- 0\n1-1 0\n",                
    "111 1\n100 1\n010 1\n001 1\n",  
    "10- 0\n1-0 0\n011 0\n",         
    "101 1\n110 1\n",                
    "101 0\n110 0\n",                
    "11- 1\n1-1 1\n-11 1\n",         
    "111 1\n000 1\n",                
    "111 0\n000 0\n",                
    "11- 1\n-11 1\n0-1 1\n",         
    "011 1\n101 1\n110 1\n",         
    "011 0\n101 0\n110 0\n",         
    "100 1\n-11 1\n",                
    "100 0\n-11 0\n"                 
}

Definition at line 77 of file cutPre22.c.

char* s_NP3Names[22] [static]
Initial value:
 {
    "   const 0            ",
    "   const 1            ",
    "   a                  ",
    "   ab                 ",
    "   (ab)'              ",
    "   a<+>b              ",
    "0s abc                ",
    "   (abc)'             ",
    "1p a(b+c)             ",
    "   (a(b+c))'          ",
    "2s a<+>b<+>c          ",
    "3p a<+>bc             ",
    "4p a(b<+>c)           ",
    "   (a(b<+>c))'        ",
    "5s ab+bc+ac           ",
    "6s abc+a'b'c'         ",
    "   (abc+a'b'c')'      ",
    "7  ab+bc+a'c          ",
    "8s a'bc+ab'c+abc'     ",
    "   (a'bc+ab'c+abc')'  ",
    "9p ab'c'+bc           ",
    "   (ab'c'+bc)'        "
}

Definition at line 103 of file cutPre22.c.

int s_NP3VarNums[22] = { 0, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } [static]

Definition at line 129 of file cutPre22.c.

int s_NPNe3[10] = { 6, 8, 10, 11, 12, 14, 15, 17, 18, 20 } [static]

Definition at line 132 of file cutPre22.c.

int s_NPNe3p[10] = { 8, 11, 12, 20 } [static]

Definition at line 138 of file cutPre22.c.

int s_NPNe3s[10] = { 6, 10, 14, 15, 18 } [static]

Definition at line 135 of file cutPre22.c.

Cut_CMan_t* s_pCMan = NULL [static]

Definition at line 149 of file cutPre22.c.


Generated on Tue Jan 5 12:19:24 2010 for abc70930 by  doxygen 1.6.1