1 /**CFile****************************************************************
2 
3   FileName    [mapperLib.c]
4 
5   PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7   Synopsis    [Generic technology mapping engine.]
8 
9   Author      [MVSIS Group]
10 
11   Affiliation [UC Berkeley]
12 
13   Date        [Ver. 2.0. Started - June 1, 2004.]
14 
15   Revision    [$Id: mapperLib.c,v 1.6 2005/01/23 06:59:44 alanmi Exp $]
16 
17 ***********************************************************************/
18 #define _BSD_SOURCE
19 
20 #ifndef WIN32
21 #include <unistd.h>
22 #endif
23 
24 #include "mapperInt.h"
25 #include "map/super/super.h"
26 #include "map/mapper/mapperInt.h"
27 
28 ABC_NAMESPACE_IMPL_START
29 
30 
31 ////////////////////////////////////////////////////////////////////////
32 ///                        DECLARATIONS                              ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 ////////////////////////////////////////////////////////////////////////
36 ///                     FUNCTION DEFINITIONS                         ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 /**Function*************************************************************
40 
41   Synopsis    [Reads in the supergate library and prepares it for use.]
42 
43   Description [The supergates library comes in a .super file. This file
44   contains descriptions of supergates along with some relevant information.
45   This procedure reads the supergate file, canonicizes the supergates,
46   and constructs an additional lookup table, which can be used to map
47   truth tables of the cuts into the pair (phase, supergate). The phase
48   indicates how the current truth table should be phase assigned to
49   match the canonical form of the supergate. The resulting phase is the
50   bitwise EXOR of the phase needed to canonicize the supergate and the
51   phase needed to transform the truth table into its canonical form.]
52 
53   SideEffects []
54 
55   SeeAlso     []
56 
57 ***********************************************************************/
Map_SuperLibCreate(Mio_Library_t * pGenlib,Vec_Str_t * vStr,char * pFileName,char * pExcludeFile,int fAlgorithm,int fVerbose)58 Map_SuperLib_t * Map_SuperLibCreate( Mio_Library_t * pGenlib, Vec_Str_t * vStr, char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
59 {
60     Map_SuperLib_t * p;
61     abctime clk;
62 
63     // start the supergate library
64     p = ABC_ALLOC( Map_SuperLib_t, 1 );
65     memset( p, 0, sizeof(Map_SuperLib_t) );
66     p->pName     = Abc_UtilStrsav(pFileName);
67     p->fVerbose  = fVerbose;
68     p->mmSupers  = Extra_MmFixedStart( sizeof(Map_Super_t) );
69     p->mmEntries = Extra_MmFixedStart( sizeof(Map_HashEntry_t) );
70     p->mmForms   = Extra_MmFlexStart();
71     Map_MappingSetupTruthTables( p->uTruths );
72 
73     // start the hash table
74     p->tTableC = Map_SuperTableCreate( p );
75     p->tTable  = Map_SuperTableCreate( p );
76 
77     // read the supergate library from file
78 clk = Abc_Clock();
79     if ( vStr != NULL )
80     {
81         // read the supergate library from file
82         int Status = Map_LibraryReadFileTreeStr( p, pGenlib, vStr, pFileName );
83         if ( Status == 0 )
84         {
85             Map_SuperLibFree( p );
86             return NULL;
87         }
88         // prepare the info about the library
89         Status = Map_LibraryDeriveGateInfo( p, NULL );
90         if ( Status == 0 )
91         {
92             Map_SuperLibFree( p );
93             return NULL;
94         }
95         assert( p->nVarsMax > 0 );
96     }
97     else if ( fAlgorithm )
98     {
99         if ( !Map_LibraryReadTree( p, pGenlib, pFileName, pExcludeFile ) )
100         {
101             Map_SuperLibFree( p );
102             return NULL;
103         }
104     }
105     else
106     {
107         if ( pExcludeFile != 0 )
108         {
109             Map_SuperLibFree( p );
110             printf ("Error: Exclude file support not present for old format. Stop.\n");
111             return NULL;
112         }
113         if ( !Map_LibraryRead( p, pFileName ) )
114         {
115             Map_SuperLibFree( p );
116             return NULL;
117         }
118     }
119     assert( p->nVarsMax > 0 );
120 
121     // report the stats
122     if ( fVerbose )
123     {
124         printf( "Loaded %d unique %d-input supergates from \"%s\".  ",
125             p->nSupersReal, p->nVarsMax, pFileName );
126         ABC_PRT( "Time", Abc_Clock() - clk );
127     }
128 
129     // assign the interver parameters
130     p->pGateInv        = Mio_LibraryReadInv( p->pGenlib );
131     p->tDelayInv.Rise  = Mio_LibraryReadDelayInvRise( p->pGenlib );
132     p->tDelayInv.Fall  = Mio_LibraryReadDelayInvFall( p->pGenlib );
133     p->tDelayInv.Worst = MAP_MAX( p->tDelayInv.Rise, p->tDelayInv.Fall );
134     p->AreaInv         = Mio_LibraryReadAreaInv( p->pGenlib );
135     p->AreaBuf         = Mio_LibraryReadAreaBuf( p->pGenlib );
136 
137     // assign the interver supergate
138     p->pSuperInv = (Map_Super_t *)Extra_MmFixedEntryFetch( p->mmSupers );
139     memset( p->pSuperInv, 0, sizeof(Map_Super_t) );
140     p->pSuperInv->Num         = -1;
141     p->pSuperInv->nGates      =  1;
142     p->pSuperInv->nFanins     =  1;
143     p->pSuperInv->nFanLimit   = 10;
144     p->pSuperInv->pFanins[0]  = p->ppSupers[0];
145     p->pSuperInv->pRoot       = p->pGateInv;
146     p->pSuperInv->Area        = p->AreaInv;
147     p->pSuperInv->tDelayMax   = p->tDelayInv;
148     p->pSuperInv->tDelaysR[0].Rise = MAP_NO_VAR;
149     p->pSuperInv->tDelaysR[0].Fall = p->tDelayInv.Rise;
150     p->pSuperInv->tDelaysF[0].Rise = p->tDelayInv.Fall;
151     p->pSuperInv->tDelaysF[0].Fall = MAP_NO_VAR;
152     return p;
153 }
154 
155 
156 /**Function*************************************************************
157 
158   Synopsis    [Deallocates the supergate library.]
159 
160   Description []
161 
162   SideEffects []
163 
164   SeeAlso     []
165 
166 ***********************************************************************/
Map_SuperLibFree(Map_SuperLib_t * p)167 void Map_SuperLibFree( Map_SuperLib_t * p )
168 {
169     if ( p == NULL ) return;
170     if ( p->pGenlib )
171     {
172         if ( p->pGenlib != Abc_FrameReadLibGen() )
173             Mio_LibraryDelete( p->pGenlib );
174         p->pGenlib = NULL;
175     }
176     if ( p->tTableC )
177         Map_SuperTableFree( p->tTableC );
178     if ( p->tTable )
179         Map_SuperTableFree( p->tTable );
180     Extra_MmFixedStop( p->mmSupers );
181     Extra_MmFixedStop( p->mmEntries );
182     Extra_MmFlexStop( p->mmForms );
183     ABC_FREE( p->ppSupers );
184     ABC_FREE( p->pName );
185     ABC_FREE( p );
186 }
187 
188 /**Function*************************************************************
189 
190   Synopsis    [Derives the library from the genlib library.]
191 
192   Description []
193 
194   SideEffects []
195 
196   SeeAlso     []
197 
198 ***********************************************************************/
Map_SuperLibDeriveFromGenlib(Mio_Library_t * pLib,int fVerbose)199 int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib, int fVerbose )
200 {
201     Map_SuperLib_t * pLibSuper;
202     Vec_Str_t * vStr;
203     char * pFileName;
204     if ( pLib == NULL )
205         return 0;
206 
207     // compute supergates
208     vStr = Super_PrecomputeStr( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0 );
209     if ( vStr == NULL )
210         return 0;
211 
212     // create supergate library
213     pFileName = Extra_FileNameGenericAppend( Mio_LibraryReadName(pLib), ".super" );
214     pLibSuper = Map_SuperLibCreate( pLib, vStr, pFileName, NULL, 1, 0 );
215     Vec_StrFree( vStr );
216 
217     // replace the library
218     Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
219     Abc_FrameSetLibSuper( pLibSuper );
220     return 1;
221 }
222 
223 /**Function*************************************************************
224 
225   Synopsis    [Derives the library from the genlib library.]
226 
227   Description []
228 
229   SideEffects []
230 
231   SeeAlso     []
232 
233 ***********************************************************************/
Map_SuperLibDeriveFromGenlib2(Mio_Library_t * pLib,int fVerbose)234 int Map_SuperLibDeriveFromGenlib2( Mio_Library_t * pLib, int fVerbose )
235 {
236     Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
237     char * pFileName;
238     if ( pLib == NULL )
239         return 0;
240     // compute supergates
241     pFileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
242     Super_Precompute( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0, pFileName );
243     // assuming that it terminated successfully
244     if ( Cmd_CommandExecute( pAbc, pFileName ) )
245     {
246         fprintf( stdout, "Cannot execute command \"read_super %s\".\n", pFileName );
247         return 0;
248     }
249     return 1;
250 }
251 
252 ////////////////////////////////////////////////////////////////////////
253 ///                       END OF FILE                                ///
254 ////////////////////////////////////////////////////////////////////////
255 
256 
257 ABC_NAMESPACE_IMPL_END
258 
259