teddy_compile: modernise

This commit is contained in:
Justin Viiret 2016-03-02 10:32:40 +11:00 committed by Matthew Barr
parent 88e6485e75
commit 37e7c96424

View File

@ -106,8 +106,8 @@ public:
} }
printf("\nnlits: %zu\nLit ids: ", litCount()); printf("\nnlits: %zu\nLit ids: ", litCount());
printf("Prob: %llu\n", probability()); printf("Prob: %llu\n", probability());
for (set<u32>::iterator i = litIds.begin(), e = litIds.end(); i != e; ++i) { for (const auto &id : litIds) {
printf("%u ", *i); printf("%u ", id);
} }
printf("\n"); printf("\n");
printf("Flood prone : %s\n", isRunProne()?"yes":"no"); printf("Flood prone : %s\n", isRunProne()?"yes":"no");
@ -193,20 +193,18 @@ bool TeddyCompiler::pack(map<BucketIndex,
while (1) { while (1) {
#ifdef TEDDY_DEBUG #ifdef TEDDY_DEBUG
printf("Size %zu\n", sts.size()); printf("Size %zu\n", sts.size());
for (set<TeddySet>::const_iterator i1 = sts.begin(), e1 = sts.end(); i1 != e1; ++i1) { for (const TeddySet &ts : sts) {
printf("\n"); i1->dump(); printf("\n"); ts.dump();
} }
printf("\n===============================================\n"); printf("\n===============================================\n");
#endif #endif
set<TeddySet>::iterator m1 = sts.end(), m2 = sts.end(); auto m1 = sts.end(), m2 = sts.end();
u64a best = 0xffffffffffffffffULL; u64a best = 0xffffffffffffffffULL;
for (set<TeddySet>::iterator i1 = sts.begin(), e1 = sts.end(); i1 != e1; ++i1) { for (auto i1 = sts.begin(), e1 = sts.end(); i1 != e1; ++i1) {
set<TeddySet>::iterator i2 = i1;
++i2;
const TeddySet &s1 = *i1; const TeddySet &s1 = *i1;
for (set<TeddySet>::iterator e2 = sts.end(); i2 != e2; ++i2) { for (auto i2 = next(i1), e2 = sts.end(); i2 != e2; ++i2) {
const TeddySet &s2 = *i2; const TeddySet &s2 = *i2;
// be more conservative if we don't absolutely need to // be more conservative if we don't absolutely need to
@ -263,19 +261,16 @@ bool TeddyCompiler::pack(map<BucketIndex,
sts.erase(m2); sts.erase(m2);
sts.insert(nts); sts.insert(nts);
} }
u32 cnt = 0;
if (sts.size() > eng.getNumBuckets()) { if (sts.size() > eng.getNumBuckets()) {
return false; return false;
} }
for (set<TeddySet>::const_iterator i = sts.begin(), e = sts.end(); i != e; u32 cnt = 0;
++i) { for (const TeddySet &ts : sts) {
for (set<u32>::const_iterator i2 = i->getLits().begin(), const auto &lits = ts.getLits();
e2 = i->getLits().end(); bucketToLits[cnt].insert(end(bucketToLits[cnt]), begin(lits),
i2 != e2; ++i2) { end(lits));
bucketToLits[cnt].push_back(*i2);
}
cnt++; cnt++;
} }
return true; return true;
@ -350,18 +345,12 @@ TeddyCompiler::build(pair<aligned_unique_ptr<u8>, size_t> &link) {
u8 *baseMsk = teddy_base + sizeof(Teddy); u8 *baseMsk = teddy_base + sizeof(Teddy);
for (map<BucketIndex, std::vector<LiteralIndex> >::const_iterator for (const auto &b2l : bucketToLits) {
i = bucketToLits.begin(), const u32 &bucket_id = b2l.first;
e = bucketToLits.end(); const vector<LiteralIndex> &ids = b2l.second;
i != e; ++i) {
const u32 bucket_id = i->first;
const vector<LiteralIndex> &ids = i->second;
const u8 bmsk = 1U << (bucket_id % 8); const u8 bmsk = 1U << (bucket_id % 8);
for (vector<LiteralIndex>::const_iterator i2 = ids.begin(), for (const LiteralIndex &lit_id : ids) {
e2 = ids.end();
i2 != e2; ++i2) {
LiteralIndex lit_id = *i2;
const hwlmLiteral &l = lits[lit_id]; const hwlmLiteral &l = lits[lit_id];
DEBUG_PRINTF("putting lit %u into bucket %u\n", lit_id, bucket_id); DEBUG_PRINTF("putting lit %u into bucket %u\n", lit_id, bucket_id);
const u32 sz = verify_u32(l.s.size()); const u32 sz = verify_u32(l.s.size());