bacOper.c 12.3 KB
Newer Older
1 2
/**CFile****************************************************************

3
  FileName    [bacOper.c]
4 5 6 7 8 9 10 11 12 13 14 15 16

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Hierarchical word-level netlist.]

  Synopsis    [Operator procedures.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - November 29, 2014.]

17
  Revision    [$Id: bacOper.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
18 19 20

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

21
#include "bac.h"
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

ABC_NAMESPACE_IMPL_START

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

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
44
int Bac_BoxCreate( Bac_Ntk_t * p, Bac_ObjType_t Type, Vec_Int_t * vFanins, int nInA, int nInB, int nOuts )
45 46
{
    char pName[100]; int i, iObj, iFanin;
47 48
    assert( BAC_OBJ_BOX < Type && Type < BAC_BOX_UNKNOWN );
    if ( BAC_BOX_CF <= Type && Type <= BAC_BOX_CZ )
49 50 51
    {
        sprintf( pName, "ABCCTo%d", nOuts );
        assert( 0 == Vec_IntSize(vFanins) );
52
        iObj = Bac_BoxAlloc( p, Type, 0, nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
53
    }
54
    else if ( BAC_BOX_BUF <= Type && Type <= BAC_BOX_INV )
55 56 57 58
    {
        char * pPref[2] = { "ABCBUF", "ABCINV" };
        assert( nInA == nOuts );
        assert( nInA == Vec_IntSize(vFanins) );
59 60
        sprintf( pName, "%sa%do%d", pPref[Type - BAC_BOX_BUF], nInA, nOuts );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
61
    }
62
    else if ( BAC_BOX_AND <= Type && Type <= BAC_BOX_XNOR )
63 64 65 66
    {
        char * pPref[6] = { "ABCAND", "ABCNAND", "ABCOR", "ABCNOR", "ABCXOR", "ABCXNOR" };
        assert( nInA == nOuts && nInB == nOuts );
        assert( nInA + nInB == Vec_IntSize(vFanins) );
67 68
        sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_AND], nInA, nInB, nOuts );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
69
    }
70
    else if ( Type == BAC_BOX_MUX )
71 72 73 74
    {
        char * pPref[1] = { "ABCMUX" };
        assert( nInA == nOuts && nInB == nOuts );
        assert( 1 + nInA + nInB == Vec_IntSize(vFanins) );
75 76
        sprintf( pName, "%sc%da%db%do%d", pPref[Type - BAC_BOX_MUX], 1, nInA, nInB, nOuts );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
77
    }
78
    else if ( Type == BAC_BOX_MAJ )
79 80 81 82
    {
        char * pPref[1] = { "ABCMAJ" };
        assert( nInA == 1 && nInB == 1 && nOuts == 1 );
        assert( 3 == Vec_IntSize(vFanins) );
83 84
        sprintf( pName, "%sa%db%dc%do%d", pPref[Type - BAC_BOX_MAJ], 1, 1, 1, 1 );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
85
    }
86
    else if ( BAC_BOX_RAND <= Type && Type <= BAC_BOX_RXNOR )
87 88 89 90
    {
        char * pPref[6] = { "ABCRAND", "ABCRNAND", "ABCROR", "ABCRNOR", "ABCRXOR", "ABCRXNOR" };
        assert( nInA == nInB && 1 == nOuts );
        assert( nInA + nInB == Vec_IntSize(vFanins) );
91 92
        sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_RAND], nInA, nInB, nOuts );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
93
    }
94
    else if ( Type == BAC_BOX_SEL )
95 96 97 98
    {
        char * pPref[1] = { "ABCSEL" };
        assert( nInA * nOuts == nInB );
        assert( nInA + nInB == Vec_IntSize(vFanins) );
99 100
        sprintf( pName, "%sa%db%do%d", pPref[Type - BAC_BOX_SEL], nInA, nInB, nOuts );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
101
    }
102
    else if ( Type == BAC_BOX_PSEL )
103 104 105 106
    {
        char * pPref[1] = { "ABCPSEL" };
        assert( nInA * nOuts == nInB );
        assert( 1 + nInA + nInB == Vec_IntSize(vFanins) );
107 108
        sprintf( pName, "%si%da%db%do%d", pPref[Type - BAC_BOX_SEL], 1, nInA, nInB, nOuts );
        iObj = Bac_BoxAlloc( p, Type, Vec_IntSize(vFanins), nOuts, Abc_NamStrFindOrAdd(p->pDesign->pMods, pName, NULL) );
109 110 111
    }
    // add fanins
    Vec_IntForEachEntry( vFanins, iFanin, i )
112
        Bac_ObjSetFanin( p, Bac_BoxBi(p, iObj, i), iFanin );
113 114 115 116 117 118 119 120 121 122 123 124 125 126
    return iObj;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
127
int Bac_ObjClpWide( Bac_Ntk_t * p, int iBox )
128
{
129 130 131
    Bac_ObjType_t Type = Bac_ObjType( p, iBox );
    int nBis = Bac_BoxBiNum(p, iBox);
    int nBos = Bac_BoxBoNum(p, iBox);
132 133 134
    int i, k, iObj;
    assert( nBos > 1 );
    Vec_IntClear( &p->vArray );
135
    if ( BAC_BOX_BUF <= Type && Type <= BAC_BOX_INV )
136 137 138
    {
        for ( i = 0; i < nBos; i++ )
        {
139 140 141
            Vec_IntFill( &p->vArray2, 1, Bac_BoxFanin(p, iBox, i) );
            iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, -1, 1 );
            Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
142 143
        }
    }
144
    else if ( BAC_BOX_AND <= Type && Type <= BAC_BOX_XNOR )
145 146 147 148
    {
        assert( nBis == 2 * nBos );
        for ( i = 0; i < nBos; i++ )
        {
149 150 151
            Vec_IntFillTwo( &p->vArray2, 2, Bac_BoxFanin(p, iBox, i), Bac_BoxFanin(p, iBox, nBos+i) );
            iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, 1, 1 );
            Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
152 153
        }
    }
154
    else if ( Type == BAC_BOX_MUX )
155 156 157 158
    {
        assert( nBis - 1 == 2 * nBos );
        for ( i = 0; i < nBos; i++ )
        {
159 160 161 162
            Vec_IntFill( &p->vArray2, 1, Bac_BoxFanin(p, iBox, 0) );
            Vec_IntPushTwo( &p->vArray2, Bac_BoxFanin(p, iBox, 1+i), Bac_BoxFanin(p, iBox, 1+nBos+i) );
            iObj = Bac_BoxCreate( p, Type, &p->vArray2, 1, 1, 1 );
            Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
163 164
        }
    }
165
    else if ( Type == BAC_BOX_NMUX )
166 167 168 169 170 171 172 173 174 175 176
    {
        int n, nIns = nBis / nBos;
        assert( nBis % nBos == 0 );
        for ( n = 1; n < 32; n++ )
            if ( n + (1 << n) == nIns )
                break;
        assert( n > 1 && n < 32 );
        for ( i = 0; i < nBos; i++ )
        {
            Vec_IntClear( &p->vArray2 );
            for ( k = 0; k < n; k++ )
177
                Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, k) );
178
            for ( k = 0; k < (1 << n); k++ )
179 180 181
                Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, n + (1 << n) * i + k) );
            iObj = Bac_BoxCreate( p, Type, &p->vArray2, n, (1 << n), 1 );
            Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
182 183
        }
    }
184
    else if ( Type == BAC_BOX_SEL )
185 186
    {
    }
187
    else if ( Type == BAC_BOX_PSEL )
188 189
    {
    }
190
    else if ( Type == BAC_BOX_DFF || Type == BAC_BOX_LATCH )
191 192
    {
    }
193
    else if ( Type == BAC_BOX_DFFRS || Type == BAC_BOX_LATCHRS )
194 195 196
    {
    }
    else assert( 0 );
197
    Bac_BoxReplace( p, iBox, Vec_IntArray(&p->vArray), Vec_IntSize(&p->vArray) );
198 199 200 201 202 203 204 205 206 207 208 209 210 211
    return iBox;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
212
int Bac_ObjClpArith( Bac_Ntk_t * p, int iBox )
213
{
214
    Bac_ObjType_t Type = Bac_ObjType( p, iBox );
215
    int i, iObj = -1;
216 217 218
    int nBis = 0;//Bac_NtkReadRangesPrim( Bac_BoxNtkName(p, iObj), &p->vArray, 0 );
    assert( nBis == Bac_BoxBiNum(p, iBox) );
    if ( Type == BAC_BOX_ADD )
219
    {
220
        int Carry = Bac_BoxFanin(p, iBox, 0);
221 222 223 224 225 226 227 228
        int nBits = Vec_IntEntry(&p->vArray, 1);
        assert( Vec_IntSize(&p->vArray) == 3 );
        assert( Vec_IntEntry(&p->vArray, 0) == 1 );
        assert( Vec_IntEntry(&p->vArray, 2) == nBits );
        Vec_IntClear( &p->vArray );
        for ( i = 0; i < nBits; i++ )
        {
            Vec_IntFill( &p->vArray2, 1, Carry );
229 230 231 232
            Vec_IntPushTwo( &p->vArray2, Bac_BoxFanin(p, iBox, 1+i), Bac_BoxFanin(p, iBox, 1+nBits+i) );
            iObj = Bac_BoxCreate( p, BAC_BOX_ADD, &p->vArray2, 1, 1, 1 );
            Carry = Bac_BoxBo(p, iObj, 1);
            Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, 0) );
233 234 235
        }
        Vec_IntPush( &p->vArray, Carry );
    }
236
    else if ( Type == BAC_BOX_SUB )
237 238 239 240 241 242 243
    {
        int iConst, nBits = Vec_IntEntry(&p->vArray, 0);
        assert( Vec_IntSize(&p->vArray) == 2 );
        assert( Vec_IntEntry(&p->vArray, 1) == nBits );
        // create inverter
        Vec_IntClear( &p->vArray2 );
        for ( i = 0; i < nBits; i++ )
244 245
            Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, nBits+i) );
        iObj = Bac_BoxCreate( p, BAC_BOX_INV, &p->vArray2, nBits, -1, nBits );
246 247
        // create constant
        Vec_IntClear( &p->vArray2 );
248
        iConst = Bac_BoxCreate( p, BAC_BOX_CT, &p->vArray2, -1, -1, 1 );
249 250 251
        // collect fanins
        Vec_IntFill( &p->vArray2, 1, iConst+1 );
        for ( i = 0; i < nBits; i++ )
252
            Vec_IntPush( &p->vArray2, Bac_BoxFanin(p, iBox, i) );
253
        for ( i = 0; i < nBits; i++ )
254
            Vec_IntPush( &p->vArray2, Bac_BoxBo(p, iObj, i) );
255
        // create adder
256
        iObj = Bac_BoxCreate( p, BAC_BOX_ADD, &p->vArray2, nBits, nBits, nBits );
257 258 259
        // collect fanins
        Vec_IntClear( &p->vArray );
        for ( i = 0; i < nBits; i++ )
260
            Vec_IntPush( &p->vArray, Bac_BoxBo(p, iObj, i) );
261
    }
262
    else if ( Type == BAC_BOX_MUL )
263 264
    {
    }
265
    else if ( Type == BAC_BOX_DIV )
266 267
    {
    }
268
    else if ( Type == BAC_BOX_MOD )
269 270
    {
    }
271
    else if ( Type == BAC_BOX_REM )
272 273
    {
    }
274
    else if ( Type == BAC_BOX_POW )
275 276
    {
    }
277
    else if ( Type == BAC_BOX_MIN )
278 279
    {
    }
280
    else if ( Type == BAC_BOX_ABS )
281 282 283
    {
    }

284
    else if ( Type == BAC_BOX_LTHAN )
285 286
    {
    }
287
    else if ( Type == BAC_BOX_LETHAN )
288 289
    {
    }
290
    else if ( Type == BAC_BOX_METHAN )
291 292
    {
    }
293
    else if ( Type == BAC_BOX_MTHAN )
294 295
    {
    }
296
    else if ( Type == BAC_BOX_EQU )
297 298
    {
    }
299
    else if ( Type == BAC_BOX_NEQU )
300 301 302
    {
    }

303
    else if ( Type == BAC_BOX_SHIL )
304 305
    {
    }
306
    else if ( Type == BAC_BOX_SHIR )
307 308
    {
    }
309
    else if ( Type == BAC_BOX_ROTL )
310 311
    {
    }
312
    else if ( Type == BAC_BOX_ROTR )
313 314
    {
    }
315
    Bac_BoxReplace( p, iBox, Vec_IntArray(&p->vArray), Vec_IntSize(&p->vArray) );
316 317 318 319 320 321 322 323 324 325 326 327 328 329
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
330
int Bac_ObjClpMemory( Bac_Ntk_t * p, int iBox )
331
{
332 333 334
    int i, En, iNext, nItems = Bac_BoxBiNum(p, iBox);
    assert( Bac_ObjType(p, iBox) == BAC_BOX_RAMBOX );
    assert( Bac_BoxBiNum(p, iBox) == Bac_BoxBoNum(p, iBox) );
335
    // for each fanin of RAMBOX, make sure address width is the same
336 337
    Bac_BoxForEachFaninBox( p, iBox, iNext, i )
        assert( Bac_ObjType(p, iNext) == BAC_BOX_RAMWC );
338 339 340 341

    // create decoders, selectors and flops
    for ( i = 0; i < nItems; i++ )
    {
342 343 344 345
        int BoxW = Bac_ObjFanin(p, Bac_BoxBi(p, iBox, i));
        int BoxR = Bac_ObjFanout(p, Bac_BoxBo(p, iBox, 0));
        assert( Bac_ObjType(p, BoxW) == BAC_BOX_RAMWC );
        assert( Bac_ObjType(p, BoxR) == BAC_BOX_RAMR );
346
        // create enable
347 348 349
        Vec_IntFillTwo( &p->vArray2, 2, Bac_BoxFanin(p, BoxW, 1), Bac_BoxFanin(p, BoxR, 0) );
        En = Bac_BoxCreate( p, BAC_BOX_AND, &p->vArray2, 1, 1, 1 );
        En = Bac_BoxBo( p, En, 0 );
350 351 352
        // collect address
    }
    // for each fanout of RAMBOX, makes ure address width is the same
353 354
//    Bac_BoxForEachFanoutBox( p, iBox, iNext, i )
//        assert( Bac_ObjType(p, iNext) == BAC_BOX_RAMR );
355 356 357 358 359 360 361 362 363 364 365
    // create selectors and connect them
    return 1;
}

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


ABC_NAMESPACE_IMPL_END