@@ -982,6 +982,106 @@ Gia_Man_t * Gia_AigerReadFromMemory( char * pContents, int nFileSize, int fGiaSi
982982 pNew -> pAigExtra = pAigExtra ;
983983 }
984984
985+ // Apply init state transformation for register boxes with init=1
986+ if ( pNew -> vRegInits && Vec_IntCountEntry (pNew -> vRegInits , 1 ) > 0 )
987+ {
988+ extern void Gia_ManFlipInit1 ( Gia_Man_t * p , Vec_Int_t * vInit );
989+ Tim_Man_t * pTimMan = (Tim_Man_t * )pNew -> pManTime ;
990+
991+ if ( pTimMan && Gia_ManRegBoxNum (pNew ) > 0 )
992+ {
993+ // Handle register boxes: apply transformation to box inputs/outputs
994+ Gia_Obj_t * pObj ;
995+ int i , curCo , curCi , nBoxIns , nBoxOuts ;
996+ int iRegBox = 0 ;
997+
998+ assert ( Vec_IntSize (pNew -> vRegInits ) == Gia_ManRegBoxNum (pNew ) );
999+
1000+ // Step 1: Mark register box outputs with init state 1
1001+ curCi = Tim_ManPiNum (pTimMan );
1002+ for ( i = 0 ; i < Gia_ManBoxNum (pNew ); i ++ )
1003+ {
1004+ nBoxIns = Tim_ManBoxInputNum (pTimMan , i );
1005+ nBoxOuts = Tim_ManBoxOutputNum (pTimMan , i );
1006+ // Check if this is a register box (1-input, 1-output)
1007+ if ( nBoxIns == 1 && nBoxOuts == 1 )
1008+ {
1009+ if ( Vec_IntEntry (pNew -> vRegInits , iRegBox ) == 1 )
1010+ {
1011+ pObj = Gia_ManCi (pNew , curCi );
1012+ pObj -> fMark0 = 1 ;
1013+ }
1014+ iRegBox ++ ;
1015+ }
1016+ curCi += nBoxOuts ;
1017+ }
1018+
1019+ // Step 2: Propagate complementation through AND gates
1020+ Gia_ManForEachAnd ( pNew , pObj , i )
1021+ {
1022+ if ( Gia_ObjFanin0 (pObj )-> fMark0 )
1023+ pObj -> fCompl0 ^= 1 ;
1024+ if ( Gia_ObjFanin1 (pObj )-> fMark0 )
1025+ pObj -> fCompl1 ^= 1 ;
1026+ }
1027+
1028+ // Step 3: Complement CO fanins if needed
1029+ Gia_ManForEachCo ( pNew , pObj , i )
1030+ {
1031+ if ( Gia_ObjFanin0 (pObj )-> fMark0 )
1032+ pObj -> fCompl0 ^= 1 ;
1033+ }
1034+
1035+ // Step 4: Clear marks
1036+ curCi = Tim_ManPiNum (pTimMan );
1037+ iRegBox = 0 ;
1038+ for ( i = 0 ; i < Gia_ManBoxNum (pNew ); i ++ )
1039+ {
1040+ nBoxIns = Tim_ManBoxInputNum (pTimMan , i );
1041+ nBoxOuts = Tim_ManBoxOutputNum (pTimMan , i );
1042+ if ( nBoxIns == 1 && nBoxOuts == 1 )
1043+ {
1044+ if ( Vec_IntEntry (pNew -> vRegInits , iRegBox ) == 1 )
1045+ {
1046+ pObj = Gia_ManCi (pNew , curCi );
1047+ pObj -> fMark0 = 0 ;
1048+ }
1049+ iRegBox ++ ;
1050+ }
1051+ curCi += nBoxOuts ;
1052+ }
1053+
1054+ // Step 5: Complement register box inputs with init state 1
1055+ curCo = Tim_ManPoNum (pTimMan );
1056+ iRegBox = 0 ;
1057+ for ( i = 0 ; i < Gia_ManBoxNum (pNew ); i ++ )
1058+ {
1059+ nBoxIns = Tim_ManBoxInputNum (pTimMan , i );
1060+ nBoxOuts = Tim_ManBoxOutputNum (pTimMan , i );
1061+ if ( nBoxIns == 1 && nBoxOuts == 1 )
1062+ {
1063+ if ( Vec_IntEntry (pNew -> vRegInits , iRegBox ) == 1 )
1064+ {
1065+ pObj = Gia_ManCo (pNew , curCo );
1066+ pObj -> fCompl0 ^= 1 ;
1067+ }
1068+ iRegBox ++ ;
1069+ }
1070+ curCo += nBoxIns ;
1071+ }
1072+
1073+ // Clear all init states to 0 (transformation is now structural)
1074+ Vec_IntFill ( pNew -> vRegInits , Vec_IntSize (pNew -> vRegInits ), 0 );
1075+ }
1076+ else if ( Gia_ManRegNum (pNew ) > 0 )
1077+ {
1078+ // Handle regular flops (no boxes)
1079+ Gia_ManFlipInit1 ( pNew , pNew -> vRegInits );
1080+ // Clear all init states to 0 (transformation is now structural)
1081+ Vec_IntFill ( pNew -> vRegInits , Vec_IntSize (pNew -> vRegInits ), 0 );
1082+ }
1083+ }
1084+
9851085 if ( fHieOnly )
9861086 {
9871087// Tim_ManPrint( (Tim_Man_t *)pNew->pManTime );
0 commit comments