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

Last change on this file since 5140 was 5140, checked in by cameron, 3 years ago

Bitstream and byte space character class kernels - initial check-in

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