ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
relationGeneration.hpp
Go to the documentation of this file.
1
20
21#ifndef ABC__OPT__ESLIM__RELATIONGENERATION_h
22#define ABC__OPT__ESLIM__RELATIONGENERATION_h
23
24#include <vector>
25#include <unordered_map>
26#include <unordered_set>
27
30#include "aig/gia/gia.h"
31#include "misc/util/utilTruth.h" // ioResub.h depends on utilTruth.h
32#include "base/io/ioResub.h"
33
34#include "utils.hpp"
35// #include "satInterfaces.hpp"
36
37
39
40namespace eSLIM {
41
42 template<class Derived>
43 class RelationGenerator {
44
45 public:
46 static Abc_RData_t* computeRelation(Gia_Man_t* gia_man, const Subcircuit& subcir);
47
48 private:
49 Gia_Man_t* pGia;
50 const Subcircuit& subcir;
51
52 RelationGenerator(Gia_Man_t* pGia, const Subcircuit& subcir);
53 void setup();
54 Vec_Int_t* getRelation();
55
56 static Abc_RData_t* constructABCRelationRepresentation(Vec_Int_t * patterns, int nof_inputs, int nof_outputs);
57 // Reimplementation with disabled prints
58 // We do not want to modify code in other parts of ABC
59 static Abc_RData_t * Abc_RData2Rel( Abc_RData_t * p );
60
61
62 friend Derived;
63 };
64
65 // The class almost entirely duplicates the functionality provided by Gia_ManGenIoCombs in giaQBF.c
66 // But the implementation in this class allows to take forbidden pairs into account.
67 class RelationGeneratorABC : public RelationGenerator<RelationGeneratorABC> {
68
69 private:
70 RelationGeneratorABC(Gia_Man_t* pGia, const Subcircuit& subcir);
71 void setupImpl() {};
72 Vec_Int_t* getRelationImpl();
73 Gia_Man_t * generateMiter();
74
75 std::unordered_set<int> inputs_in_forbidden_pairs;
76
77 friend RelationGenerator;
78 };
79
80
81 // Add other engine for the generation of relations
82 // class MyRelationGenerator : public RelationGenerator<MyRelationGenerator> {
83 // private:
84 // void setupImpl()
85 // Vec_Int_t* getRelationImpl();
86 // friend RelationGenerator;
87 // };
88
89
90 template <typename T>
91 inline RelationGenerator<T>::RelationGenerator(Gia_Man_t* pGia, const Subcircuit& subcir)
92 : pGia(pGia), subcir(subcir) {
93 }
94
95 template <typename T>
97 T generator(gia_man, subcir);
98 generator.setup();
99 Vec_Int_t* relation_patterns_masks = generator.getRelation();
100 if ( relation_patterns_masks == NULL ) {
101 return nullptr;
102 }
103 int nof_inputs = subcir.nof_inputs;
104 int nof_outputs = Vec_IntSize(subcir.io) - subcir.nof_inputs;
105 Abc_RData_t* r = constructABCRelationRepresentation(relation_patterns_masks, nof_inputs, nof_outputs);
106 Vec_IntFree(relation_patterns_masks);
107 return r;
108 }
109
110 template <typename T>
111 inline Abc_RData_t* RelationGenerator<T>::constructABCRelationRepresentation(Vec_Int_t * patterns, int nof_inputs, int nof_outputs) {
112 int i, mask;
113 int nof_vars = nof_inputs + nof_outputs;
114 Abc_RData_t* p = Abc_RDataStart( nof_inputs, nof_outputs, Vec_IntSize(patterns) );
115 Vec_IntForEachEntry( patterns, mask, i ) {
116 for ( int k = 0; k < nof_vars; k++ ) {
117 if ( (mask >> (nof_vars-1-k)) & 1 ) {
118 if ( k < nof_inputs ) {
119 Abc_RDataSetIn( p, k, i );
120 } else {
121 Abc_RDataSetOut( p, 2*(k-nof_inputs)+1, i );
122 }
123 } else {
124 if ( k >= nof_inputs ) {
125 Abc_RDataSetOut( p, 2*(k-nof_inputs), i );
126 }
127 }
128 }
129 }
130 Abc_RData_t* p2 = Abc_RData2Rel(p);
131 Abc_RDataStop(p);
132 return p2;
133 }
134
135 template <typename T>
136 inline Abc_RData_t * RelationGenerator<T>::Abc_RData2Rel( Abc_RData_t * p ) {
137 assert( p->nIns < 64 );
138 assert( p->nOuts < 32 );
139 int w;
140 Vec_Wrd_t * vSimsIn2 = Vec_WrdStart( 64*p->nSimWords );
141 Vec_Wrd_t * vSimsOut2 = Vec_WrdStart( 64*p->nSimWords );
142 for ( w = 0; w < p->nIns; w++ )
143 Abc_TtCopy( Vec_WrdEntryP(vSimsIn2, w*p->nSimWords), Vec_WrdEntryP(p->vSimsIn, w*p->nSimWords), p->nSimWords, 0 );
144 for ( w = 0; w < p->nOuts; w++ )
145 Abc_TtCopy( Vec_WrdEntryP(vSimsOut2, w*p->nSimWords), Vec_WrdEntryP(p->vSimsOut, (2*w+1)*p->nSimWords), p->nSimWords, 0 );
146 Vec_Wrd_t * vTransIn = Vec_WrdStart( 64*p->nSimWords );
147 Vec_Wrd_t * vTransOut = Vec_WrdStart( 64*p->nSimWords );
148 Extra_BitMatrixTransposeP( vSimsIn2, p->nSimWords, vTransIn, 1 );
149 Extra_BitMatrixTransposeP( vSimsOut2, p->nSimWords, vTransOut, 1 );
150 Vec_WrdShrink( vTransIn, p->nPats );
151 Vec_WrdShrink( vTransOut, p->nPats );
152 Vec_Wrd_t * vTransInCopy = Vec_WrdDup(vTransIn);
153 Vec_WrdUniqify( vTransInCopy );
154 // if ( Vec_WrdSize(vTransInCopy) == p->nPats )
155 // printf( "This resub problem is not a relation.\n" );
156 // create the relation
157 Abc_RData_t * pNew = Abc_RDataStart( p->nIns, 1 << (p->nOuts-1), Vec_WrdSize(vTransInCopy) );
158 pNew->nOuts = p->nOuts;
159 int i, k, n, iLine = 0; word Entry, Entry2;
160 Vec_WrdForEachEntry( vTransInCopy, Entry, i ) {
161 for ( n = 0; n < p->nIns; n++ )
162 if ( (Entry >> n) & 1 )
163 Abc_InfoSetBit( (unsigned *)Vec_WrdEntryP(pNew->vSimsIn, n*pNew->nSimWords), iLine );
164 Vec_WrdForEachEntry( vTransIn, Entry2, k ) {
165 if ( Entry != Entry2 )
166 continue;
167 Entry2 = Vec_WrdEntry( vTransOut, k );
168 assert( Entry2 < (1 << p->nOuts) );
169 Abc_InfoSetBit( (unsigned *)Vec_WrdEntryP(pNew->vSimsOut, Entry2*pNew->nSimWords), iLine );
170 }
171 iLine++;
172 }
173 assert( iLine == pNew->nPats );
174 Vec_WrdFree( vTransOut );
175 Vec_WrdFree( vTransInCopy );
176 Vec_WrdFree( vTransIn );
177 Vec_WrdFree( vSimsIn2 );
178 Vec_WrdFree( vSimsOut2 );
179 return pNew;
180 }
181
182 template <typename T>
183 inline void RelationGenerator<T>::setup() {
184 static_cast<T*>(this)->setupImpl();
185 }
186
187 template <typename T>
188 inline Vec_Int_t* RelationGenerator<T>::getRelation() {
189 return static_cast<T*>(this)->getRelationImpl();
190 }
191}
192
194
195#endif
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ABC_NAMESPACE_HEADER_START typedef uint64_t generator
Definition random.h:12
static Abc_RData_t * computeRelation(Gia_Man_t *gia_man, const Subcircuit &subcir)
Cube * p
Definition exorList.c:222
ABC_NAMESPACE_IMPL_START void Extra_BitMatrixTransposeP(Vec_Wrd_t *vSimsIn, int nWordsIn, Vec_Wrd_t *vSimsOut, int nWordsOut)
DECLARATIONS ///.
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
typedefABC_NAMESPACE_HEADER_START struct Abc_RData_t_ Abc_RData_t
INCLUDES ///.
Definition ioResub.h:40
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecWrd.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42