summaryrefslogtreecommitdiffstats
path: root/src/proof/acec/acecBo.c
blob: 9cddcd132641cc8a25d0b5564e71f603a3d5845f (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
/**CFile****************************************************************

  FileName    [acecBo.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [CEC for arithmetic circuits.]

  Synopsis    [Core procedures.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "acecInt.h"
#include "misc/vec/vecWec.h"
#include "misc/extra/extra.h"

ABC_NAMESPACE_IMPL_START

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


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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Acec_DetectBoothXorMux( Gia_Man_t * p, Gia_Obj_t * pMux, Gia_Obj_t * pXor, int pIns[3] )
{
    Gia_Obj_t * pFan0, * pFan1;
    Gia_Obj_t * pDat0, * pDat1, * pCtrl;
    if ( !Gia_ObjIsMuxType(pMux) || !Gia_ObjIsMuxType(pXor) )
        return 0;
    if ( !Gia_ObjRecognizeExor( pXor, &pFan0, &pFan1 ) )
        return 0;
    pFan0 = Gia_Regular(pFan0);
    pFan1 = Gia_Regular(pFan1);
    if ( Gia_ObjId(p, pFan0) > Gia_ObjId(p, pFan1) )
        ABC_SWAP( Gia_Obj_t *, pFan0, pFan1 );
    if ( !(pCtrl = Gia_ObjRecognizeMux( pMux, &pDat0, &pDat1 )) )
        return 0;
    pDat0 = Gia_Regular(pDat0);
    pDat1 = Gia_Regular(pDat1);
    pCtrl = Gia_Regular(pCtrl);
    if ( !Gia_ObjIsAnd(pDat0) || !Gia_ObjIsAnd(pDat1) )
        return 0;
    if ( Gia_ObjFaninId0p(p, pDat0) != Gia_ObjFaninId0p(p, pDat1) ||
         Gia_ObjFaninId1p(p, pDat0) != Gia_ObjFaninId1p(p, pDat1) )
         return 0;
    if ( Gia_ObjFaninId0p(p, pDat0) != Gia_ObjId(p, pFan0) ||
         Gia_ObjFaninId1p(p, pDat0) != Gia_ObjId(p, pFan1) )
         return 0;
    pIns[0] = Gia_ObjId(p, pFan0);
    pIns[1] = Gia_ObjId(p, pFan1);
    pIns[2] = Gia_ObjId(p, pCtrl);
    return 1;
}
int Acec_DetectBoothXorFanin( Gia_Man_t * p, Gia_Obj_t * pObj, int pIns[5] )
{
    Gia_Obj_t * pFan0, * pFan1;
    //int Id = Gia_ObjId(p, pObj);
    if ( !Gia_ObjIsAnd(pObj) )
        return 0;
    if ( !Gia_ObjFaninC0(pObj) || !Gia_ObjFaninC1(pObj) )
        return 0;
    pFan0 = Gia_ObjFanin0(pObj);
    pFan1 = Gia_ObjFanin1(pObj);
    if ( !Gia_ObjIsAnd(pFan0) || !Gia_ObjIsAnd(pFan1) )
        return 0;
    if ( Acec_DetectBoothXorMux(p, Gia_ObjFanin0(pFan0), Gia_ObjFanin0(pFan1), pIns) )
    {
        pIns[3] = Gia_ObjId(p, Gia_ObjFanin1(pFan0));
        pIns[4] = Gia_ObjId(p, Gia_ObjFanin1(pFan1));
        return 1;
    }
    if ( Acec_DetectBoothXorMux(p, Gia_ObjFanin0(pFan0), Gia_ObjFanin1(pFan1), pIns) )
    {
        pIns[3] = Gia_ObjId(p, Gia_ObjFanin1(pFan0));
        pIns[4] = Gia_ObjId(p, Gia_ObjFanin0(pFan1));
        return 1;
    }
    if ( Acec_DetectBoothXorMux(p, Gia_ObjFanin1(pFan0), Gia_ObjFanin0(pFan1), pIns) )
    {
        pIns[3] = Gia_ObjId(p, Gia_ObjFanin0(pFan0));
        pIns[4] = Gia_ObjId(p, Gia_ObjFanin1(pFan1));
        return 1;
    }
    if ( Acec_DetectBoothXorMux(p, Gia_ObjFanin1(pFan0), Gia_ObjFanin1(pFan1), pIns) )
    {
        pIns[3] = Gia_ObjId(p, Gia_ObjFanin0(pFan0));
        pIns[4] = Gia_ObjId(p, Gia_ObjFanin0(pFan1));
        return 1;
    }
    return 0;
}
int Acec_DetectBoothOne( Gia_Man_t * p, Gia_Obj_t * pObj, int pIns[5] )
{
    Gia_Obj_t * pFan0, * pFan1;
    if ( !Gia_ObjRecognizeExor( pObj, &pFan0, &pFan1 ) )
        return 0;
    pFan0 = Gia_Regular(pFan0);
    pFan1 = Gia_Regular(pFan1);
    if ( Acec_DetectBoothXorFanin( p, pFan0, pIns ) && pIns[2] == Gia_ObjId(p, pFan1) )
        return 1;
    if ( Acec_DetectBoothXorFanin( p, pFan1, pIns ) && pIns[2] == Gia_ObjId(p, pFan0) )
        return 1;
    return 0;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Acec_DetectBoothTwoXor( Gia_Man_t * p, Gia_Obj_t * pObj, int pIns[5] )
{
    Gia_Obj_t * pFan0, * pFan1;
    if ( !Gia_ObjIsAnd(pObj) )
        return 0;
    if ( Gia_ObjRecognizeExor( Gia_ObjFanin0(pObj), &pFan0, &pFan1 ) )
    {
        pIns[0] = Gia_ObjId(p, Gia_Regular(pFan0));
        pIns[1] = Gia_ObjId(p, Gia_Regular(pFan1));
        pIns[2] = -1;
        pIns[3] = 0;
        pIns[4] = Gia_ObjId(p, Gia_ObjFanin1(pObj));
        return 1;
    }
    if ( Gia_ObjRecognizeExor( Gia_ObjFanin1(pObj), &pFan0, &pFan1 ) )
    {
        pIns[0] = Gia_ObjId(p, Gia_Regular(pFan0));
        pIns[1] = Gia_ObjId(p, Gia_Regular(pFan1));
        pIns[2] = -1;
        pIns[3] = 0;
        pIns[4] = Gia_ObjId(p, Gia_ObjFanin0(pObj));
        return 1;
    }
    return 0;
}
int Acec_DetectBoothTwo( Gia_Man_t * p, Gia_Obj_t * pObj, int pIns[5] )
{
    Gia_Obj_t * pFan0, * pFan1;
    if ( !Gia_ObjRecognizeExor( pObj, &pFan0, &pFan1 ) )
        return 0;
    pFan0 = Gia_Regular(pFan0);
    pFan1 = Gia_Regular(pFan1);
    if ( Acec_DetectBoothTwoXor( p, pFan0, pIns ) )
    {
        pIns[2] = Gia_ObjId(p, pFan1);
        return 1;
    }
    if ( Acec_DetectBoothTwoXor( p, pFan1, pIns ) )
    {
        pIns[2] = Gia_ObjId(p, pFan0);
        return 1;
    }
    return 0;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Acec_DetectBoothTest( Gia_Man_t * p )
{
    Gia_Obj_t * pObj;
    int i, pIns[5];
    Gia_ManForEachAnd( p, pObj, i )
    {        
        if ( !Acec_DetectBoothOne(p, pObj, pIns) && !Acec_DetectBoothTwo(p, pObj, pIns) )
                continue;
        printf( "obj = %4d  :  b0 = %4d  b1 = %4d  b2 = %4d    a0 = %4d  a1 = %4d\n", 
            i, pIns[0], pIns[1], pIns[2], pIns[3], pIns[4] );
    }
}

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


ABC_NAMESPACE_IMPL_END