source: icGREP/icgrep-devel/icgrep/kernels/unicode_linebreak_kernel.cpp @ 5353

Last change on this file since 5353 was 5350, checked in by nmedfort, 3 years ago

First attempt at inlining all DoBlock? and FinalBlock? functions by using indirect jumps. Disabled for NVPTX until Linda can check whether they're supported by the LLVM NVPTX library.

File size: 2.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 "unicode_linebreak_kernel.h"
7#include <re/re_cc.h>
8#include <pablo/pe_ones.h>          // for Ones
9#include <pablo/pe_var.h>           // for Var
10#include <pablo/pe_zeroes.h>        // for Zeroes
11#include <cc/cc_compiler.h>
12#include <pablo/builder.hpp>
13#include <llvm/IR/Module.h>
14
15using namespace cc;
16using namespace kernel;
17using namespace pablo;
18using namespace re;
19using namespace llvm;
20
21UnicodeLineBreakKernelBuilder::UnicodeLineBreakKernelBuilder (
22IDISA::IDISA_Builder * iBuilder
23, std::string unicodelinebreak
24, unsigned basisBitsCount)
25: PabloKernel(iBuilder, unicodelinebreak +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}) {
26
27    CC_Compiler ccc(this, getInput(0));
28    auto & builder = ccc.getBuilder();
29   
30    PabloAST * LF = ccc.compileCC("LF", makeCC(0x0A), builder);
31    PabloAST * CR = ccc.compileCC(makeCC(0x0D));
32    PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
33
34    Zeroes * const zero = builder.createZeroes();
35    Var * crlf = builder.createVar("crlf", zero);
36    PabloBuilder crb = PabloBuilder::Create(builder);
37    PabloAST * cr1 = crb.createAdvance(CR, 1, "cr1");
38    crb.createAssign(crlf, crb.createAnd(cr1, LF));
39    builder.createIf(CR, crb);
40   
41    Var * NEL_LS_PS = builder.createVar("NEL_LS_PS", zero);
42
43    PabloAST * u8pfx = ccc.compileCC(makeCC(0xC0, 0xFF));
44    PabloBuilder it = PabloBuilder::Create(builder);
45    builder.createIf(u8pfx, it);
46    PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF), it);
47    PabloAST * u8pfx3 = ccc.compileCC(makeCC(0xE0, 0xEF), it);
48
49    //
50    // Two-byte sequences
51    Var * NEL = it.createVar("NEL", zero);
52    PabloBuilder it2 = PabloBuilder::Create(it);
53    it2.createAssign(NEL, it2.createAnd(it2.createAdvance(ccc.compileCC(makeCC(0xC2), it2), 1), ccc.compileCC(makeCC(0x85), it2)));
54    it.createIf(u8pfx2, it2);
55
56    //
57    // Three-byte sequences
58
59    Var * LS_PS = it.createVar("LS_PS", zero);
60    PabloBuilder it3 = PabloBuilder::Create(it);
61    it.createIf(u8pfx3, it3);
62    PabloAST * E2_80 = it3.createAnd(it3.createAdvance(ccc.compileCC(makeCC(0xE2), it3), 1), ccc.compileCC(makeCC(0x80), it3));
63    it3.createAssign(LS_PS, it3.createAnd(it3.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9), it3)));
64    it.createAssign(NEL_LS_PS, it.createOr(NEL, LS_PS));
65
66
67    PabloAST * LB_chars = builder.createOr(LF_VT_FF_CR, NEL_LS_PS);
68    PabloAST * UnicodeLineBreak = builder.createAnd(LB_chars, builder.createNot(crlf));  // count the CR, but not CRLF
69    Var * const r = addOutput("unicodeLineBreak", getStreamTy());
70    builder.createAssign(r, UnicodeLineBreak);
71}
Note: See TracBrowser for help on using the repository browser.