Ignore:
Timestamp:
May 7, 2017, 4:34:48 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work. PabloKernel? now abstract base type with a 'generatePabloMethod' hook to generate Pablo code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5435 r5436  
    55 */
    66
    7 #include <IR_Gen/idisa_builder.h>                  // for IDISA_Builder
    87#include <IR_Gen/idisa_target.h>                   // for GetIDISA_Builder
    98#include <cc/cc_compiler.h>                        // for CC_Compiler
     
    2221#include <pablo/pablo_kernel.h>                    // for PabloKernel
    2322#include <pablo/pablo_toolchain.h>                 // for pablo_function_passes
     23#include <kernels/kernel_builder.h>
    2424#include <pablo/pe_zeroes.h>
    2525#include <toolchain/toolchain.h>
     
    4848static cl::opt<bool> memAlignBuffering("memalign-buffering", cl::desc("Enable posix_memalign buffering."), cl::cat(u8u16Options));
    4949
    50 
    51 std::unique_ptr<PabloKernel> u8u16_pablo(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder) {
    52 
    53     auto kernel = std::unique_ptr<PabloKernel>(new PabloKernel(iBuilder, "u8u16",
    54                        {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
    55                        {Binding{iBuilder->getStreamSetTy(16, 1), "u16bit"},
    56                            Binding{iBuilder->getStreamSetTy(1, 1), "delMask"},
    57                            Binding{iBuilder->getStreamSetTy(1, 1), "errMask"}}, {}));
    58    
    59     kernel->setBuilder(iBuilder.get());
     50class U8U16Kernel final: public pablo::PabloKernel {
     51public:
     52    U8U16Kernel(const std::unique_ptr<kernel::KernelBuilder> & b);
     53    bool isCachable() const override { return true; }
     54    bool moduleIDisSignature() const override { return true; }
     55    void generatePabloMethod() override;
     56};
     57
     58U8U16Kernel::U8U16Kernel(const std::unique_ptr<kernel::KernelBuilder> & b)
     59: PabloKernel(b, "u8u16",
     60{Binding{b->getStreamSetTy(8, 1), "u8bit"}},
     61{Binding{b->getStreamSetTy(16, 1), "u16bit"}, Binding{b->getStreamSetTy(1, 1), "delMask"}, Binding{b->getStreamSetTy(1, 1), "errMask"}}) {
     62
     63}
     64
     65void U8U16Kernel::generatePabloMethod() {
    6066
    6167    //  input: 8 basis bit streams
    62    
    63     const auto u8bitSet = kernel->getInputStreamVar("u8bit");
    64    
     68
     69    const auto u8bitSet = getInputStreamVar("u8bit");
     70
    6571    //  output: 16 u8-indexed streams, + delmask stream + error stream
    66    
    67     cc::CC_Compiler ccc(kernel.get(), u8bitSet);
    68    
     72
     73    cc::CC_Compiler ccc(this, u8bitSet);
     74
    6975    PabloBuilder & main = ccc.getBuilder();
    7076    const auto u8_bits = ccc.getBasisBits();
    71    
     77
    7278    Zeroes * zeroes = main.createZeroes();
    7379
     
    8692    // The logic for processing non-ASCII bytes will be embedded within an if-hierarchy.
    8793    PabloAST * nonASCII = ccc.compileCC(re::makeCC(0x80, 0xFF));
    88    
     94
    8995    // Builder for the if statement handling all non-ASCII logic
    9096    PabloBuilder nAb = PabloBuilder::Create(main);
    9197    // Bits 3 through 7 of a 2-byte prefix are data bits, needed to
    92     // produce the UTF-16 code unit data ..., 
     98    // produce the UTF-16 code unit data ...,
    9399    PabloAST * bit3a1 = nAb.createAdvance(u8_bits[3], 1);
    94100    PabloAST * bit4a1 = nAb.createAdvance(u8_bits[4], 1);
     
    96102    PabloAST * bit6a1 = nAb.createAdvance(u8_bits[6], 1);
    97103    PabloAST * bit7a1 = nAb.createAdvance(u8_bits[7], 1);
    98    
     104
    99105    // Entry condition for 3 or 4 byte sequences: we have a prefix byte in the range 0xE0-0xFF.
    100106    PabloAST * pfx34 = ccc.compileCC(re::makeCC(0xE0, 0xFF), nAb);
     
    109115    PabloAST * bit7a2 = p34b.createAdvance(bit7a1, 1);
    110116
    111 
    112117    Var * const u8scope32 = nAb.createVar("u8scope32", zeroes);
    113118    Var * const u8scope33 = nAb.createVar("u8scope33", zeroes);
     
    140145    p4b.createAssign(u8scope44, p4b.createAdvance(u8scope43, 1));
    141146    //
    142    
     147
    143148    //  From the 4-byte sequence 11110abc 10defghi 10jklmno 10pqrstu,
    144149    //  we must calculate the value abcde - 1 to produce the bit values
     
    190195    // Two surrogate UTF-16 units are computed at the 3rd and 4th positions of 4-byte sequences.
    191196    PabloAST * surrogate = p34b.createOr(u8scope43, u8scope44);
    192    
     197
    193198    Var * p34del = nAb.createVar("p34del", zeroes);
    194199    p34b.createAssign(p34del, p34b.createOr(u8scope32, u8scope42));
     
    202207    p34b.createAssign(u16_hi[3], p34b.createOr(p34b.createAnd(u8scope33, bit7a2), surrogate));
    203208    p34b.createAssign(u16_hi[4], p34b.createOr(p34b.createAnd(u8scope33, bit2a1), surrogate));
    204    
     209
    205210    //
    206211    nAb.createIf(pfx34, p34b);
     
    220225    nAb.createAssign(error_mask, nAb.createOr(scope_suffix_mismatch, nAb.createOr(C0_C1_err, EX_FX_err)));
    221226    nAb.createAssign(delmask, nAb.createOr(p34del, ccc.compileCC(re::makeCC(0xC0, 0xFF), nAb)));
    222    
     227
    223228    // The low 3 bits of the high byte of the UTF-16 code unit as well as the high bit of the
    224229    // low byte are only nonzero for 2, 3 and 4 byte sequences.
     
    244249    main.createAssign(u16_lo[6], main.createOr(main.createAnd(last_byte, u8_bits[6]), s43_lo6));
    245250    main.createAssign(u16_lo[7], main.createOr(main.createAnd(last_byte, u8_bits[7]), s43_lo7));
    246    
    247     Var * output = kernel->getOutputStreamVar("u16bit");
    248     Var * delmask_out = kernel->getOutputStreamVar("delMask");
    249     Var * error_mask_out = kernel->getOutputStreamVar("errMask");
    250    
     251
     252    Var * output = getOutputStreamVar("u16bit");
     253    Var * delmask_out = getOutputStreamVar("delMask");
     254    Var * error_mask_out = getOutputStreamVar("errMask");
     255
    251256    for (unsigned i = 0; i < 8; i++) {
    252257        main.createAssign(main.createExtract(output, i), u16_hi[i]);
     
    257262    main.createAssign(main.createExtract(delmask_out, main.getInteger(0)), delmask);
    258263    main.createAssign(main.createExtract(error_mask_out,  main.getInteger(0)), error_mask);
    259 
    260     pablo_function_passes(kernel.get());
    261     return kernel;
    262264}
    263265
     
    304306    StreamSetBuffer * ErrorMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    305307   
    306     Kernel * u8u16k = pxDriver.addKernelInstance(u8u16_pablo(iBuilder));
     308    Kernel * u8u16k = pxDriver.addKernelInstance(make_unique<U8U16Kernel>(iBuilder));
    307309    pxDriver.makeKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
    308310   
     
    397399    StreamSetBuffer * ErrorMask = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments));
    398400   
    399     Kernel * u8u16k = pxDriver.addKernelInstance(u8u16_pablo(iBuilder));
     401    Kernel * u8u16k = pxDriver.addKernelInstance(make_unique<U8U16Kernel>(iBuilder));
    400402    pxDriver.makeKernelCall(u8u16k, {BasisBits}, {U8u16Bits, DelMask, ErrorMask});
    401403   
Note: See TracChangeset for help on using the changeset viewer.