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

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

Partial removal of BlockNo?

File size: 3.2 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() {
19    unsigned packCount = 8 * mCodeUnitSize; 
20    unsigned codeUnitWidth = 8 * mCodeUnitSize;
21    Value * codeUnitPack[packCount];
22    for (unsigned i = 0; i < packCount; i++) {
23        Value * ptr = getInputStream("codeUnitStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
24        codeUnitPack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
25    }
26    for (unsigned j = 0; j < mCharClasses.size();  j++) {
27        Value * theCCstream = iBuilder->allZeroes();
28        for (const auto & interval : *mCharClasses[j]) {
29            Value * strmPack[packCount];
30            unsigned lo = re::lo_codepoint(interval);
31            unsigned hi = re::hi_codepoint(interval);
32            if (lo == hi) {
33                Value * cp = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo);
34                Value * cp_splat = iBuilder->simd_fill(codeUnitWidth, cp);
35                for (unsigned k = 0; k < packCount; k++) {
36                    strmPack[k] = iBuilder->simd_eq(codeUnitWidth, codeUnitPack[k], cp_splat);
37                }
38            }
39            else {
40                Value * v1 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo-1);
41                Value * lo_splat = iBuilder->simd_fill(codeUnitWidth, v1);
42                Value * v2 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), hi+1);
43                Value * hi_splat = iBuilder->simd_fill(codeUnitWidth, v2);
44                for (unsigned k = 0; k < packCount; k++) {
45                    Value * lo_test = iBuilder->simd_ugt(codeUnitWidth, codeUnitPack[k], lo_splat);
46                    Value * hi_test = iBuilder->simd_ult(codeUnitWidth, codeUnitPack[k], hi_splat);
47                    strmPack[k] = iBuilder->simd_and(lo_test, hi_test);
48                }
49            }
50            unsigned packFields = iBuilder->getBitBlockWidth()/packCount;
51            Value * pack = iBuilder->allZeroes();
52            for (unsigned k = 0; k < packCount; k++) {
53                pack = iBuilder->mvmd_insert(packFields, pack, iBuilder->CreateTrunc(iBuilder->hsimd_signmask(codeUnitWidth, strmPack[k]), iBuilder->getIntNTy(packFields)), k);
54            }
55
56            theCCstream = iBuilder->simd_or(theCCstream, pack);
57        }
58        Value * ptr = getOutputStream("ccStream", iBuilder->getInt32(j));
59        iBuilder->CreateBlockAlignedStore(theCCstream, ptr);
60    }
61}
62
63ParabixCharacterClassKernelBuilder::ParabixCharacterClassKernelBuilder (
64IDISA::IDISA_Builder * iBuilder
65, std::string ccSetName
66, const std::vector<CC *> & charClasses
67, unsigned basisBitsCount)
68: PabloKernel(iBuilder, ccSetName +"_kernel") {
69
70    CC_Compiler ccc(this, basisBitsCount);
71    auto & builder = ccc.getBuilder();
72    for (CC * cc : charClasses) {
73        Var * const r = addOutput(cc->canonicalName(re::ByteClass), getStreamSetTy());
74        builder.createAssign(r, ccc.compileCC("cc", cc, builder));
75    }
76
77}
Note: See TracBrowser for help on using the repository browser.