335 int i, k, iConst, iMono, iFirst;
337 int nLargest = 0, nNonConst = 0;
343 vArray = Hsh_VecReadEntry( pHashC, iConst );
344 nLargest = Abc_MaxInt( nLargest, Abc_AbsInt(Vec_IntEntry(vArray, 0)) );
348 vSorted = Vec_WecStart( nLargest+1 );
353 vArray = Hsh_VecReadEntry( pHashC, iConst );
354 vLevel = Vec_WecEntry( vSorted, Abc_AbsInt(Vec_IntEntry(vArray, 0)) );
355 vArray = Hsh_VecReadEntry( pHashM, iMono );
356 iFirst = Vec_IntSize(vArray) ? Vec_IntEntry(vArray, 0) : -1;
357 Vec_IntPushThree( vLevel, iConst, iMono, iFirst );
360 vPolyn = Vec_WecAlloc( 2*nNonConst );
364 qsort( Vec_IntArray(vClass), (
size_t)(Vec_IntSize(vClass)/3), 12, (
int (*)(
const void *,
const void *))
Gia_PolynGetResultCompare );
367 vArray = Hsh_VecReadEntry( pHashC, iConst );
368 Vec_IntCheckUniqueOrderAbs( vArray );
369 vLevel = Vec_WecPushLevel( vPolyn );
370 Vec_IntGrow( vLevel, Vec_IntSize(vArray) );
371 Vec_IntAppend( vLevel, vArray );
373 vArray = Hsh_VecReadEntry( pHashM, iMono );
374 Vec_IntCheckUniqueOrder( vArray );
375 vLevel = Vec_WecPushLevel( vPolyn );
376 Vec_IntGrow( vLevel, Vec_IntSize(vArray) );
377 Vec_IntAppend( vLevel, vArray );
380 assert( Vec_WecSize(vPolyn) == 2*nNonConst );
381 Vec_WecFree( vSorted );
516 Vec_Wec_t * vLit2Mono = Vec_WecStart( 2 * Gia_ManObjNum(pGia) );
519 Vec_Int_t * vCoefs = Vec_IntAlloc( 1000 );
522 int i, k, iObj, iLit, iMono, nMonos = 0, nBuilds = 0;
525 Hsh_VecManAdd( pHashC, vTempC );
526 Hsh_VecManAdd( pHashM, vTempM );
527 Vec_IntPush( vCoefs, 0 );
532 int Value = 1 + Abc_MinInt( i, Vec_IntSize(vRootLits)-nExtra );
533 Vec_IntFill( vTempC, 1, (fSigned && i == Vec_IntSize(vRootLits)-1-nExtra) ? -Value : Value );
534 Vec_IntFill( vTempM, 1, iLit );
535 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC, vTempM );
542 Gia_Obj_t * pObj = Gia_ManObj( pGia, iObj );
543 int iLits[2] = { Abc_Var2Lit(iObj, 0), Abc_Var2Lit(iObj, 1) };
544 int iFans[2] = { Gia_ObjFaninLit0(pObj, iObj), Gia_ObjFaninLit1(pObj, iObj) };
546 Vec_Int_t * vArray = Vec_WecEntry( vLit2Mono, iLits[1] );
548 if ( Vec_IntEntry(vCoefs, iMono) > 0 )
550 nMonos += Gia_PolynHandleOne( pHashC, pHashM, vCoefs, vLit2Mono, vTempC, vTempM, iMono, iLits[1], -1, -1 );
551 nMonos += Gia_PolynHandleOne( pHashC, pHashM, vCoefs, vLit2Mono, vTempC, vTempM, iMono, iLits[1], iLits[0], -1 );
552 Vec_IntWriteEntry( vCoefs, iMono, 0 );
558 vArray = Vec_WecEntry( vLit2Mono, iLits[0] );
560 if ( Vec_IntEntry(vCoefs, iMono) > 0 )
562 nMonos += Gia_PolynHandleOne( pHashC, pHashM, vCoefs, vLit2Mono, vTempC, vTempM, iMono, iLits[0], iFans[0], iFans[1] );
563 Vec_IntWriteEntry( vCoefs, iMono, 0 );
573 int iLits[2] = { Abc_Var2Lit(iObj, 0), Abc_Var2Lit(iObj, 1) };
575 Vec_Int_t * vArray = Vec_WecEntry( vLit2Mono, iLits[1] );
577 if ( Vec_IntEntry(vCoefs, iMono) > 0 )
579 nMonos += Gia_PolynHandleOne( pHashC, pHashM, vCoefs, vLit2Mono, vTempC, vTempM, iMono, iLits[1], -1, -1 );
580 nMonos += Gia_PolynHandleOne( pHashC, pHashM, vCoefs, vLit2Mono, vTempC, vTempM, iMono, iLits[1], iLits[0], -1 );
581 Vec_IntWriteEntry( vCoefs, iMono, 0 );
590 printf(
"HashC = %d. HashM = %d. Total = %d. Left = %d. Used = %d. ",
591 Hsh_VecSize(pHashC), Hsh_VecSize(pHashM), nBuilds, nMonos, Vec_WecSize(vPolyn)/2 );
592 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
594 Vec_IntFree( vTempC );
595 Vec_IntFree( vTempM );
596 Vec_IntFree( vCoefs );
597 Vec_WecFree( vLit2Mono );
598 Hsh_VecManStop( pHashC );
599 Hsh_VecManStop( pHashM );
643 Vec_Wec_t * vLit2Mono = Vec_WecStart( Gia_ManObjNum(pGia) );
646 Vec_Int_t * vCoefs = Vec_IntAlloc( 1000 );
648 int i, k, iObj, iLit, iMono, iConst, nMonos = 0, nBuilds = 0;
649 for ( i = 0; i < 4; i++ )
650 vTempC[i] = Vec_IntAlloc( 10 );
651 for ( i = 0; i < 4; i++ )
652 vTempM[i] = Vec_IntAlloc( 10 );
655 Hsh_VecManAdd( pHashC, vTempC[0] );
656 Hsh_VecManAdd( pHashM, vTempM[0] );
657 Vec_IntPush( vCoefs, 0 );
660 printf(
"Assigning %d outputs from %d to %d rank %d.\n", nExtra, Vec_IntSize(vRootLits)-nExtra, Vec_IntSize(vRootLits)-1, Vec_IntSize(vRootLits)-nExtra );
669 Vec_IntClear( vTempM[0] );
670 Vec_IntFill( vTempC[0], 1, Vec_IntEntryLast(vLevel) );
674 Vec_IntPushUniqueOrder( vTempM[0], Vec_IntEntry(vLeaves, -1-Entry) );
678 OutLit = Vec_IntEntry(vRootLits, Entry);
682 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[0] );
683 else if ( !Abc_LitIsCompl(OutLit) )
685 Vec_IntPushUniqueOrder( vTempM[0], Abc_Lit2Var(OutLit) );
686 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[0] );
691 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[0] );
693 Vec_IntFill( vTempC[0], 1, -Vec_IntEntryLast(vLevel) );
694 Vec_IntPushUniqueOrder( vTempM[0], Abc_Lit2Var(OutLit) );
695 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[0] );
703 int Value = 1 + Abc_MinInt( i, Vec_IntSize(vRootLits)-nExtra );
704 Gia_PolynPrepare2( vTempC, vTempM, Abc_Lit2Var(iLit), Value );
705 if ( fSigned && i >= Vec_IntSize(vRootLits)-nExtra-1 )
707 if ( fVeryVerbose ) printf(
"Out %d : Negative Value = %d\n", i, Value-1 );
708 if ( Abc_LitIsCompl(iLit) )
710 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[1], vTempM[0] );
711 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[1] );
715 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[1], vTempM[1] );
719 if ( fVeryVerbose ) printf(
"Out %d : Positive Value = %d\n", i, Value-1 );
720 if ( Abc_LitIsCompl(iLit) )
722 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[0] );
723 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[1], vTempM[1] );
727 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[1] );
735 Gia_Obj_t * pObj = Gia_ManObj( pGia, iObj );
736 Vec_Int_t * vArray = Vec_WecEntry( vLit2Mono, iObj );
738 if ( (iConst = Vec_IntEntry(vCoefs, iMono)) > 0 )
740 Vec_Int_t * vArrayC = Hsh_VecReadEntry( pHashC, iConst );
741 Vec_Int_t * vArrayM = Hsh_VecReadEntry( pHashM, iMono );
742 Gia_PolynPrepare4( vTempC, vTempM, vArrayC, vArrayM, iObj, Gia_ObjFaninId0(pObj, iObj), Gia_ObjFaninId1(pObj, iObj) );
743 if ( Gia_ObjIsXor(pObj) )
746 else if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
748 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[0] );
749 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[1], vTempM[1] );
750 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[3], vTempM[2] );
751 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[2], vTempM[3] );
754 else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
756 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[2] );
757 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[1], vTempM[3] );
760 else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
762 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[1] );
763 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[1], vTempM[3] );
767 nMonos += Gia_PolynBuildAdd( pHashC, pHashM, vCoefs, vLit2Mono, vTempC[0], vTempM[3] );
768 Vec_IntWriteEntry( vCoefs, iMono, 0 );
778 printf(
"HashC = %d. HashM = %d. Total = %d. Left = %d. Used = %d. ",
779 Hsh_VecSize(pHashC), Hsh_VecSize(pHashM), nBuilds, nMonos, Vec_WecSize(vPolyn)/2 );
780 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
782 for ( i = 0; i < 4; i++ )
783 Vec_IntFree( vTempC[i] );
784 for ( i = 0; i < 4; i++ )
785 Vec_IntFree( vTempM[i] );
786 Vec_IntFree( vCoefs );
787 Vec_WecFree( vLit2Mono );
788 Hsh_VecManStop( pHashC );
789 Hsh_VecManStop( pHashM );