Ignore:
Timestamp:
May 12, 2017, 10:25:03 AM (2 years ago)
Author:
cameron
Message:

Fix for raw pointer calculation

File:
1 edited

Legend:

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

    r5442 r5445  
    9797        ptr = iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), streamIndex});
    9898    }
    99     Value * bufferItemPosition = modByBufferBlocks(iBuilder, absolutePosition);
    100     IntegerType * const ty = cast<IntegerType>(mBaseType->getArrayElementType()->getVectorElementType());
    101     ptr = iBuilder->CreatePointerCast(ptr, ty->getPointerTo());
    102     if (LLVM_UNLIKELY(ty->getBitWidth() < 8)) {
    103         const auto bw = ty->getBitWidth();
    104         if (LLVM_LIKELY((bw & (bw - 1)) == 0)) { // is power of 2
    105             bufferItemPosition = iBuilder->CreateUDiv(bufferItemPosition, ConstantInt::get(absolutePosition->getType(), 8 / bw));
    106         } else {
    107             bufferItemPosition = iBuilder->CreateMul(bufferItemPosition, ConstantInt::get(absolutePosition->getType(), bw));
    108             bufferItemPosition = iBuilder->CreateUDiv(bufferItemPosition, ConstantInt::get(absolutePosition->getType(), 8));
    109         }
    110     }
    111     Value * rawPointer = iBuilder->CreateGEP(ptr, bufferItemPosition);
     99    Value * relativePosition = iBuilder->CreateURem(absolutePosition, ConstantInt::get(absolutePosition->getType(), mBufferBlocks * iBuilder->getBitBlockWidth()));
     100    const auto bw = mBaseType->getArrayElementType()->getScalarSizeInBits();
     101    if (bw < 8) {
     102        relativePosition = iBuilder->CreateUDiv(relativePosition, ConstantInt::get(relativePosition->getType(), 8 / bw));
     103        ptr = iBuilder->CreatePointerCast(ptr, iBuilder->getInt8PtrTy());
     104    }
     105    else {
     106        ptr = iBuilder->CreatePointerCast(ptr, iBuilder->getIntNTy(bw)->getPointerTo());
     107    }
     108    Value * rawPointer = iBuilder->CreateGEP(ptr, relativePosition);
    112109    return rawPointer;
    113110}
Note: See TracChangeset for help on using the changeset viewer.