source: icGREP/icgrep-devel/icgrep/kernels/match_count.cpp @ 5353

Last change on this file since 5353 was 5343, checked in by lindanl, 2 years ago

Add count only option for separate compilation of multiple kernels.

File size: 1.4 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "match_count.h"
7#include <IR_Gen/idisa_builder.h>
8#include <llvm/IR/Value.h>
9
10using namespace llvm;
11
12namespace kernel {
13
14MatchCount::MatchCount(IDISA::IDISA_Builder * iBuilder)
15    : BlockOrientedKernel(iBuilder, "matchCount", 
16                        {Binding{iBuilder->getStreamSetTy(1, 1), "matches"}}, {}, {}, {Binding{iBuilder->getSizeTy(), "matchedLineCount"}}, {}) {
17    }
18
19void MatchCount::generateDoBlockMethod() {
20
21    const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
22    Value * to_count = loadInputStreamBlock("matches", iBuilder->getInt32(0));
23    Value * count = getScalarField("matchedLineCount");
24   
25    Value * value = nullptr;
26    Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
27    if (LLVM_UNLIKELY(counterSize <= 1)) {
28        value = partial;
29    } else {
30        value = iBuilder->mvmd_extract(counterSize, partial, 0);
31        const auto fields = (iBuilder->getBitBlockWidth() / counterSize);
32        for (unsigned i = 1; i < fields; ++i) {
33            Value * temp = iBuilder->mvmd_extract(counterSize, partial, i);
34            value = iBuilder->CreateAdd(value, temp);
35        }
36    }
37    value = iBuilder->CreateAdd(value, count);
38    setScalarField("matchedLineCount", value);
39}
40
41
42}
Note: See TracBrowser for help on using the repository browser.