Changeset 4797 for icGREP/icgrepdevel/icgrep/cc/cc_compiler.cpp
 Timestamp:
 Sep 27, 2015, 1:32:27 AM (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

icGREP/icgrepdevel/icgrep/cc/cc_compiler.cpp
r4788 r4797 133 133 134 134 template<typename PabloBlockOrBuilder> 135 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBlockOrBuilder &pb) 136 { 137 if (selected_bits == 0) { 138 return pb.createOnes(); 139 } 140 141 std::vector<PabloAST*> bit_terms; 142 for (unsigned i = 0; selected_bits; ++i) { 143 unsigned test_bit = static_cast<unsigned>(1) << i; 144 if ((selected_bits & test_bit) != 0) { 145 if ((pattern & test_bit) == 0) { 146 bit_terms.push_back(pb.createNot(getBasisVar(i))); 147 } 148 else { 149 bit_terms.push_back(getBasisVar(i)); 150 } 151 } 152 else { 153 bit_terms.push_back(pb.createOnes()); 154 } 155 selected_bits &= ~test_bit; 156 } 157 158 if (bit_terms.size() > 1) { 159 //Reduce the list so that all of the expressions are contained within a single expression. 160 std::vector<PabloAST*> new_terms; 161 new_terms.reserve(bit_terms.size() / 2); 162 do { 163 for (auto i = 0; i < (bit_terms.size() / 2); i++) { 164 new_terms.push_back(pb.createAnd(bit_terms[(2 * i) + 1], bit_terms[2 * i])); 165 } 166 if (bit_terms.size() % 2 == 1) { 167 new_terms.push_back(bit_terms[bit_terms.size()  1]); 168 } 169 bit_terms.swap(new_terms); 170 new_terms.clear(); 171 } 172 while (bit_terms.size() > 1); 173 } 174 return bit_terms[0]; 135 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, PabloBlockOrBuilder & pb) { 136 if (LLVM_UNLIKELY(selected_bits == 0)) { 137 return PabloBlock::createOnes(); 138 } else { 139 std::vector<PabloAST*> terms; 140 for (unsigned i = 0; selected_bits; ++i) { 141 unsigned test_bit = static_cast<unsigned>(1) << i; 142 PabloAST * term = PabloBlock::createOnes(); 143 if (selected_bits & test_bit) { 144 term = getBasisVar(i); 145 if ((pattern & test_bit) == 0) { 146 term = pb.createNot(term); 147 } 148 selected_bits ^= test_bit; 149 } 150 terms.push_back(term); 151 } 152 if (terms.size() > 1) { 153 //Reduce the list so that all of the expressions are contained within a single expression. 154 std::vector<PabloAST*> temp; 155 temp.reserve(terms.size()); 156 do { 157 for (unsigned i = 0; i < (terms.size() / 2); i++) { 158 temp.push_back(pb.createAnd(terms[2 * i], terms[(2 * i) + 1])); 159 } 160 if (terms.size() % 2 == 1) { 161 temp.push_back(terms.back()); 162 } 163 terms.swap(temp); 164 temp.clear(); 165 } 166 while (terms.size() > 1); 167 } 168 assert (terms.size() == 1); 169 return terms.front(); 170 } 175 171 } 176 172 … … 269 265 270 266 inline Var * CC_Compiler::getBasisVar(const int i) const { 267 assert (i >= 0 && i < mEncoding.getBits()); 271 268 return mBasisBit[mEncoding.getBits()  i  1]; 272 269 }
Note: See TracChangeset
for help on using the changeset viewer.