Changeset 6060


Ignore:
Timestamp:
May 31, 2018, 1:33:48 AM (3 months ago)
Author:
xwa163
Message:

Implement S2PByPextKernel

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r6026 r6060  
    189189
    190190
    191 }
     191S2PByPextKernel::S2PByPextKernel(const std::unique_ptr<kernel::KernelBuilder> &b, std::string prefix)
     192        : BlockOrientedKernel(prefix + "s2pByPext",
     193                           {Binding{b->getStreamSetTy(1, 8), "byteStream", FixedRate(), Principal()}},
     194                           {Binding{b->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {})
     195{
     196
     197}
     198
     199void S2PByPextKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> &b) {
     200    Value* inputBasePtr = b->CreatePointerCast(b->getInputStreamBlockPtr("byteStream", b->getSize(0)), b->getInt64Ty()->getPointerTo());
     201    std::vector<Value*> outputPtrs(8, nullptr);
     202    for (unsigned i = 0; i < 8; i++) {
     203        outputPtrs[i] = b->CreatePointerCast(b->getOutputStreamBlockPtr("basisBits", b->getSize(i)), b->getInt64Ty()->getPointerTo());
     204    }
     205    uint64_t base_mask = 0x0101010101010101;
     206
     207    Constant * pext = Intrinsic::getDeclaration(b->getModule(), Intrinsic::x86_bmi_pext_64);
     208
     209    for (unsigned iBlockIndex = 0; iBlockIndex < 4; iBlockIndex++) {
     210        std::vector<Value*> tempValues(8, b->getInt64(0));
     211        for (size_t iDataIndex = 0; iDataIndex < 8; iDataIndex++) {
     212            Value* inputData = b->CreateLoad(b->CreateGEP(inputBasePtr, b->getSize(iDataIndex + iBlockIndex * 8)));
     213            for (int iStreamIndex = 0; iStreamIndex < 8; iStreamIndex++) {
     214                Value* targetMask = b->getInt64(base_mask << iStreamIndex);
     215                Value * const outputValue = b->CreateCall(pext, {inputData, targetMask});
     216                tempValues[iStreamIndex] = b->CreateOr(tempValues[iStreamIndex], b->CreateShl(outputValue, b->getInt64(iDataIndex * 8)));
     217            }
     218        }
     219        for (int iStreamIndex = 0; iStreamIndex < 8; iStreamIndex++) {
     220            b->CreateStore(tempValues[iStreamIndex], b->CreateGEP(outputPtrs[7 - iStreamIndex], b->getSize(iBlockIndex)));
     221        }
     222    }
     223}
     224}
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r6026 r6060  
    3737};
    3838
     39
     40class S2PByPextKernel final : public BlockOrientedKernel {
     41public:
     42    S2PByPextKernel(const std::unique_ptr<kernel::KernelBuilder> & b, std::string prefix = "");
     43    bool isCachable() const override { return true; }
     44    bool hasSignature() const override { return false; }
     45protected:
     46    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
     47};
     48
    3949}
    4050#endif
Note: See TracChangeset for help on using the changeset viewer.