ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
exorUtil.c
Go to the documentation of this file.
1
20
44
45#include "exor.h"
46
48
52
53// information about the options, the function, and the cover
54extern cinfo g_CoverInfo;
55
59
60// Cube Cover Iterator
61// starts an iterator that traverses all the cubes in the ring
62extern Cube* IterCubeSetStart();
63// returns the next cube in the ring
64extern Cube* IterCubeSetNext();
65
66// retrieves the variable from the cube
67extern varvalue GetVar( Cube* pC, int Var );
68
72
76
78{
79 Cube* p;
80 int LitCounter = 0;
81 for ( p = IterCubeSetStart( ); p; p = IterCubeSetNext() )
82 LitCounter += p->a;
83 return LitCounter;
84}
85
87{
88 Cube* p;
89 int Value, v;
90 int LitCounter = 0;
91 int LitCounterControl = 0;
92
93 for ( p = IterCubeSetStart( ); p; p = IterCubeSetNext() )
94 {
95 LitCounterControl += p->a;
96
97 assert( p->fMark == 0 );
98
99 // write the input variables
100 for ( v = 0; v < g_CoverInfo.nVarsIn; v++ )
101 {
102 Value = GetVar( p, v );
103 if ( Value == VAR_NEG )
104 LitCounter++;
105 else if ( Value == VAR_POS )
106 LitCounter++;
107 else if ( Value != VAR_ABS )
108 {
109 assert(0);
110 }
111 }
112 }
113
114 if ( LitCounterControl != LitCounter )
115 printf( "Warning! The recorded number of literals (%d) differs from the actual number (%d)\n", LitCounterControl, LitCounter );
116 return LitCounter;
117}
118
120{
121 Cube* p;
122 int QCost = 0;
123 int QCostControl = 0;
124 for ( p = IterCubeSetStart( ); p; p = IterCubeSetNext() )
125 {
126 QCostControl += p->q;
127 QCost += ComputeQCostBits( p );
128 }
129// if ( QCostControl != QCost )
130// printf( "Warning! The recorded number of literals (%d) differs from the actual number (%d)\n", QCostControl, QCost );
131 return QCost;
132}
133
134
135void WriteTableIntoFile( FILE * pFile )
136// nCubesAlloc is the number of allocated cubes
137{
138 int v, w;
139 Cube * p;
140 int cOutputs;
141 int nOutput;
142 int WordSize;
143
144 for ( p = IterCubeSetStart( ); p; p = IterCubeSetNext() )
145 {
146 assert( p->fMark == 0 );
147
148 // write the input variables
149 for ( v = 0; v < g_CoverInfo.nVarsIn; v++ )
150 {
151 int Value = GetVar( p, v );
152 if ( Value == VAR_NEG )
153 fprintf( pFile, "0" );
154 else if ( Value == VAR_POS )
155 fprintf( pFile, "1" );
156 else if ( Value == VAR_ABS )
157 fprintf( pFile, "-" );
158 else
159 assert(0);
160 }
161 fprintf( pFile, " " );
162
163 // write the output variables
164 cOutputs = 0;
165 nOutput = g_CoverInfo.nVarsOut;
166 WordSize = 8*sizeof( unsigned );
167 for ( w = 0; w < g_CoverInfo.nWordsOut; w++ )
168 for ( v = 0; v < WordSize; v++ )
169 {
170 if ( p->pCubeDataOut[w] & (1<<v) )
171 fprintf( pFile, "1" );
172 else
173 fprintf( pFile, "0" );
174 if ( ++cOutputs == nOutput )
175 break;
176 }
177 fprintf( pFile, "\n" );
178 }
179}
180
181
182int WriteResultIntoFile( char * pFileName )
183// write the ESOP cover into the PLA file <NewFileName>
184{
185 FILE * pFile;
186 time_t ltime;
187 char * TimeStr;
188
189 pFile = fopen( pFileName, "w" );
190 if ( pFile == NULL )
191 {
192 fprintf( stderr, "\n\nCannot open the output file\n" );
193 return 1;
194 }
195
196 // get current time
197 time( &ltime );
198 TimeStr = asctime( localtime( &ltime ) );
199 // get the number of literals
200 g_CoverInfo.nLiteralsAfter = CountLiteralsCheck();
201 g_CoverInfo.QCostAfter = CountQCost();
202 fprintf( pFile, "# EXORCISM-4 output for command line arguments: " );
203 fprintf( pFile, "\"-Q %d -V %d\"\n", g_CoverInfo.Quality, g_CoverInfo.Verbosity );
204 fprintf( pFile, "# Minimization performed %s", TimeStr );
205 fprintf( pFile, "# Initial statistics: " );
206 fprintf( pFile, "Cubes = %d Literals = %d QCost = %d\n", g_CoverInfo.nCubesBefore, g_CoverInfo.nLiteralsBefore, g_CoverInfo.QCostBefore );
207 fprintf( pFile, "# Final statistics: " );
208 fprintf( pFile, "Cubes = %d Literals = %d QCost = %d\n", g_CoverInfo.nCubesInUse, g_CoverInfo.nLiteralsAfter, g_CoverInfo.QCostAfter );
209 fprintf( pFile, "# File reading and reordering time = %.2f sec\n", TICKS_TO_SECONDS(g_CoverInfo.TimeRead) );
210 fprintf( pFile, "# Starting cover generation time = %.2f sec\n", TICKS_TO_SECONDS(g_CoverInfo.TimeStart) );
211 fprintf( pFile, "# Pure ESOP minimization time = %.2f sec\n", TICKS_TO_SECONDS(g_CoverInfo.TimeMin) );
212 fprintf( pFile, ".i %d\n", g_CoverInfo.nVarsIn );
213 fprintf( pFile, ".o %d\n", g_CoverInfo.nVarsOut );
214 fprintf( pFile, ".p %d\n", g_CoverInfo.nCubesInUse );
215 fprintf( pFile, ".type esop\n" );
216 WriteTableIntoFile( pFile );
217 fprintf( pFile, ".e\n" );
218 fclose( pFile );
219 return 0;
220}
221
225
226
228
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
int CountLiterals()
FUNCTION DECLARATIONS ///.
Definition exorUtil.c:77
int CountQCost()
Definition exorUtil.c:119
int CountLiteralsCheck()
Definition exorUtil.c:86
int WriteResultIntoFile(char *pFileName)
Definition exorUtil.c:182
varvalue GetVar(Cube *pC, int Var)
INLINE FUNCTION DEFINITIONS ///.
Definition exorBits.c:188
void WriteTableIntoFile(FILE *pFile)
Definition exorUtil.c:135
Cube * IterCubeSetStart()
EXTERNAL FUNCTIONS ///.
Definition exorList.c:880
Cube * IterCubeSetNext()
Definition exorList.c:892
int ComputeQCostBits(Cube *p)
Definition exor.c:139
ABC_NAMESPACE_IMPL_START cinfo g_CoverInfo
GLOBAL VARIABLES ///.
Definition exor.c:58
struct cube Cube
struct cinfo_tag cinfo
varvalue
VARVALUE and CUBEDIST enum typedefs ///.
Definition exor.h:178
@ VAR_POS
Definition exor.h:178
@ VAR_NEG
Definition exor.h:178
@ VAR_ABS
Definition exor.h:178
#define assert(ex)
Definition util_old.h:213