Changeset 5116 for icGREP/icgrep-devel


Ignore:
Timestamp:
Aug 5, 2016, 12:52:33 PM (3 years ago)
Author:
cameron
Message:

bitblock_advance performance improvement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.cpp

    r5115 r5116  
    375375}
    376376
     377#define SHIFT_FIELDWIDTH 64
    377378// full shift producing {shiftout, shifted}
    378379std::pair<Value *, Value *> IDISA_Builder::bitblock_advance(Value * a, Value * shiftin, unsigned shift) {
     380    Value * shifted = nullptr;
     381    Value * shiftout = nullptr;
     382#ifdef USE_SIMPLE_BITBLOCK_ADVANCE
    379383    Value * shiftin_bitblock = CreateBitCast(shiftin, getIntNTy(mBitBlockWidth));
    380384    Value * a_bitblock = CreateBitCast(a, getIntNTy(mBitBlockWidth));
    381     Value * shifted = bitCast(CreateOr(CreateShl(a_bitblock, shift), shiftin_bitblock));
    382     Value * shiftout = bitCast(CreateLShr(a_bitblock, mBitBlockWidth - shift));
     385    shifted = bitCast(CreateOr(CreateShl(a_bitblock, shift), shiftin_bitblock));
     386    shiftout = bitCast(CreateLShr(a_bitblock, mBitBlockWidth - shift));
     387#endif
     388#ifndef USE_SIMPLE_BITBLOCK_ADVANCE
     389    Type * shiftTy = shiftin->getType();
     390    if (LLVM_UNLIKELY(shift == 0)) {
     391        return std::pair<Value *, Value *>(Constant::getNullValue(shiftTy), a);
     392    }
     393    Value * si = shiftin;
     394    if (shiftTy != mBitBlockType) {
     395        si = bitCast(CreateZExt(shiftin, getIntNTy(mBitBlockWidth)));
     396    }
     397    if (LLVM_UNLIKELY(shift == mBitBlockWidth)) {
     398        return std::pair<Value *, Value *>(CreateBitCast(a, shiftTy), si);
     399    }
     400    if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
     401        shifted = simd_or(mvmd_slli(8, a, shift / 8), si);
     402        shiftout = mvmd_srli(8, a, (mBitBlockWidth - shift) / 8);
     403        return std::pair<Value *, Value *>(shiftout, shifted);
     404    }
     405    Value * shiftback = simd_srli(SHIFT_FIELDWIDTH, a, SHIFT_FIELDWIDTH - (shift % SHIFT_FIELDWIDTH));
     406    Value * shiftfwd = simd_slli(SHIFT_FIELDWIDTH, a, shift % SHIFT_FIELDWIDTH);
     407    if (LLVM_LIKELY(shift < SHIFT_FIELDWIDTH)) {
     408        shiftout = mvmd_srli(SHIFT_FIELDWIDTH, shiftback, mBitBlockWidth/SHIFT_FIELDWIDTH - 1);
     409        shifted = simd_or(simd_or(shiftfwd, si), mvmd_slli(SHIFT_FIELDWIDTH, shiftback, 1));
     410    }
     411    else {
     412        shiftout = simd_or(shiftback, mvmd_srli(SHIFT_FIELDWIDTH, shiftfwd, 1));
     413        shifted = simd_or(si, mvmd_slli(SHIFT_FIELDWIDTH, shiftfwd, (mBitBlockWidth - shift) / SHIFT_FIELDWIDTH));
     414        if (shift < mBitBlockWidth - SHIFT_FIELDWIDTH) {
     415            shiftout = mvmd_srli(SHIFT_FIELDWIDTH, shiftout, (mBitBlockWidth - shift) / SHIFT_FIELDWIDTH);
     416            shifted = simd_or(shifted, mvmd_slli(SHIFT_FIELDWIDTH, shiftback, shift/SHIFT_FIELDWIDTH + 1));
     417        }
     418    }
     419    if (shiftTy != mBitBlockType) {
     420        shiftout = CreateBitCast(shiftout, shiftTy);
     421    }
     422#endif
    383423    return std::pair<Value *, Value *>(shiftout, shifted);
    384424}
    385425
     426                 
    386427Value * IDISA_Builder::simd_and(Value * a, Value * b) {
    387428    return a->getType() == b->getType() ? CreateAnd(a, b) : CreateAnd(bitCast(a), bitCast(b));
Note: See TracChangeset for help on using the changeset viewer.