Changeset 5629


Ignore:
Timestamp:
Sep 7, 2017, 7:10:42 AM (3 months ago)
Author:
cameron
Message:

Popcount improvement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5628 r5629  
    521521            value = iBuilder->simd_and(compileExpression(iBuilder, e->getExpr()), EOFbit);
    522522        } else if (const Count * c = dyn_cast<Count>(stmt)) {
    523         Value * EOFbit = iBuilder->getScalarField("EOFbit");
    524         Value * EOFmask = iBuilder->getScalarField("EOFmask");
    525         Value * const to_count = iBuilder->simd_and(iBuilder->simd_or(iBuilder->simd_not(EOFmask), EOFbit), compileExpression(iBuilder, c->getExpr()));
     523            Value * EOFbit = iBuilder->getScalarField("EOFbit");
     524            Value * EOFmask = iBuilder->getScalarField("EOFmask");
     525            Value * const to_count = iBuilder->simd_and(iBuilder->simd_or(iBuilder->simd_not(EOFmask), EOFbit), compileExpression(iBuilder, c->getExpr()));
    526526            const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
    527527            const auto f = mAccumulator.find(c);
     
    531531            Value * ptr = iBuilder->getScalarFieldPtr(f->second);
    532532            const auto alignment = getPointerElementAlignment(ptr);
    533             Value * count = iBuilder->CreateAlignedLoad(ptr, alignment, c->getName() + "_accumulator");
    534             Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
    535             if (LLVM_UNLIKELY(counterSize <= 1)) {
    536                 value = partial;
    537             } else {
    538                 value = iBuilder->mvmd_extract(counterSize, partial, 0);
    539                 const auto fields = (iBuilder->getBitBlockWidth() / counterSize);
    540                 for (unsigned i = 1; i < fields; ++i) {
    541                     Value * temp = iBuilder->mvmd_extract(counterSize, partial, i);
    542                     value = iBuilder->CreateAdd(value, temp);
    543                 }
    544             }
    545             value = iBuilder->CreateAdd(value, count);
     533            Value * countSoFar = iBuilder->CreateAlignedLoad(ptr, alignment, c->getName() + "_accumulator");
     534            auto fields = (iBuilder->getBitBlockWidth() / counterSize);
     535            Value * fieldCounts = iBuilder->simd_popcount(counterSize, to_count);
     536            while (fields > 1) {
     537                fields = fields/2;
     538                fieldCounts = iBuilder->CreateAdd(fieldCounts, iBuilder->mvmd_srli(counterSize, fieldCounts, fields));
     539            }
     540            value = iBuilder->CreateAdd(iBuilder->mvmd_extract(counterSize, fieldCounts, 0), countSoFar, "countSoFar");
    546541            iBuilder->CreateAlignedStore(value, ptr, alignment);
    547542        } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
Note: See TracChangeset for help on using the changeset viewer.