Changeset 6106


Ignore:
Timestamp:
Jun 21, 2018, 6:21:22 PM (5 months ago)
Author:
cameron
Message:

mergeh, mergel for arbitrary BitBlockWidth?

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_avx_builder.h

    r6105 r6106  
    1111
    1212namespace IDISA {
     13   
     14    const unsigned AVX_width = 256;
     15    const unsigned AVX512_width = 512;
    1316
    1417class IDISA_AVX_Builder : public IDISA_SSE2_Builder {
    1518public:
    16     const unsigned NativeBitBlockWidth = 256;
     19    const unsigned NativeBitBlockWidth = AVX_width;
    1720    IDISA_AVX_Builder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
    18     : IDISA_Builder(C, NativeBitBlockWidth, vectorWidth, laneWidth)
     21    : IDISA_Builder(C, AVX_width, vectorWidth, laneWidth)
    1922    , IDISA_SSE2_Builder(C, vectorWidth, laneWidth)
    2023    {
     
    3235class IDISA_AVX2_Builder : public IDISA_AVX_Builder {
    3336public:
    34     const unsigned NativeBitBlockWidth = 256;
     37    const unsigned NativeBitBlockWidth = AVX_width;
    3538    IDISA_AVX2_Builder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
    36     : IDISA_Builder(C, NativeBitBlockWidth, vectorWidth, laneWidth)
     39    : IDISA_Builder(C, AVX_width, vectorWidth, laneWidth)
    3740    , IDISA_AVX_Builder(C, vectorWidth, laneWidth) {
    3841
     
    6366class IDISA_AVX512F_Builder : public IDISA_AVX2_Builder {
    6467public:
    65     const unsigned NativeBitBlockWidth = 512;
     68    const unsigned NativeBitBlockWidth = AVX512_width;
    6669    IDISA_AVX512F_Builder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
    67     : IDISA_Builder(C, NativeBitBlockWidth, vectorWidth, laneWidth)
     70    : IDISA_Builder(C, AVX512_width, vectorWidth, laneWidth)
    6871    , IDISA_AVX2_Builder(C, vectorWidth, laneWidth) {
    6972        getAVX512Features();
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r6105 r6106  
    8888Constant * IDISA_Builder::simd_lomask(unsigned fw) {
    8989    return Constant::getIntegerValue(getIntNTy(mBitBlockWidth), APInt::getSplat(mBitBlockWidth, APInt::getLowBitsSet(fw, fw/2)));
     90}
     91
     92unsigned getVectorBitWidth(Value * vec) {
     93    return cast<VectorType>(vec->getType())->getBitWidth();
     94}
     95
     96Constant * IDISA_Builder::getConstantVectorSequence(unsigned fw, unsigned first, unsigned last, unsigned by) {
     97    const unsigned seqLgth = (last - first)/by + 1;
     98    assert(((first + (seqLgth - 1) * by) == last) && "invalid element sequence");
     99    Type * fwTy = getIntNTy(fw);
     100    Constant * elements[seqLgth];
     101    for (unsigned i = 0; i < seqLgth; i++) {
     102        elements[i] = ConstantInt::get(fwTy, i*by + first);
     103    }
     104    return ConstantVector::get({elements, seqLgth});
     105}
     106
     107Value * IDISA_Builder::CreateHalfVectorHigh(Value * vec) {
     108    VectorType * const vecTy = cast<VectorType>(vec->getType());
     109    const unsigned fieldCount = vecTy->getNumElements();
     110    return CreateShuffleVector(vec, UndefValue::get(vecTy), getConstantVectorSequence(32, fieldCount/2, fieldCount-1));
     111}
     112
     113Value * IDISA_Builder::CreateHalfVectorLow(Value * vec) {
     114    VectorType * const vecTy = cast<VectorType>(vec->getType());
     115    const unsigned fieldCount = vecTy->getNumElements();
     116    return CreateShuffleVector(vec, UndefValue::get(vecTy), getConstantVectorSequence(32, 0, fieldCount/2-1));
     117}
     118
     119Value * IDISA_Builder::CreateDoubleVector(Value * lo, Value * hi) {
     120    VectorType * const vecTy = cast<VectorType>(lo->getType());
     121    const unsigned fieldCount = vecTy->getNumElements();
     122    return CreateShuffleVector(lo, hi, getConstantVectorSequence(32, 0, fieldCount*2-1));
    90123}
    91124
     
    431464}
    432465   
    433 Value * IDISA_Builder::esimd_mergeh(unsigned fw, Value * a, Value * b) {   
     466Value * IDISA_Builder::esimd_mergeh(unsigned fw, Value * a, Value * b) {
     467    if (getVectorBitWidth(a) > mBitBlockWidth) {
     468        Value * a_hi = CreateHalfVectorHigh(a);
     469        Value * b_hi = CreateHalfVectorHigh(b);
     470        return CreateDoubleVector(esimd_mergel(fw, a_hi, b_hi), esimd_mergeh(fw, a_hi, b_hi));
     471    }
    434472    if (fw < 8) {
    435473        Value * abh = simd_or(simd_and(simd_himask(fw*2), b), simd_srli(32, simd_and(simd_himask(fw*2), a), fw));
     
    437475        return esimd_mergeh(fw * 2, abl, abh);
    438476    }
    439     if (fw < 4) UnsupportedFieldWidthError(fw, "mergeh");
    440477    const auto field_count = mBitBlockWidth / fw;
    441478    Constant * Idxs[field_count];
     
    448485
    449486Value * IDISA_Builder::esimd_mergel(unsigned fw, Value * a, Value * b) {
     487    if (getVectorBitWidth(a) > mBitBlockWidth) {
     488        Value * a_lo = CreateHalfVectorLow(a);
     489        Value * b_lo = CreateHalfVectorLow(b);
     490        return CreateDoubleVector(esimd_mergel(fw, a_lo, b_lo), esimd_mergeh(fw, a_lo, b_lo));
     491    }
    450492    if (fw < 8) {
    451493        Value * abh = simd_or(simd_and(simd_himask(fw*2), b), simd_srli(32, simd_and(simd_himask(fw*2), a), fw));
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r6105 r6106  
    6363        return mOneInitializer;
    6464    }
     65   
     66    llvm::Constant * getConstantVectorSequence(unsigned fw, unsigned first, unsigned last, unsigned by = 1);
     67   
     68    llvm::Value * CreateHalfVectorHigh(llvm::Value *);
     69   
     70    llvm::Value * CreateHalfVectorLow(llvm::Value *);
     71
     72    llvm::Value * CreateDoubleVector(llvm::Value * lo, llvm::Value * hi);
    6573   
    6674    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr) {
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_i64_builder.h

    r6105 r6106  
    1010
    1111namespace IDISA {
     12    const unsigned I64_width = 64;
    1213
    1314class IDISA_I64_Builder : public virtual IDISA_Builder {
    1415public:
    15     const unsigned NativeBitBlockWidth = 64;
     16    const unsigned NativeBitBlockWidth = I64_width;
    1617 
    1718    IDISA_I64_Builder(llvm::LLVMContext & C, unsigned bitBlockWidth, unsigned laneWidth)
    18     : IDISA_Builder(C, NativeBitBlockWidth, bitBlockWidth, laneWidth) {
     19    : IDISA_Builder(C, I64_width, bitBlockWidth, laneWidth) {
    1920
    2021    }
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_sse_builder.h

    r6105 r6106  
    1111namespace IDISA {
    1212
     13const unsigned SSE_width = 128;
     14   
    1315class IDISA_SSE_Builder : public virtual IDISA_Builder {
    1416public:
    15     const unsigned NativeBitBlockWidth = 128;
     17    const unsigned NativeBitBlockWidth = SSE_width;
    1618    IDISA_SSE_Builder(llvm::LLVMContext & C, unsigned bitBlockWidth, unsigned laneWidth)
    17     : IDISA_Builder(C, NativeBitBlockWidth, bitBlockWidth, laneWidth) {
     19    : IDISA_Builder(C, SSE_width, bitBlockWidth, laneWidth) {
    1820
    1921    }
     
    2729class IDISA_SSE2_Builder : public IDISA_SSE_Builder {
    2830public:
    29     const unsigned NativeBitBlockWidth = 128; 
     31    const unsigned NativeBitBlockWidth = SSE_width;
    3032    IDISA_SSE2_Builder(llvm::LLVMContext & C, unsigned bitBlockWidth, unsigned laneWidth)
    31     : IDISA_Builder(C, NativeBitBlockWidth, bitBlockWidth, laneWidth)
     33    : IDISA_Builder(C, SSE_width, bitBlockWidth, laneWidth)
    3234    , IDISA_SSE_Builder(C, bitBlockWidth, laneWidth) {
    3335
     
    4547class IDISA_SSSE3_Builder : public IDISA_SSE2_Builder {
    4648public:
    47     const unsigned NativeBitBlockWidth = 128;   
     49    const unsigned NativeBitBlockWidth = SSE_width;
    4850    IDISA_SSSE3_Builder(llvm::LLVMContext & C, unsigned bitBlockWidth, unsigned laneWidth)
    49     : IDISA_Builder(C, NativeBitBlockWidth, bitBlockWidth, laneWidth)
     51    : IDISA_Builder(C, SSE_width, bitBlockWidth, laneWidth)
    5052    , IDISA_SSE2_Builder(C, bitBlockWidth, laneWidth)
    5153    {
Note: See TracChangeset for help on using the changeset viewer.