ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
exor.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include "misc/vec/vec.h"
#include "misc/vec/vecWec.h"
Include dependency graph for exor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cinfo_tag
 
struct  cube
 

Typedefs

typedef struct cinfo_tag cinfo
 
typedef unsigned int drow
 
typedef unsigned char byte
 
typedef struct cube Cube
 

Enumerations

enum  {
  BPI = 32 , BPIMASK = 31 , LOGBPI = 5 , MAXVARS = 1000 ,
  ADDITIONAL_CUBES = 33 , CUBE_PAIR_FACTOR = 20 , DIFFERENT = 0x55555555
}
 MACRO DEFINITIONS ///. More...
 
enum  type { MULTI_OUTPUT = 1 , SINGLE_NODE , MULTI_NODE }
 CUBE COVER and CUBE typedefs ///. More...
 
enum  varvalue { VAR_NEG = 1 , VAR_POS , VAR_ABS }
 VARVALUE and CUBEDIST enum typedefs ///. More...
 
enum  cubedist { DIST2 , DIST3 , DIST4 }
 

Functions

void PrepareBitSetModule ()
 FUNCTION DEFINITIONS ///.
 
int WriteResultIntoFile (char *pFileName)
 
int IterativelyApplyExorLink2 (char fDistEnable)
 FUNCTIONS OF THIS MODULE ///.
 
int IterativelyApplyExorLink3 (char fDistEnable)
 
int IterativelyApplyExorLink4 (char fDistEnable)
 
int AllocateCubeSets (int nVarsIn, int nVarsOut)
 CUBE SET MANIPULATION PROCEDURES ///.
 
void DelocateCubeSets ()
 
int AllocateQueques (int nPlaces)
 
void DelocateQueques ()
 
int AllocateCover (int nCubes, int nWordsIn, int nWordsOut)
 CUBE COVER MEMORY MANAGEMENT //.
 
void DelocateCover ()
 
void AddToFreeCubes (Cube *pC)
 FREE CUBE LIST MANIPULATION FUNCTIONS ///.
 
CubeGetFreeCube ()
 
void InsertVarsWithoutClearing (Cube *pC, int *pVars, int nVarsIn, int *pVarValues, int Output)
 
int CheckForCloseCubes (Cube *p, int fAddCube)
 
int FindDiffVars (int *pDiffVars, Cube *pC1, Cube *pC2)
 
int ComputeQCost (Vec_Int_t *vCube)
 
int ComputeQCostBits (Cube *p)
 
int CountLiterals ()
 FUNCTION DECLARATIONS ///.
 
int CountQCost ()
 

Variables

unsigned char BitCount []
 

Typedef Documentation

◆ byte

typedef unsigned char byte

Definition at line 121 of file exor.h.

◆ cinfo

typedef struct cinfo_tag cinfo

◆ Cube

typedef struct cube Cube

◆ drow

typedef unsigned int drow

Definition at line 120 of file exor.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

MACRO DEFINITIONS ///.

CFile****************************************************************

FileName [exor.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Exclusive sum-of-product minimization.]

Synopsis [Internal declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id
exor.h,v 1.0 2005/06/20 00:00:00 alanmi Exp

]

                                                            ///
              Interface of EXORCISM - 4                     ///
        An Exclusive Sum-of-Product Minimizer               ///
         Alan Mishchenko  <alanmi@ee.pdx.edu>               ///
                                                            ///

                                                            ///
                   Main Module                              ///
                                                            ///

Ver. 1.0. Started - July 15, 2000. Last update - July 20, 2000 /// Ver. 1.4. Started - Aug 10, 2000. Last update - Aug 10, 2000 /// Ver. 1.7. Started - Sep 20, 2000. Last update - Sep 23, 2000 /// ///

This software was tested with the BDD package "CUDD", v.2.3.0 /// by Fabio Somenzi /// http://vlsi.colorado.edu/~fabio/ ///

Enumerator
BPI 
BPIMASK 
LOGBPI 
MAXVARS 
ADDITIONAL_CUBES 
CUBE_PAIR_FACTOR 
DIFFERENT 

Definition at line 57 of file exor.h.

57 {
58 // the number of bits per integer
59 BPI = 32,
60 BPIMASK = 31,
61 LOGBPI = 5,
62
63 // the maximum number of input variables
64 MAXVARS = 1000,
65
66 // the number of cubes that are allocated additionally
68
69 // the factor showing how many cube pairs will be allocated
71 // the following number of cube pairs are allocated:
72 // nCubesAlloc/CUBE_PAIR_FACTOR
73
74 DIFFERENT = 0x55555555,
75};
#define LOGBPI
Definition espresso.h:69
@ BPI
Definition exor.h:59
@ ADDITIONAL_CUBES
Definition exor.h:67
@ CUBE_PAIR_FACTOR
Definition exor.h:70
@ DIFFERENT
Definition exor.h:74
@ BPIMASK
Definition exor.h:60
#define MAXVARS

◆ cubedist

enum cubedist
Enumerator
DIST2 
DIST3 
DIST4 

Definition at line 181 of file exor.h.

cubedist
Definition exor.h:181
@ DIST4
Definition exor.h:181
@ DIST2
Definition exor.h:181
@ DIST3
Definition exor.h:181

◆ type

enum type

CUBE COVER and CUBE typedefs ///.

Enumerator
MULTI_OUTPUT 
SINGLE_NODE 
MULTI_NODE 

Definition at line 90 of file exor.h.

type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
@ SINGLE_NODE
Definition exor.h:90
@ MULTI_OUTPUT
Definition exor.h:90
@ MULTI_NODE
Definition exor.h:90

◆ varvalue

enum varvalue

VARVALUE and CUBEDIST enum typedefs ///.

Enumerator
VAR_NEG 
VAR_POS 
VAR_ABS 

Definition at line 178 of file exor.h.

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

Function Documentation

◆ AddToFreeCubes()

void AddToFreeCubes ( Cube * pC)
extern

FREE CUBE LIST MANIPULATION FUNCTIONS ///.

Definition at line 157 of file exorCubes.c.

158{
159 assert( p );
160 assert( p->Prev == NULL ); // the cube should not be in use
161 assert( p->Next == NULL );
162 assert( p->ID );
163
164 p->Next = s_CubesFree;
165 s_CubesFree = p;
166
167 // set the ID of the cube to 0,
168 // so that cube pair garbage collection could recognize it as different
169 p->ID = 0;
170
171 g_CoverInfo.nCubesFree++;
172}
Cube * s_CubesFree
Definition exorCubes.c:84
Cube * p
Definition exorList.c:222
ABC_NAMESPACE_IMPL_START cinfo g_CoverInfo
GLOBAL VARIABLES ///.
Definition exor.c:58
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ AllocateCover()

int AllocateCover ( int nCubes,
int nWordsIn,
int nWordsOut )
extern

CUBE COVER MEMORY MANAGEMENT //.

CUBE COVER MEMORY MANAGEMENT //.

Definition at line 90 of file exorCubes.c.

93{
94 int OneCubeSize;
95 int OneInputSetSize;
96 Cube ** pp;
97 int TotalSize;
98 int i, k;
99
100 // determine the size of one cube WITH storage for bits
101 OneCubeSize = sizeof(Cube) + (nWordsIn+nWordsOut)*sizeof(unsigned);
102 // determine what is the amount of storage for the input part of the cube
103 OneInputSetSize = nWordsIn*sizeof(unsigned);
104
105 // allocate memory for the array of pointers
106 pp = (Cube **)ABC_ALLOC( Cube *, nCubes );
107 if ( pp == NULL )
108 return 0;
109
110 // determine the size of the total cube cover
111 TotalSize = nCubes*OneCubeSize;
112 // allocate and clear memory for the cover in one large piece
113 pp[0] = (Cube *)ABC_ALLOC( char, TotalSize );
114 if ( pp[0] == NULL )
115 return 0;
116 memset( pp[0], 0, (size_t)TotalSize );
117
118 // assign pointers to cubes and bit strings inside this piece
119 pp[0]->pCubeDataIn = (unsigned*)(pp[0] + 1);
120 pp[0]->pCubeDataOut = (unsigned*)((char*)pp[0]->pCubeDataIn + OneInputSetSize);
121 for ( i = 1; i < nCubes; i++ )
122 {
123 pp[i] = (Cube *)((char*)pp[i-1] + OneCubeSize);
124 pp[i]->pCubeDataIn = (unsigned*)(pp[i] + 1);
125 pp[i]->pCubeDataOut = (unsigned*)((char*)pp[i]->pCubeDataIn + OneInputSetSize);
126 }
127
128 // connect the cubes into the list using Next pointers
129 for ( k = 0; k < nCubes-1; k++ )
130 pp[k]->Next = pp[k+1];
131 // the last pointer is already set to NULL
132
133 // assign the head of the free list
134 s_CubesFree = pp[0];
135 // set the counters of the used and free cubes
136 g_CoverInfo.nCubesInUse = 0;
137 g_CoverInfo.nCubesFree = nCubes;
138
139 // save the pointer to the allocated memory
140 s_pCoverMemory = pp;
141
142 assert ( g_CoverInfo.nCubesInUse + g_CoverInfo.nCubesFree == g_CoverInfo.nCubesAlloc );
143
144 return nCubes*sizeof(Cube *) + TotalSize;
145}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
Cube ** s_pCoverMemory
EXPORTED VARIABLES ///.
Definition exorCubes.c:81
struct cube Cube
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateCubeSets()

int AllocateCubeSets ( int nVarsIn,
int nVarsOut )
extern

CUBE SET MANIPULATION PROCEDURES ///.

Memory Allocation/Delocation ///

Definition at line 792 of file exorList.c.

793{
794 s_List = NULL;
795
796 // clean other data
797 s_fDistEnable2 = 1;
798 s_fDistEnable3 = 0;
799 s_fDistEnable4 = 0;
800 memset( s_CubeGroup, 0, sizeof(void *) * 5 );
801 memset( s_fInserted, 0, sizeof(int) * 5 );
803 s_cEnquequed = 0;
804 s_cAttempts = 0;
805 s_cReshapes = 0;
806 s_nCubesBefore = 0;
807 s_Gain = 0;
808 s_GainTotal = 0;
809 s_GroupCounter = 0;
810 s_GroupBest = 0;
811 s_pC1 = s_pC2 = NULL;
812
813 return 4;
814}
int s_fDecreaseLiterals
Definition exorList.c:247
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateQueques()

int AllocateQueques ( int nPlaces)
extern

Definition at line 1112 of file exorList.c.

1115{
1116 int i;
1117 s_nPosAlloc = nPlaces;
1118
1119 for ( i = 0; i < 3; i++ )
1120 {
1121 // clean data
1122 memset( &s_Que[i], 0, sizeof(que) );
1123
1124 s_Que[i].pC1 = (Cube**) ABC_ALLOC( Cube*, nPlaces );
1125 s_Que[i].pC2 = (Cube**) ABC_ALLOC( Cube*, nPlaces );
1126 s_Que[i].ID1 = (byte*) ABC_ALLOC( byte, nPlaces );
1127 s_Que[i].ID2 = (byte*) ABC_ALLOC( byte, nPlaces );
1128
1129 if ( s_Que[i].pC1==NULL || s_Que[i].pC2==NULL || s_Que[i].ID1==NULL || s_Que[i].ID2==NULL )
1130 return 0;
1131
1132 s_nPosMax[i] = 0;
1133 s_Que[i].fEmpty = 1;
1134 }
1135
1136 return nPlaces * (sizeof(Cube*) + sizeof(Cube*) + 2*sizeof(byte) );
1137}
int s_nPosAlloc
EXPORTED VARIABLES /// /////////////////////////////////////////////////////////////////////`.
Definition exorList.c:179
int s_nPosMax[3]
Definition exorList.c:181
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckForCloseCubes()

int CheckForCloseCubes ( Cube * p,
int fAddCube )
extern

Definition at line 643 of file exorList.c.

650{
651 // start the new range
652 NewRangeReset();
653
654 for ( s_q = s_List; s_q; s_q = s_q->Next )
655 {
657 if ( s_Distance > 4 )
658 {
659 }
660 else if ( s_Distance == 4 )
661 {
662 if ( s_fDistEnable4 )
663 NewRangeInsertCubePair( DIST4, p, s_q );
664 }
665 else if ( s_Distance == 3 )
666 {
667 if ( s_fDistEnable3 )
668 NewRangeInsertCubePair( DIST3, p, s_q );
669 }
670 else if ( s_Distance == 2 )
671 {
672 if ( s_fDistEnable2 )
673 NewRangeInsertCubePair( DIST2, p, s_q );
674 }
675 else if ( s_Distance == 1 )
676 { // extract the cube from the data structure
677
679 // store the changes
680 s_ChangeStore.fInput = (s_DiffVarNum != -1);
681 s_ChangeStore.p = p;
682 s_ChangeStore.PrevQa = s_q->a;
683 s_ChangeStore.PrevPa = p->a;
684 s_ChangeStore.PrevQq = s_q->q;
685 s_ChangeStore.PrevPq = p->q;
686 s_ChangeStore.PrevPz = p->z;
687 s_ChangeStore.Var = s_DiffVarNum;
688 s_ChangeStore.Value = s_DiffVarValueQ;
689 s_ChangeStore.PrevID = s_q->ID;
691
692 CubeExtract( s_q );
693 // perform the EXOR of the two cubes and write the result into p
694
695 // it is important that the resultant cube is written into p!!!
696
697 if ( s_DiffVarNum == -1 )
698 {
699 int i;
700 // exor the output part
701 p->z = 0;
702 for ( i = 0; i < g_CoverInfo.nWordsOut; i++ )
703 {
704 p->pCubeDataOut[i] ^= s_q->pCubeDataOut[i];
705 p->z += BIT_COUNT(p->pCubeDataOut[i]);
706 }
707 }
708 else
709 {
710 // the cube has already been updated by GetDistancePlus()
711
712 // modify the parameters of the number of literals in the new cube
713// p->a += s_UpdateLiterals[ s_DiffVarValueP ][ s_DiffVarValueQ ];
715 p->a--;
717 p->a++;
718 p->q = ComputeQCostBits(p);
719 }
720
721 // move q to the free cube list
723
724 // make sure that nobody with use the pairs created so far
725// NewRangeReset();
726 // call the function again for the new cube
727 return 1 + CheckForCloseCubes( p, 1 );
728 }
729 else // if ( Distance == 0 )
730 { // extract the second cube from the data structure and add them both to the free list
731 AddToFreeCubes( p );
733
734 // make sure that nobody with use the pairs created so far
735 NewRangeReset();
736 return 2;
737 }
738 }
739
740 // add the cube to the data structure if needed
741 if ( fAddCube )
742 CubeInsert( p );
743
744 // add temporarily stored new range of cube pairs to the queque
745 NewRangeAdd();
746
747 return 0;
748}
int s_DiffVarValueP_new
Definition exorList.c:640
int s_DiffVarValueQ
Definition exorList.c:641
int s_DiffVarNum
Definition exorList.c:638
int s_DiffVarValueP_old
Definition exorList.c:639
int s_Distance
Definition exorList.c:637
Cube * s_q
Definition exorList.c:636
int CheckForCloseCubes(Cube *p, int fAddCube)
Definition exorList.c:643
Cube * CubeExtract(Cube *p)
Definition exorList.c:843
void AddToFreeCubes(Cube *pC)
FREE CUBE LIST MANIPULATION FUNCTIONS ///.
Definition exorCubes.c:157
void CubeInsert(Cube *p)
Insertion Operators ///.
Definition exorList.c:824
int GetDistancePlus(Cube *pC1, Cube *pC2)
Definition exorBits.c:246
int ComputeQCostBits(Cube *p)
Definition exor.c:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeQCost()

int ComputeQCost ( Vec_Int_t * vCube)
extern

Definition at line 132 of file exor.c.

133{
134 int i, Entry, nLitsN = 0;
135 Vec_IntForEachEntry( vCube, Entry, i )
136 nLitsN += Abc_LitIsCompl(Entry);
137 return GetQCost( Vec_IntSize(vCube), nLitsN );
138}
int GetQCost(int nVars, int nNegs)
EXTERNAL FUNCTIONS ///.
Definition exor.c:96
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeQCostBits()

int ComputeQCostBits ( Cube * p)
extern

Definition at line 139 of file exor.c.

140{
141 extern varvalue GetVar( Cube* pC, int Var );
142 int v, nLits = 0, nLitsN = 0;
143 for ( v = 0; v < g_CoverInfo.nVarsIn; v++ )
144 {
145 int Value = GetVar( p, v );
146 if ( Value == VAR_NEG )
147 nLitsN++;
148 else if ( Value == VAR_POS )
149 nLits++;
150 }
151 nLits += nLitsN;
152 return GetQCost( nLits, nLitsN );
153}
varvalue GetVar(Cube *pC, int Var)
INLINE FUNCTION DEFINITIONS ///.
Definition exorBits.c:188
int Var
Definition exorList.c:228
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CountLiterals()

int CountLiterals ( )
extern

FUNCTION DECLARATIONS ///.

Definition at line 77 of file exorUtil.c.

78{
79 Cube* p;
80 int LitCounter = 0;
81 for ( p = IterCubeSetStart( ); p; p = IterCubeSetNext() )
82 LitCounter += p->a;
83 return LitCounter;
84}
Cube * IterCubeSetStart()
EXTERNAL FUNCTIONS ///.
Definition exorList.c:880
Cube * IterCubeSetNext()
Definition exorList.c:892
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CountQCost()

int CountQCost ( )
extern

Definition at line 119 of file exorUtil.c.

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}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DelocateCover()

void DelocateCover ( )
extern

Definition at line 147 of file exorCubes.c.

148{
151}
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ DelocateCubeSets()

void DelocateCubeSets ( )
extern

Definition at line 816 of file exorList.c.

817{
818}
Here is the caller graph for this function:

◆ DelocateQueques()

void DelocateQueques ( )
extern

Definition at line 1139 of file exorList.c.

1140{
1141 int i;
1142 for ( i = 0; i < 3; i++ )
1143 {
1144 ABC_FREE( s_Que[i].pC1 );
1145 ABC_FREE( s_Que[i].pC2 );
1146 ABC_FREE( s_Que[i].ID1 );
1147 ABC_FREE( s_Que[i].ID2 );
1148 }
1149}
Here is the caller graph for this function:

◆ FindDiffVars()

int FindDiffVars ( int * pDiffVars,
Cube * pC1,
Cube * pC2 )
extern

Definition at line 304 of file exorBits.c.

309{
310 int i, v;
311 DiffVarCounter = 0;
312 // check whether the output parts of the cubes are different
313
314 for ( i = 0; i < g_CoverInfo.nWordsOut; i++ )
315 if ( pC1->pCubeDataOut[i] != pC2->pCubeDataOut[i] )
316 { // they are different
317 pDiffVars[0] = -1;
318 DiffVarCounter = 1;
319 break;
320 }
321
322 for ( i = 0; i < g_CoverInfo.nWordsIn; i++ )
323 {
324
325 Temp1 = pC1->pCubeDataIn[i] ^ pC2->pCubeDataIn[i];
326 Temp2 = (Temp1|(Temp1>>1)) & DIFFERENT;
327
328 // check the first part of this word
329 Temp = Temp2 & 0xffff;
330 cVars = BitCount[ Temp ];
331 if ( cVars )
332 {
333 if ( cVars < 5 )
334 for ( v = 0; v < cVars; v++ )
335 {
336 assert( BitGroupNumbers[Temp] != MARKNUMBER );
337 pDiffVars[ DiffVarCounter++ ] = i*16 + GroupLiterals[ BitGroupNumbers[Temp] ][v];
338 }
339 else
340 return 5;
341 }
342 if ( DiffVarCounter > 4 )
343 return 5;
344
345 // check the second part of this word
346 Temp = Temp2 >> 16;
347 cVars = BitCount[ Temp ];
348 if ( cVars )
349 {
350 if ( cVars < 5 )
351 for ( v = 0; v < cVars; v++ )
352 {
353 assert( BitGroupNumbers[Temp] != MARKNUMBER );
354 pDiffVars[ DiffVarCounter++ ] = i*16 + 8 + GroupLiterals[ BitGroupNumbers[Temp] ][v];
355 }
356 else
357 return 5;
358 }
359 if ( DiffVarCounter > 4 )
360 return 5;
361 }
362 return DiffVarCounter;
363}
#define MARKNUMBER
Definition exorBits.c:135
unsigned char BitCount[]
Definition exorBits.c:138
drow * pCubeDataOut
Definition exor.h:130
drow * pCubeDataIn
Definition exor.h:129
Here is the caller graph for this function:

◆ GetFreeCube()

Cube * GetFreeCube ( )
extern

Definition at line 174 of file exorCubes.c.

175{
176 Cube * p;
178 p = s_CubesFree;
179 s_CubesFree = s_CubesFree->Next;
180 p->Next = NULL;
181 g_CoverInfo.nCubesFree--;
182 return p;
183}
Here is the caller graph for this function:

◆ InsertVarsWithoutClearing()

void InsertVarsWithoutClearing ( Cube * pC,
int * pVars,
int nVarsIn,
int * pVarValues,
int Output )
extern

Definition at line 388 of file exorBits.c.

392{
393 int GlobalBit;
394 int LocalWord;
395 int LocalBit;
396 int i;
397 assert( nVarsIn > 0 && nVarsIn <= g_CoverInfo.nVarsIn );
398 for ( i = 0; i < nVarsIn; i++ )
399 {
400 assert( pVars[i] >= 0 && pVars[i] < g_CoverInfo.nVarsIn );
401 assert( pVarValues[i] == VAR_NEG || pVarValues[i] == VAR_POS || pVarValues[i] == VAR_ABS );
402 GlobalBit = (pVars[i]<<1);
403 LocalWord = VarWord(GlobalBit);
404 LocalBit = VarBit(GlobalBit);
405
406 // correct this variables
407 pC->pCubeDataIn[LocalWord] |= ( pVarValues[i] << LocalBit );
408 }
409 // insert the output bit
410 pC->pCubeDataOut[VarWord(Output)] |= ( 1 << VarBit(Output) );
411}
Here is the caller graph for this function:

◆ IterativelyApplyExorLink2()

int IterativelyApplyExorLink2 ( char fDistEnable)
extern

FUNCTIONS OF THIS MODULE ///.

Definition at line 277 of file exorList.c.

281{
282 int z;
283
284 // this var is specific to ExorLink-2
285 s_Dist = (cubedist)0;
286
287 // enable pair accumulation
288 s_fDistEnable2 = fDistEnable & 1;
289 s_fDistEnable3 = fDistEnable & 2;
290 s_fDistEnable4 = fDistEnable & 4;
291
292 // initialize counters
293 s_cEnquequed = GetQuequeStats( s_Dist );
294 s_cAttempts = 0;
295 s_cReshapes = 0;
296
297 // remember the number of cubes before minimization
298 s_nCubesBefore = g_CoverInfo.nCubesInUse;
299
300 for ( z = IteratorCubePairStart( s_Dist, &s_pC1, &s_pC2 ); z; z = IteratorCubePairNext() )
301 {
302 s_cAttempts++;
303 // start ExorLink of the given Distance
304 if ( ExorLinkCubeIteratorStart( s_CubeGroup, s_pC1, s_pC2, s_Dist ) )
305 {
306 // extract old cubes from storage (to prevent EXORing with their derivitives)
307 CubeExtract( s_pC1 );
308 CubeExtract( s_pC2 );
309
310 // mark the current position in the cube pair queques
311 MarkSet();
312
313 // check the first group (generated by ExorLinkCubeIteratorStart())
314 if ( CheckForCloseCubes( s_CubeGroup[0], 0 ) )
315 { // the first cube leads to improvement - it is already inserted
316 CheckForCloseCubes( s_CubeGroup[1], 1 ); // insert the second cube
317 goto SUCCESS;
318 }
319 if ( CheckForCloseCubes( s_CubeGroup[1], 0 ) )
320 { // the second cube leads to improvement - it is already inserted
321 CheckForCloseCubes( s_CubeGroup[0], 1 ); // insert the first cube
322// CheckAndInsert( s_CubeGroup[0] );
323 goto SUCCESS;
324 }
325 // the first group does not lead to improvement
326
327 // rewind to the previously marked position in the cube pair queques
328 MarkRewind();
329
330 // generate the second group
331 ExorLinkCubeIteratorNext( s_CubeGroup );
332
333 // check the second group
334 if ( CheckForCloseCubes( s_CubeGroup[0], 0 ) )
335 { // the first cube leads to improvement - it is already inserted
336 CheckForCloseCubes( s_CubeGroup[1], 1 ); // insert the second cube
337 goto SUCCESS;
338 }
339 if ( CheckForCloseCubes( s_CubeGroup[1], 0 ) )
340 { // the second cube leads to improvement - it is already inserted
341 CheckForCloseCubes( s_CubeGroup[0], 1 ); // insert the first cube
342// CheckAndInsert( s_CubeGroup[0] );
343 goto SUCCESS;
344 }
345 // the second group does not lead to improvement
346
347 // decide whether to accept the second group, depending on literals
349 {
350 if ( g_CoverInfo.fUseQCost ?
351 s_CubeGroup[0]->q + s_CubeGroup[1]->q >= s_pC1->q + s_pC2->q :
352 s_CubeGroup[0]->a + s_CubeGroup[1]->a >= s_pC1->a + s_pC2->a )
353 // the group increases literals
354 { // do not take the last group
355
356 // rewind to the previously marked position in the cube pair queques
357 MarkRewind();
358
359 // return the old cubes back to storage
360 CubeInsert( s_pC1 );
361 CubeInsert( s_pC2 );
362 // clean the results of generating ExorLinked cubes
364 continue;
365 }
366 }
367
368 // take the last group
369 // there is no need to test these cubes again,
370 // because they have been tested and did not yield any improvement
371 CubeInsert( s_CubeGroup[0] );
372 CubeInsert( s_CubeGroup[1] );
373// CheckForCloseCubes( s_CubeGroup[0], 1 );
374// CheckForCloseCubes( s_CubeGroup[1], 1 );
375
376SUCCESS:
377 // clean the results of generating ExorLinked cubes
378 ExorLinkCubeIteratorCleanUp( 1 ); // take the last group
379 // free old cubes
380 AddToFreeCubes( s_pC1 );
381 AddToFreeCubes( s_pC2 );
382 // increate the counter
383 s_cReshapes++;
384 }
385 }
386 // print the report
387 if ( g_CoverInfo.Verbosity == 2 )
388 {
389 printf( "ExLink-%d", 2 );
390 printf( ": Que= %5d", s_cEnquequed );
391 printf( " Att= %4d", s_cAttempts );
392 printf( " Resh= %4d", s_cReshapes );
393 printf( " NoResh= %4d", s_cAttempts - s_cReshapes );
394 printf( " Cubes= %3d", g_CoverInfo.nCubesInUse );
395 printf( " (%d)", s_nCubesBefore - g_CoverInfo.nCubesInUse );
396 printf( " Lits= %5d", CountLiterals() );
397 printf( " QCost = %6d", CountQCost() );
398 printf( "\n" );
399 }
400
401 // return the number of cubes gained in the process
402 return s_nCubesBefore - g_CoverInfo.nCubesInUse;
403}
int IteratorCubePairNext()
Definition exorList.c:1073
int IteratorCubePairStart(cubedist Dist, Cube **ppC1, Cube **ppC2)
Definition exorList.c:1023
int GetQuequeStats(cubedist Dist)
Definition exorList.c:998
int ExorLinkCubeIteratorNext(Cube **pGroup)
Definition exorLink.c:560
int ExorLinkCubeIteratorStart(Cube **pGroup, Cube *pC1, Cube *pC2, cubedist Dist)
ExorLink Functions.
Definition exorLink.c:376
void ExorLinkCubeIteratorCleanUp(int fTakeLastGroup)
Definition exorLink.c:710
int CountLiterals()
FUNCTION DECLARATIONS ///.
Definition exorUtil.c:77
int CountQCost()
Definition exorUtil.c:119
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IterativelyApplyExorLink3()

int IterativelyApplyExorLink3 ( char fDistEnable)
extern

Definition at line 405 of file exorList.c.

406{
407 int z, c, d;
408 // this var is specific to ExorLink-3
409 s_Dist = (cubedist)1;
410
411 // enable pair accumulation
412 s_fDistEnable2 = fDistEnable & 1;
413 s_fDistEnable3 = fDistEnable & 2;
414 s_fDistEnable4 = fDistEnable & 4;
415
416 // initialize counters
417 s_cEnquequed = GetQuequeStats( s_Dist );
418 s_cAttempts = 0;
419 s_cReshapes = 0;
420
421 // remember the number of cubes before minimization
422 s_nCubesBefore = g_CoverInfo.nCubesInUse;
423
424 for ( z = IteratorCubePairStart( s_Dist, &s_pC1, &s_pC2 ); z; z = IteratorCubePairNext() )
425 {
426 s_cAttempts++;
427 // start ExorLink of the given Distance
428 if ( ExorLinkCubeIteratorStart( s_CubeGroup, s_pC1, s_pC2, s_Dist ) )
429 {
430 // extract old cubes from storage (to prevent EXORing with their derivitives)
431 CubeExtract( s_pC1 );
432 CubeExtract( s_pC2 );
433
434 // mark the current position in the cube pair queques
435 MarkSet();
436
437 // check cube groups one by one
438 s_GroupCounter = 0;
439 do
440 { // check the cubes of this group one by one
441 for ( c = 0; c < 3; c++ )
442 if ( !s_CubeGroup[c]->fMark ) // this cube has not yet been checked
443 {
444 s_Gain = CheckForCloseCubes( s_CubeGroup[c], 0 ); // do not insert the cube, by default
445 if ( s_Gain )
446 { // this cube leads to improvement or reshaping - it is already inserted
447
448 // decide whether to accept this group based on literal count
449 if ( s_fDecreaseLiterals && s_Gain == 1 )
450 if ( g_CoverInfo.fUseQCost ?
451 s_CubeGroup[0]->q + s_CubeGroup[1]->q + s_CubeGroup[2]->q > s_pC1->q + s_pC2->q + s_ChangeStore.PrevQq :
452 s_CubeGroup[0]->a + s_CubeGroup[1]->a + s_CubeGroup[2]->a > s_pC1->a + s_pC2->a + s_ChangeStore.PrevQa
453 ) // the group increases literals
454 { // do not take this group
455 // remember the group
456 s_GroupBest = s_GroupCounter;
457 // undo changes to be able to continue checking other groups
459 break;
460 }
461
462 // take this group
463 for ( d = 0; d < 3; d++ ) // insert other cubes
464 if ( d != c )
465 {
466 CheckForCloseCubes( s_CubeGroup[d], 1 );
467// if ( s_CubeGroup[d]->fMark )
468// CheckAndInsert( s_CubeGroup[d] );
469// CheckOnlyOneCube( s_CubeGroup[d] );
470// CheckForCloseCubes( s_CubeGroup[d], 1 );
471// else
472// CheckForCloseCubes( s_CubeGroup[d], 1 );
473 }
474
475 // clean the results of generating ExorLinked cubes
476 ExorLinkCubeIteratorCleanUp( 1 ); // take the last group
477 // free old cubes
478 AddToFreeCubes( s_pC1 );
479 AddToFreeCubes( s_pC2 );
480 // update the counter
481 s_cReshapes++;
482 goto END_OF_LOOP;
483 }
484 else // mark the cube as checked
485 s_CubeGroup[c]->fMark = 1;
486 }
487 // the group is not taken - find the new group
488 s_GroupCounter++;
489
490 // rewind to the previously marked position in the cube pair queques
491 MarkRewind();
492 }
493 while ( ExorLinkCubeIteratorNext( s_CubeGroup ) );
494 // none of the groups leads to improvement
495
496 // return the old cubes back to storage
497 CubeInsert( s_pC1 );
498 CubeInsert( s_pC2 );
499 // clean the results of generating ExorLinked cubes
501 }
502END_OF_LOOP: {}
503 }
504
505 // print the report
506 if ( g_CoverInfo.Verbosity == 2 )
507 {
508 printf( "ExLink-%d", 3 );
509 printf( ": Que= %5d", s_cEnquequed );
510 printf( " Att= %4d", s_cAttempts );
511 printf( " Resh= %4d", s_cReshapes );
512 printf( " NoResh= %4d", s_cAttempts - s_cReshapes );
513 printf( " Cubes= %3d", g_CoverInfo.nCubesInUse );
514 printf( " (%d)", s_nCubesBefore - g_CoverInfo.nCubesInUse );
515 printf( " Lits= %5d", CountLiterals() );
516 printf( " QCost = %6d", CountQCost() );
517 printf( "\n" );
518 }
519
520 // return the number of cubes gained in the process
521 return s_nCubesBefore - g_CoverInfo.nCubesInUse;
522}
void UndoRecentChanges()
Definition exorList.c:750
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IterativelyApplyExorLink4()

int IterativelyApplyExorLink4 ( char fDistEnable)
extern

Definition at line 524 of file exorList.c.

525{
526 int z, c;
527 // this var is specific to ExorLink-4
528 s_Dist = (cubedist)2;
529
530 // enable pair accumulation
531 s_fDistEnable2 = fDistEnable & 1;
532 s_fDistEnable3 = fDistEnable & 2;
533 s_fDistEnable4 = fDistEnable & 4;
534
535 // initialize counters
536 s_cEnquequed = GetQuequeStats( s_Dist );
537 s_cAttempts = 0;
538 s_cReshapes = 0;
539
540 // remember the number of cubes before minimization
541 s_nCubesBefore = g_CoverInfo.nCubesInUse;
542
543 for ( z = IteratorCubePairStart( s_Dist, &s_pC1, &s_pC2 ); z; z = IteratorCubePairNext() )
544 {
545 s_cAttempts++;
546 // start ExorLink of the given Distance
547 if ( ExorLinkCubeIteratorStart( s_CubeGroup, s_pC1, s_pC2, s_Dist ) )
548 {
549 // extract old cubes from storage (to prevent EXORing with their derivitives)
550 CubeExtract( s_pC1 );
551 CubeExtract( s_pC2 );
552
553 // mark the current position in the cube pair queques
554 MarkSet();
555
556 // check cube groups one by one
557 do
558 { // check the cubes of this group one by one
559 s_GainTotal = 0;
560 for ( c = 0; c < 4; c++ )
561 if ( !s_CubeGroup[c]->fMark ) // this cube has not yet been checked
562 {
563 s_Gain = CheckForCloseCubes( s_CubeGroup[c], 0 ); // do not insert the cube, by default
564 // if the cube leads to gain, it is already inserted
565 s_fInserted[c] = (int)(s_Gain>0);
566 // increment the total gain
567 s_GainTotal += s_Gain;
568 }
569 else
570 s_fInserted[c] = 0; // the cube has already been checked - it is not inserted
571
572 if ( s_GainTotal == 0 ) // the group does not lead to any gain
573 { // mark the cubes
574 for ( c = 0; c < 4; c++ )
575 s_CubeGroup[c]->fMark = 1;
576 }
577 else if ( s_GainTotal == 1 ) // the group does not lead to substantial gain, too
578 {
579 // undo changes to be able to continue checking groups
581 // mark those cubes that were not inserted
582 for ( c = 0; c < 4; c++ )
583 s_CubeGroup[c]->fMark = !s_fInserted[c];
584 }
585 else // if ( s_GainTotal > 1 ) // the group reshapes or improves
586 { // accept the group
587 for ( c = 0; c < 4; c++ ) // insert other cubes
588 if ( !s_fInserted[c] )
589 CheckForCloseCubes( s_CubeGroup[c], 1 );
590// CheckAndInsert( s_CubeGroup[c] );
591 // clean the results of generating ExorLinked cubes
592 ExorLinkCubeIteratorCleanUp( 1 ); // take the last group
593 // free old cubes
594 AddToFreeCubes( s_pC1 );
595 AddToFreeCubes( s_pC2 );
596 // update the counter
597 s_cReshapes++;
598 goto END_OF_LOOP;
599 }
600
601 // rewind to the previously marked position in the cube pair queques
602 MarkRewind();
603 }
604 while ( ExorLinkCubeIteratorNext( s_CubeGroup ) );
605 // none of the groups leads to improvement
606
607 // return the old cubes back to storage
608 CubeInsert( s_pC1 );
609 CubeInsert( s_pC2 );
610 // clean the results of generating ExorLinked cubes
612 }
613END_OF_LOOP: {}
614 }
615
616 // print the report
617 if ( g_CoverInfo.Verbosity == 2 )
618 {
619 printf( "ExLink-%d", 4 );
620 printf( ": Que= %5d", s_cEnquequed );
621 printf( " Att= %4d", s_cAttempts );
622 printf( " Resh= %4d", s_cReshapes );
623 printf( " NoResh= %4d", s_cAttempts - s_cReshapes );
624 printf( " Cubes= %3d", g_CoverInfo.nCubesInUse );
625 printf( " (%d)", s_nCubesBefore - g_CoverInfo.nCubesInUse );
626 printf( " Lits= %5d", CountLiterals() );
627 printf( " QCost = %6d", CountQCost() );
628 printf( "\n" );
629 }
630
631 // return the number of cubes gained in the process
632 return s_nCubesBefore - g_CoverInfo.nCubesInUse;
633}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareBitSetModule()

void PrepareBitSetModule ( )
extern

FUNCTION DEFINITIONS ///.

Definition at line 144 of file exorBits.c.

146{
147 // prepare bit count
148 int i, k;
149 int nLimit;
150
151 nLimit = FULL16BITS;
152 for ( i = 0; i < nLimit; i++ )
153 {
154 BitCount[i] = __builtin_popcount( i & 0xffff );
155 BitGroupNumbers[i] = MARKNUMBER;
156 }
157 // prepare bit groups
158 for ( k = 0; k < 163; k++ )
159 BitGroupNumbers[ SparseNumbers[k] ] = k;
160/*
161 // verify bit groups
162 int n = 4368;
163 char Buff[100];
164 cout << "The number is " << n << endl;
165 cout << "The binary is " << itoa(n,Buff,2) << endl;
166 cout << "BitGroupNumbers[n] is " << (int)BitGroupNumbers[n] << endl;
167 cout << "The group literals are ";
168 for ( int g = 0; g < 4; g++ )
169 cout << " " << (int)GroupLiterals[BitGroupNumbers[n]][g];
170*/
171}
#define FULL16BITS
Definition exorBits.c:134
Here is the caller graph for this function:

◆ WriteResultIntoFile()

int WriteResultIntoFile ( char * pFileName)
extern

Definition at line 182 of file exorUtil.c.

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}
int CountQCost()
Definition exorUtil.c:119
int CountLiteralsCheck()
Definition exorUtil.c:86
void WriteTableIntoFile(FILE *pFile)
Definition exorUtil.c:135
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ BitCount

unsigned char BitCount[]
extern

Definition at line 138 of file exorBits.c.