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

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

Code clean up to enforce proper calling order of KernelBuilder? methods

File size: 3.8 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
11using namespace cc;
12using namespace kernel;
13using namespace pablo;
14using namespace re;
15
16void DirectCharacterClassKernelBuilder::generateDoBlockMethod() const {
17    auto savePoint = iBuilder->saveIP();
18    Module * m = iBuilder->getModule();
19
20    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
21   
22    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
23   
24    Value * self = getParameter(doBlockFunction, "self");
25    Value * blockNo = getScalarField(self, blockNoScalar);
26   
27    Value * codeUnitStreamBlock_ptr = getStreamSetBlockPtr(self, "codeUnitStream", blockNo);
28    Value * ccStreamBlock_ptr = getStreamSetBlockPtr(self, "ccStream", blockNo);
29
30    unsigned packCount = 8 * mCodeUnitSize; 
31    unsigned codeUnitWidth = 8 * mCodeUnitSize;
32    Value * codeUnitPack[packCount];
33    for (unsigned i = 0; i < packCount; i++) {
34        codeUnitPack[i] = iBuilder->CreateBlockAlignedLoad(codeUnitStreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
35    }
36
37    std::vector<Value *> ccStreams;
38    for (unsigned j = 0; j < mCharClasses.size();  j++) {
39        Value * theCCstream = iBuilder->allZeroes();
40        for (const auto & interval : *mCharClasses[j]) {
41            Value * strmPack[packCount];
42            unsigned lo = re::lo_codepoint(interval);
43            unsigned hi = re::hi_codepoint(interval);
44            if (lo == hi) {
45                Value * cp = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo);
46                Value * cp_splat = iBuilder->simd_fill(codeUnitWidth, cp);
47                for (unsigned k = 0; k < packCount; k++) {
48                    strmPack[k] = iBuilder->simd_eq(codeUnitWidth, codeUnitPack[k], cp_splat);
49                }
50            }
51            else {
52                Value * v1 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo-1);
53                Value * lo_splat = iBuilder->simd_fill(codeUnitWidth, v1);
54                Value * v2 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), hi+1);
55                Value * hi_splat = iBuilder->simd_fill(codeUnitWidth, v2);
56                for (unsigned k = 0; k < packCount; k++) {
57                    Value * lo_test = iBuilder->simd_ugt(codeUnitWidth, codeUnitPack[k], lo_splat);
58                    Value * hi_test = iBuilder->simd_ult(codeUnitWidth, codeUnitPack[k], hi_splat);
59                    strmPack[k] = iBuilder->simd_and(lo_test, hi_test);
60                }
61            }
62            unsigned packFields = iBuilder->getBitBlockWidth()/packCount;
63            Value * pack = iBuilder->allZeroes();
64            for (unsigned k = 0; k < packCount; k++) {
65                pack = iBuilder->mvmd_insert(packFields, pack, iBuilder->CreateTrunc(iBuilder->hsimd_signmask(codeUnitWidth, strmPack[k]), iBuilder->getIntNTy(packFields)), k);
66            }
67
68            theCCstream = iBuilder->simd_or(theCCstream, pack);
69        }
70        iBuilder->CreateBlockAlignedStore(theCCstream, ccStreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
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.