ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mpmDsd.c File Reference
#include "mpmInt.h"
#include "misc/extra/extra.h"
Include dependency graph for mpmDsd.c:

Go to the source code of this file.

Functions

Vec_Wrd_tMpm_ManGetTruthWithCnf (int Limit)
 FUNCTION DEFINITIONS ///.
 
void Mpm_ManPrintDsdStats (Mpm_Man_t *p)
 
Hsh_IntMan_tMpm_ManBuildHashTable (Vec_Int_t **pvConfgRes)
 
void Mpm_ManPrintPerm (unsigned s)
 
void Mpm_ManPrecomputePerms (Mpm_Man_t *p)
 
word Mpm_CutTruthFromDsd (Mpm_Man_t *pMan, Mpm_Cut_t *pCut, int iClass)
 
int Mpm_CutCheckDsd6 (Mpm_Man_t *p, word t)
 
int Mpm_CutComputeDsd6 (Mpm_Man_t *p, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, Mpm_Cut_t *pCut1, Mpm_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, int Type)
 

Function Documentation

◆ Mpm_CutCheckDsd6()

int Mpm_CutCheckDsd6 ( Mpm_Man_t * p,
word t )

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

Synopsis [Checks hash table for DSD class.]

Description []

SideEffects []

SeeAlso []

Definition at line 905 of file mpmDsd.c.

906{
907 int fCompl, Entry, Config;
908 if ( (fCompl = (t & 1)) )
909 t = ~t;
910 Entry = *Hsh_IntManLookup( p->pHash, (unsigned *)&t );
911 if ( Entry == -1 )
912 return -1;
913 Config = Vec_IntEntry( p->vConfgRes, Entry );
914 if ( fCompl )
915 Config ^= (1 << 16);
916 return Config;
917}
Cube * p
Definition exorList.c:222
Here is the caller graph for this function:

◆ Mpm_CutComputeDsd6()

int Mpm_CutComputeDsd6 ( Mpm_Man_t * p,
Mpm_Cut_t * pCut,
Mpm_Cut_t * pCut0,
Mpm_Cut_t * pCut1,
Mpm_Cut_t * pCutC,
int fCompl0,
int fCompl1,
int fComplC,
int Type )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 930 of file mpmDsd.c.

931{
932 int fVerbose = 0;
933 int i, Config, iClass, fCompl;
934 int pLeavesNew[6] = { -1, -1, -1, -1, -1, -1 };
935 word t = 0;
936 if ( pCutC == NULL )
937 {
938 word t0, t1;
939 int iClass0 = Abc_Lit2Var(pCut0->iFunc);
940 int iClass1 = Abc_Lit2Var(pCut1->iFunc);
941 word Truth0 = p->pDsd6[iClass0].uTruth;
942 int Perm1 = Vec_IntEntry( p->vMap2Perm, p->uPermMask[1] );
943 word Truth1p = Vec_WrdEntry( p->vPerm6, iClass1 * 720 + Perm1 );
944 if ( p->uComplMask[1] )
945 {
946 for ( i = 0; i < 6; i++ )
947 if ( (p->uComplMask[1] >> i) & 1 )
948 Truth1p = Abc_Tt6Flip( Truth1p, i );
949 }
950 t0 = (fCompl0 ^ pCut0->fCompl ^ Abc_LitIsCompl(pCut0->iFunc)) ? ~Truth0 : Truth0;
951 t1 = (fCompl1 ^ pCut1->fCompl ^ Abc_LitIsCompl(pCut1->iFunc)) ? ~Truth1p : Truth1p;
952 if ( Type == 1 )
953 t = t0 & t1;
954 else if ( Type == 2 )
955 t = t0 ^ t1;
956 else assert( 0 );
957
958if ( fVerbose )
959{
960Mpm_ManPrintPerm( p->uPermMask[1] ); printf( "\n" );
961Kit_DsdPrintFromTruth( (unsigned *)&Truth0, 6 ); printf( "\n" );
962Kit_DsdPrintFromTruth( (unsigned *)&Truth1p, 6 ); printf( "\n" );
963Kit_DsdPrintFromTruth( (unsigned *)&t, 6 ); printf( "\n" );
964}
965 }
966 else
967 {
968 word t0, t1, tC;
969 int iClass0 = Abc_Lit2Var(pCut0->iFunc);
970 int iClass1 = Abc_Lit2Var(pCut1->iFunc);
971 int iClassC = Abc_Lit2Var(pCutC->iFunc);
972 word Truth0 = p->pDsd6[iClass0].uTruth;
973 int Perm1 = Vec_IntEntry( p->vMap2Perm, p->uPermMask[1] );
974 int PermC = Vec_IntEntry( p->vMap2Perm, p->uPermMask[2] );
975 word Truth1p = Vec_WrdEntry( p->vPerm6, iClass1 * 720 + Perm1 );
976 word TruthCp = Vec_WrdEntry( p->vPerm6, iClassC * 720 + PermC );
977 if ( p->uComplMask[1] )
978 {
979 for ( i = 0; i < 6; i++ )
980 if ( (p->uComplMask[1] >> i) & 1 )
981 Truth1p = Abc_Tt6Flip( Truth1p, i );
982 }
983 if ( p->uComplMask[2] )
984 {
985 for ( i = 0; i < 6; i++ )
986 if ( (p->uComplMask[2] >> i) & 1 )
987 TruthCp = Abc_Tt6Flip( TruthCp, i );
988 }
989 t0 = (fCompl0 ^ pCut0->fCompl ^ Abc_LitIsCompl(pCut0->iFunc)) ? ~Truth0 : Truth0;
990 t1 = (fCompl1 ^ pCut1->fCompl ^ Abc_LitIsCompl(pCut1->iFunc)) ? ~Truth1p : Truth1p;
991 tC = (fComplC ^ pCutC->fCompl ^ Abc_LitIsCompl(pCutC->iFunc)) ? ~TruthCp : TruthCp;
992 t = (tC & t1) | (~tC & t0);
993 }
994
995 // find configuration
996 Config = Mpm_CutCheckDsd6( p, t );
997 if ( Config == -1 )
998 {
999 p->nNonDsd++;
1000 return 0;
1001 }
1002
1003 // get the class
1004 iClass = Config >> 17;
1005 fCompl = (Config >> 16) & 1;
1006 Config &= 0xFFFF;
1007
1008 // check if the gate exists
1009 if ( p->pPars->fMap4Gates )
1010 {
1011 if ( Vec_IntSize(Vec_WecEntry(p->vNpnConfigs, iClass)) == 0 )
1012 {
1013 p->nNoMatch++;
1014 return 0;
1015 }
1016 }
1017
1018 // set the function
1019 pCut->iFunc = Abc_Var2Lit( iClass, fCompl );
1020
1021if ( fVerbose )
1022{
1023Mpm_CutPrint( pCut0 );
1024Mpm_CutPrint( pCut1 );
1025Mpm_CutPrint( pCut );
1026}
1027
1028 // update cut
1029 assert( (Config >> 6) < 720 );
1030 for ( i = 0; i < (int)pCut->nLeaves; i++ )
1031 pLeavesNew[(int)(p->Perm6[Config >> 6][i])] = Abc_LitNotCond( pCut->pLeaves[i], (Config >> i) & 1 );
1032 pCut->nLeaves = p->pDsd6[iClass].nVars;
1033 for ( i = 0; i < (int)pCut->nLeaves; i++ )
1034 assert( pLeavesNew[i] != -1 );
1035 for ( i = 0; i < (int)pCut->nLeaves; i++ )
1036 pCut->pLeaves[i] = pLeavesNew[i];
1037 p->nCountDsd[iClass]++;
1038 p->nSmallSupp += (int)(pCut->nLeaves < 2);
1039
1040if ( fVerbose )
1041{
1042printf( "Computed " );
1043Mpm_CutPrint( pCut );
1044printf( "\n" );
1045}
1046 return 1;
1047}
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition kitDsd.c:491
int Mpm_CutCheckDsd6(Mpm_Man_t *p, word t)
Definition mpmDsd.c:905
void Mpm_ManPrintPerm(unsigned s)
Definition mpmDsd.c:736
void Mpm_CutPrint(Mpm_Cut_t *pCut)
Definition mpmMap.c:103
unsigned fCompl
Definition mpmInt.h:66
unsigned nLeaves
Definition mpmInt.h:68
int pLeaves[1]
Definition mpmInt.h:69
unsigned iFunc
Definition mpmInt.h:65
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:

◆ Mpm_CutTruthFromDsd()

word Mpm_CutTruthFromDsd ( Mpm_Man_t * pMan,
Mpm_Cut_t * pCut,
int iClass )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 883 of file mpmDsd.c.

884{
885 int i;
886 word uTruth = pMan->pDsd6[iClass].uTruth;
887 assert( pMan->pDsd6[iClass].nVars == (int)pCut->nLeaves );
888 for ( i = 0; i < (int)pCut->nLeaves; i++ )
889 if ( Abc_LitIsCompl(pCut->pLeaves[i]) )
890 uTruth = Abc_Tt6Flip( uTruth, i );
891 return uTruth;
892}
word uTruth
Definition mpmInt.h:90
int nVars
Definition mpmInt.h:87
Mpm_Dsd_t * pDsd6
Definition mpmInt.h:132
Here is the caller graph for this function:

◆ Mpm_ManBuildHashTable()

Hsh_IntMan_t * Mpm_ManBuildHashTable ( Vec_Int_t ** pvConfgRes)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 699 of file mpmDsd.c.

700{
701 FILE * pFile;
702 char * pFileName = "dsdfuncs6.dat";
703 int RetValue, size = Extra_FileSize( pFileName ) / 12; // 2866420
704 Vec_Wrd_t * vTruthRes = Vec_WrdAlloc( size );
705 Vec_Int_t * vConfgRes = Vec_IntAlloc( size );
706 Hsh_IntMan_t * pHash;
707
708 pFile = fopen( pFileName, "rb" );
709 RetValue = fread( Vec_WrdArray(vTruthRes), sizeof(word), size, pFile );
710 RetValue = fread( Vec_IntArray(vConfgRes), sizeof(int), size, pFile );
711 vTruthRes->nSize = size;
712 vConfgRes->nSize = size;
713 // create hash table
714 pHash = Hsh_WrdManHashArrayStart( vTruthRes, 1 );
715 // cleanup
716 if ( pvConfgRes )
717 *pvConfgRes = vConfgRes;
718 else
719 Vec_IntFree( vConfgRes );
720 Vec_WrdFree( vTruthRes );
721// Hsh_IntManStop( pHash );
722 return pHash;
723}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
int Extra_FileSize(char *pFileName)
unsigned long long size
Definition giaNewBdd.h:39
struct Hsh_IntMan_t_ Hsh_IntMan_t
Definition vecHsh.h:66
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mpm_ManGetTruthWithCnf()

Vec_Wrd_t * Mpm_ManGetTruthWithCnf ( int Limit)

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 644 of file mpmDsd.c.

645{
646 Vec_Wrd_t * vRes = Vec_WrdAlloc( 1000 );
647 int i;
648 for ( i = 0; i < 595; i++ )
649 if ( s_DsdClass6[i].nClauses <= Limit )
650 Vec_WrdPush( vRes, s_DsdClass6[i].uTruth );
651 return vRes;
652}
Here is the caller graph for this function:

◆ Mpm_ManPrecomputePerms()

void Mpm_ManPrecomputePerms ( Mpm_Man_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 755 of file mpmDsd.c.

756{
757 int nVars = 6;
758 // 0(1:1) 1(2:1) 2(4:2) 3(10:6) 4(33:23) 5(131:98) 6(595:464)
759 int nClasses[7] = { 1, 2, 4, 10, 33, 131, 595 };
760 int nPerms = Extra_Factorial( nVars );
761// int nSwaps = (1 << nVars);
762 int * pComp, * pPerm;
763 int i, k, x, One, OneCopy, Num;
764 Vec_Int_t * vVars;
765 abctime clk = Abc_Clock();
766 assert( p->pDsd6 == NULL );
767 p->pDsd6 = s_DsdClass6;
768 // precompute schedules
769 pComp = Extra_GreyCodeSchedule( nVars );
770 pPerm = Extra_PermSchedule( nVars );
771 // map numbers into perms
772 p->vMap2Perm = Vec_IntStartFull( (1<<(3*nVars)) );
773 // store permutations
774 One = 0;
775 for ( x = 0; x < nVars; x++ )
776 {
777 p->Perm6[0][x] = (char)x;
778 One |= (x << (3*x));
779 }
780// Vec_IntWriteEntry( p->vMap2Perm, One, 0 );
781 OneCopy = One;
782 for ( k = 0; k < nPerms; k++ )
783 {
784 if ( k > 0 )
785 for ( x = 0; x < nVars; x++ )
786 p->Perm6[k][x] = p->Perm6[k-1][x];
787 ABC_SWAP( char, p->Perm6[k][pPerm[k]], p->Perm6[k][pPerm[k]+1] );
788
789 Num = ( (One >> (3*(pPerm[k] ))) ^ (One >> (3*(pPerm[k]+1))) ) & 7;
790 One ^= (Num << (3*(pPerm[k] )));
791 One ^= (Num << (3*(pPerm[k]+1)));
792
793 Vec_IntWriteEntry( p->vMap2Perm, One, k );
794
795// Mpm_ManPrintPerm( One );
796// for ( x = 0; x < nVars; x++ )
797// printf( "%d ", p->Perm6[k][x] );
798// printf( "\n" );
799 }
800 assert( OneCopy == One );
801 // fill in the gaps
802 vVars = Vec_IntAlloc( 6 );
803 Vec_IntForEachEntry( p->vMap2Perm, Num, i )
804 {
805 // mark used variables
806 int Count = 0;
807 One = i;
808 Vec_IntFill( vVars, 6, 0 );
809 for ( k = 0; k < nVars; k++ )
810 {
811 int iVar = ((One >> (3*k)) & 7);
812 if ( iVar >= nVars && iVar < 7 )
813 break;
814 if ( iVar != 7 )
815 {
816 if ( Vec_IntEntry( vVars, iVar ) == 1 )
817 break;
818 Vec_IntWriteEntry( vVars, iVar, 1 );
819 Count++;
820 }
821 }
822 // skip ones with dups and complete
823 if ( k < nVars || Count == nVars )
824 continue;
825 // find unused variables
826 for ( x = k = 0; k < 6; k++ )
827 if ( Vec_IntEntry(vVars, k) == 0 )
828 Vec_IntWriteEntry( vVars, x++, k );
829 Vec_IntShrink( vVars, x );
830 // fill in used variables
831 x = 0;
832 for ( k = 0; k < nVars; k++ )
833 {
834 int iVar = ((One >> (3*k)) & 7);
835 if ( iVar == 7 )
836 One ^= ((Vec_IntEntry(vVars, x++) ^ 7) << (3*k));
837 }
838 assert( x == Vec_IntSize(vVars) );
839 // save this one
840 assert( Vec_IntEntry( p->vMap2Perm, One ) != -1 );
841 Vec_IntWriteEntry( p->vMap2Perm, i, Vec_IntEntry(p->vMap2Perm, One) );
842/*
843 // mapping
844 Mpm_ManPrintPerm( i );
845 printf( "-> " );
846 Mpm_ManPrintPerm( One );
847 printf( "\n" );
848*/
849 }
850 Vec_IntFree( vVars );
851
852 // store permuted truth tables
853 assert( p->vPerm6 == NULL );
854 p->vPerm6 = Vec_WrdAlloc( nPerms * 595 );
855 for ( i = 0; i < nClasses[nVars]; i++ )
856 {
857 word uTruth = s_DsdClass6[i].uTruth;
858 for ( k = 0; k < nPerms; k++ )
859 {
860 uTruth = Abc_Tt6SwapAdjacent( uTruth, pPerm[k] );
861 Vec_WrdPush( p->vPerm6, uTruth );
862 }
863 assert( uTruth == s_DsdClass6[i].uTruth );
864 }
865 ABC_FREE( pPerm );
866 ABC_FREE( pComp );
867 // build hash table
868 p->pHash = Mpm_ManBuildHashTable( &p->vConfgRes );
869 Abc_PrintTime( 1, "Setting up DSD information", Abc_Clock() - clk );
870}
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_FREE(obj)
Definition abc_global.h:267
int * Extra_PermSchedule(int n)
int Extra_Factorial(int n)
int * Extra_GreyCodeSchedule(int n)
Hsh_IntMan_t * Mpm_ManBuildHashTable(Vec_Int_t **pvConfgRes)
Definition mpmDsd.c:699
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mpm_ManPrintDsdStats()

void Mpm_ManPrintDsdStats ( Mpm_Man_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 665 of file mpmDsd.c.

666{
667 int i, Absent = 0;
668 for ( i = 0; i < 595; i++ )
669 {
670 if ( p->nCountDsd[i] == 0 )
671 {
672 Absent++;
673 continue;
674 }
675 if ( p->pPars->fVeryVerbose )
676 {
677 printf( "%5d : ", i );
678 printf( "%-20s ", p->pDsd6[i].pStr );
679 printf( "%8d ", p->nCountDsd[i] );
680 printf( "\n" );
681 }
682 }
683 printf( "Unused classes = %d (%.2f %%). ", Absent, 100.0 * Absent / 595 );
684 printf( "Non-DSD cuts = %d (%.2f %%). ", p->nNonDsd, 100.0 * p->nNonDsd / p->nCutsMergedAll );
685 printf( "No-match cuts = %d (%.2f %%).\n", p->nNoMatch, 100.0 * p->nNoMatch / p->nCutsMergedAll );
686}
Here is the caller graph for this function:

◆ Mpm_ManPrintPerm()

void Mpm_ManPrintPerm ( unsigned s)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 736 of file mpmDsd.c.

737{
738 int i;
739 for ( i = 0; i < 6; i++ )
740 printf( "%d ", (s >> (3*i)) & 7 );
741 printf( " " );
742}
Here is the caller graph for this function: