source: icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp @ 5267

Last change on this file since 5267 was 5267, checked in by nmedfort, 2 years ago

Code clean-up. Removed Pablo Call, SetIthBit? and Prototype.

File size: 3.7 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "cc_kernel.h"
7#include <re/re_cc.h>
8#include <cc/cc_compiler.h>
9#include <pablo/builder.hpp>
10#include <llvm/IR/Module.h>
11
12using namespace cc;
13using namespace kernel;
14using namespace pablo;
15using namespace re;
16using namespace llvm;
17
18void DirectCharacterClassKernelBuilder::generateDoBlockMethod() const {
19    auto savePoint = iBuilder->saveIP();
20    Module * m = iBuilder->getModule();
21
22    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
23   
24    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
25   
26    Value * self = getParameter(doBlockFunction, "self");
27    Value * blockNo = getScalarField(self, blockNoScalar);
28   
29    unsigned packCount = 8 * mCodeUnitSize; 
30    unsigned codeUnitWidth = 8 * mCodeUnitSize;
31    Value * codeUnitPack[packCount];
32    for (unsigned i = 0; i < packCount; i++) {
33        Value * ptr = getStream(self, "codeUnitStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
34        codeUnitPack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
35    }
36
37    for (unsigned j = 0; j < mCharClasses.size();  j++) {
38        Value * theCCstream = iBuilder->allZeroes();
39        for (const auto & interval : *mCharClasses[j]) {
40            Value * strmPack[packCount];
41            unsigned lo = re::lo_codepoint(interval);
42            unsigned hi = re::hi_codepoint(interval);
43            if (lo == hi) {
44                Value * cp = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo);
45                Value * cp_splat = iBuilder->simd_fill(codeUnitWidth, cp);
46                for (unsigned k = 0; k < packCount; k++) {
47                    strmPack[k] = iBuilder->simd_eq(codeUnitWidth, codeUnitPack[k], cp_splat);
48                }
49            }
50            else {
51                Value * v1 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo-1);
52                Value * lo_splat = iBuilder->simd_fill(codeUnitWidth, v1);
53                Value * v2 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), hi+1);
54                Value * hi_splat = iBuilder->simd_fill(codeUnitWidth, v2);
55                for (unsigned k = 0; k < packCount; k++) {
56                    Value * lo_test = iBuilder->simd_ugt(codeUnitWidth, codeUnitPack[k], lo_splat);
57                    Value * hi_test = iBuilder->simd_ult(codeUnitWidth, codeUnitPack[k], hi_splat);
58                    strmPack[k] = iBuilder->simd_and(lo_test, hi_test);
59                }
60            }
61            unsigned packFields = iBuilder->getBitBlockWidth()/packCount;
62            Value * pack = iBuilder->allZeroes();
63            for (unsigned k = 0; k < packCount; k++) {
64                pack = iBuilder->mvmd_insert(packFields, pack, iBuilder->CreateTrunc(iBuilder->hsimd_signmask(codeUnitWidth, strmPack[k]), iBuilder->getIntNTy(packFields)), k);
65            }
66
67            theCCstream = iBuilder->simd_or(theCCstream, pack);
68        }
69        Value * ptr = getStream(self, "ccStream", blockNo, iBuilder->getInt32(j));
70        iBuilder->CreateBlockAlignedStore(theCCstream, ptr);
71    }
72 
73    iBuilder->CreateRetVoid();
74    iBuilder->restoreIP(savePoint);
75}
76
77ParabixCharacterClassKernelBuilder::ParabixCharacterClassKernelBuilder (
78IDISA::IDISA_Builder * iBuilder
79, std::string ccSetName
80, const std::vector<CC *> & charClasses
81, unsigned basisBitsCount)
82: PabloKernel(iBuilder, ccSetName +"_kernel") {
83
84    CC_Compiler ccc(this, basisBitsCount);
85    auto & builder = ccc.getBuilder();
86    for (CC * cc : charClasses) {
87        Var * const r = addOutput(cc->canonicalName(re::ByteClass), getStreamSetTy());
88        builder.createAssign(r, ccc.compileCC("cc", cc, builder));
89    }
90
91}
Note: See TracBrowser for help on using the repository browser.