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

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

memcpy/memset support for 32-bit systems; more error messages/handling; bug fix for ParabixCharacterClassKernelBuilder?. continued work on parenthesis matching + expandable buffers.

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