summaryrefslogtreecommitdiffstats
path: root/src/opt/cut/cutSeq.c
blob: 3f671d2489b01a7e2ada64070e30d50aa3137c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/**CFile****************************************************************

  FileName    [cutSeq.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [K-feasible cut computation package.]

  Synopsis    [Sequential cut computation.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: cutSeq.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "cutInt.h"

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Shifts all cut leaves of the node by the given number of latches.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Cut_NodeShiftCutLeaves( Cut_Cut_t * pList, int nLat )
{
    Cut_Cut_t * pTemp;
    int i;
    // shift the cuts by as many latches
    Cut_ListForEachCut( pList, pTemp )
    {
        pTemp->uSign = 0;
        for ( i = 0; i < (int)pTemp->nLeaves; i++ )
        {
            pTemp->pLeaves[i] += nLat;
            pTemp->uSign      |= Cut_NodeSign( pTemp->pLeaves[i] );
        }
    }
}

/**Function*************************************************************

  Synopsis    [Computes sequential cuts for the node from its fanins.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_NodeComputeCutsSeq( Cut_Man_t * p, int Node, int Node0, int Node1, int fCompl0, int fCompl1, int nLat0, int nLat1, int fTriv, int CutSetNum )
{
    Cut_List_t Super, * pSuper = &Super;
    Cut_Cut_t * pListNew;
    int clk;
    
    // get the number of cuts at the node
    p->nNodeCuts = Cut_CutCountList( Cut_NodeReadCutsOld(p, Node) );
    if ( p->nNodeCuts >= p->pParams->nKeepMax )
        return;

    // count only the first visit
    if ( p->nNodeCuts == 0 )
        p->nNodes++;

    // store the fanin lists
    p->pStore0[0] = Cut_NodeReadCutsOld( p, Node0 );
    p->pStore0[1] = Cut_NodeReadCutsNew( p, Node0 );
    p->pStore1[0] = Cut_NodeReadCutsOld( p, Node1 );
    p->pStore1[1] = Cut_NodeReadCutsNew( p, Node1 );

    // duplicate the cut lists if fanin nodes are non-standard
    if ( Node == Node0 || Node == Node1 || Node0 == Node1 )
    {
        p->pStore0[0] = Cut_CutDupList( p, p->pStore0[0] );
        p->pStore0[1] = Cut_CutDupList( p, p->pStore0[1] );
        p->pStore1[0] = Cut_CutDupList( p, p->pStore1[0] );
        p->pStore1[1] = Cut_CutDupList( p, p->pStore1[1] );
    }

    // shift the cuts by as many latches and recompute signatures
    if ( nLat0 ) Cut_NodeShiftCutLeaves( p->pStore0[0], nLat0 );
    if ( nLat0 ) Cut_NodeShiftCutLeaves( p->pStore0[1], nLat0 );
    if ( nLat1 ) Cut_NodeShiftCutLeaves( p->pStore1[0], nLat1 );
    if ( nLat1 ) Cut_NodeShiftCutLeaves( p->pStore1[1], nLat1 );

    // store the original lists for comparison
    p->pCompareOld = Cut_NodeReadCutsOld( p, Node );
    p->pCompareNew = Cut_NodeReadCutsNew( p, Node );

    // merge the old and the new
clk = clock();
    Cut_ListStart( pSuper );
    Cut_NodeDoComputeCuts( p, pSuper, Node, fCompl0, fCompl1, p->pStore0[0], p->pStore1[1], 0, 0 );
    Cut_NodeDoComputeCuts( p, pSuper, Node, fCompl0, fCompl1, p->pStore0[1], p->pStore1[0], 0, 0 );
    Cut_NodeDoComputeCuts( p, pSuper, Node, fCompl0, fCompl1, p->pStore0[1], p->pStore1[1], fTriv, 0 );
    pListNew = Cut_ListFinish( pSuper );
p->timeMerge += clock() - clk;

    // shift the cuts by as many latches and recompute signatures
    if ( Node == Node0 || Node == Node1 || Node0 == Node1 )
    {
        Cut_CutRecycleList( p, p->pStore0[0] );
        Cut_CutRecycleList( p, p->pStore0[1] );
        Cut_CutRecycleList( p, p->pStore1[0] );
        Cut_CutRecycleList( p, p->pStore1[1] );
    }
    else
    {
        if ( nLat0 ) Cut_NodeShiftCutLeaves( p->pStore0[0], -nLat0 );
        if ( nLat0 ) Cut_NodeShiftCutLeaves( p->pStore0[1], -nLat0 );
        if ( nLat1 ) Cut_NodeShiftCutLeaves( p->pStore1[0], -nLat1 );
        if ( nLat1 ) Cut_NodeShiftCutLeaves( p->pStore1[1], -nLat1 );
    }

    // set the lists at the node
    if ( CutSetNum >= 0 )
    {
        assert( Cut_NodeReadCutsTemp(p, CutSetNum) == NULL );
        Cut_NodeWriteCutsTemp( p, CutSetNum, pListNew );
    }
    else
    {
        assert( Cut_NodeReadCutsNew(p, Node) == NULL );
        Cut_NodeWriteCutsNew( p, Node, pListNew );
    }

    // mark the node if we exceeded the number of cuts
    if ( p->nNodeCuts >= p->pParams->nKeepMax )
        p->nCutsLimit++;
}

/**Function*************************************************************

  Synopsis    [Merges the new cuts with the old cuts.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_NodeNewMergeWithOld( Cut_Man_t * p, int Node )
{
    Cut_Cut_t * pListOld, * pListNew, * pList;
    // get the new cuts
    pListNew = Cut_NodeReadCutsNew( p, Node );
    if ( pListNew == NULL )
        return;
    Cut_NodeWriteCutsNew( p, Node, NULL );
    // get the old cuts
    pListOld = Cut_NodeReadCutsOld( p, Node );
    if ( pListOld == NULL )
    {
        Cut_NodeWriteCutsOld( p, Node, pListNew );
        return;
    }
    // merge the lists
    pList = Cut_CutMergeLists( pListOld, pListNew );
    Cut_NodeWriteCutsOld( p, Node, pList );
}


/**Function*************************************************************

  Synopsis    [Transfers the temporary cuts to be the new cuts.]

  Description [Returns 1 if something was transferred.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Cut_NodeTempTransferToNew( Cut_Man_t * p, int Node, int CutSetNum )
{
    Cut_Cut_t * pList;
    pList = Cut_NodeReadCutsTemp( p, CutSetNum );
    Cut_NodeWriteCutsTemp( p, CutSetNum, NULL );
    Cut_NodeWriteCutsNew( p, Node, pList );
    return pList != NULL;
}

/**Function*************************************************************

  Synopsis    [Transfers the old cuts to be the new cuts.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_NodeOldTransferToNew( Cut_Man_t * p, int Node )
{
    Cut_Cut_t * pList;
    pList = Cut_NodeReadCutsOld( p, Node );
    Cut_NodeWriteCutsOld( p, Node, NULL );
    Cut_NodeWriteCutsNew( p, Node, pList );
//    Cut_CutListVerify( pList );
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END