Changeset 5823


Ignore:
Timestamp:
Jan 9, 2018, 12:01:46 PM (7 months ago)
Author:
cameron
Message:

Direct CC compiler

Location:
icGREP/icgrep-devel/icgrep
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/alphabet.h

    r5816 r5823  
    7373    }
    7474    static inline bool classof(const void *) {return false;}
    75     uint8_t getCodeUnitBitWidth() { return mCodeUnitBits;}
     75    uint8_t getCodeUnitBitWidth() const { return mCodeUnitBits;}
    7676    const unsigned getSize() const override {return 1<<mCodeUnitBits;}
    7777
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5814 r5823  
    11/*
    2  *  Copyright (c) 2014 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    66
    77#include "cc_compiler.h"
     8#include <cc/alphabet.h>
    89#include <pablo/codegenstate.h>
    910#include <pablo/boolean.h>
     
    228229}
    229230
     231   
     232PabloAST * compileCCfromCodeUnitStream(const CC *cc, PabloAST * codeUnitStream, PabloBuilder & pb) {
     233    const Alphabet * a = cc->getAlphabet();
     234    if (!isa<CodeUnitAlphabet>(a)) {
     235        llvm::report_fatal_error("compileCCfromCodeUnitStream must be applied to a CC with a CodeUnitAlphabet");
     236    }
     237    unsigned codeUnitWidth = cast<const CodeUnitAlphabet>(a)->getCodeUnitBitWidth();
     238    unsigned topBit = 1 << codeUnitWidth;
     239    unsigned maxCodeVal = (topBit - 1) | topBit;
     240    PabloAST * ccStrm = pb.createZeroes();
     241#ifdef PABLO_ALL
     242    for (const auto & interval : *cc) {
     243        unsigned lo = re::lo_codepoint(interval);
     244        unsigned hi = re::hi_codepoint(interval);
     245        if (lo == hi) {
     246            PabloAST * testVal = pb.createAll(codeUnitWidth, lo);
     247            ccStrm = pb.createOr(ccStrm, pb.createEqual(codeUnitStream, testVal));
     248        } else if (lo == 0) {
     249            if (hi == maxCodeVal) {
     250                // All code units
     251                ccStrm = pb.createOnes();
     252            } else {
     253                PabloAST * testVal = pb.createAll(codeUnitWidth, hi+1);
     254                ccStrm = pb.createOr(ccStrm, pb.createLessThan(codeUnitStream, testVal));
     255            }
     256        } else if (hi == maxCodeVal) {
     257            PabloAST * testVal = pb.createAll(codeUnitWidth, lo);
     258            ccStrm = pb.createOr(ccStrm, pb.createNot(pb.createLessThan(codeUnitStream, testVal));)
     259        } else {
     260            PabloAST * testVal_lo = pb.createAll(codeUnitWidth, lo);
     261            PabloAST * testVal_hi = pb.createAll(codeUnitWidth, hi+1);
     262            ccStrm = pb.createOr(ccStrm, pb.createAnd(pb.createNot(pb.createLessThan(codeUnitStream, testVal_lo)),
     263                                                      pb.createLessThan(codeUnitStream, testVal_hi)));
     264        }
     265    }
     266#endif
     267    return ccStrm;
     268}
    230269} // end of namespace cc
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5781 r5823  
    8585}
    8686
     87pablo::PabloAST * compileCCfromCodeUnitStream(const re::CC *cc, pablo::PabloAST * codeUnitStream, pablo::PabloBuilder & pb);
     88   
    8789}
    8890
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp

    r5781 r5823  
    1919        const std::unique_ptr<kernel::KernelBuilder> & b, std::string ccSetName, std::vector<re::CC *> charClasses, unsigned codeUnitSize)
    2020: BlockOrientedKernel(std::move(ccSetName),
    21               {Binding{b->getStreamSetTy(1, 8 * codeUnitSize), "codeUnitStream"}},
     21              {Binding{b->getStreamSetTy(1, 8 * codeUnitSize), "codeUnitStream", FixedRate(), Principal()}},
    2222              {Binding{b->getStreamSetTy(charClasses.size(), 1), "ccStream"}},
    2323              {}, {}, {})
     
    3030    unsigned packCount = 8 * mCodeUnitSize; 
    3131    unsigned codeUnitWidth = 8 * mCodeUnitSize;
     32    unsigned topBit = 1 << codeUnitWidth;
     33    unsigned maxCodeVal = (topBit - 1) | topBit;
    3234    Value * codeUnitPack[packCount];
    3335    for (unsigned i = 0; i < packCount; i++) {
     
    4648                    strmPack[k] = iBuilder->simd_eq(codeUnitWidth, codeUnitPack[k], cp_splat);
    4749                }
    48             }
    49             else {
     50            } else if (lo == 0) {
     51                if (hi == maxCodeVal) {
     52                    for (unsigned k = 0; k < packCount; k++) {
     53                        strmPack[k] = iBuilder->allOnes();
     54                    }
     55                } else {
     56                    Value * cp = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), hi + 1);
     57                    Value * cp_splat = iBuilder->simd_fill(codeUnitWidth, cp);
     58                    for (unsigned k = 0; k < packCount; k++) {
     59                        strmPack[k] = iBuilder->simd_ult(codeUnitWidth, codeUnitPack[k], cp_splat);
     60                    }
     61                }
     62            } else if (hi == maxCodeVal) {
     63                Value * cp = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo - 1);
     64                Value * cp_splat = iBuilder->simd_fill(codeUnitWidth, cp);
     65                for (unsigned k = 0; k < packCount; k++) {
     66                    strmPack[k] = iBuilder->simd_ugt(codeUnitWidth, codeUnitPack[k], cp_splat);
     67                }
     68            } else {
    5069                Value * v1 = ConstantInt::get(iBuilder->getIntNTy(codeUnitWidth), lo-1);
    5170                Value * lo_splat = iBuilder->simd_fill(codeUnitWidth, v1);
Note: See TracChangeset for help on using the changeset viewer.