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

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

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

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