Ignore:
Timestamp:
Mar 30, 2017, 1:22:39 PM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for last check in

File:
1 edited

Legend:

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

    r5377 r5379  
    115115}
    116116
    117 Value * StreamSetBuffer::reserveItemCount(Value * self, llvm::Value * position, llvm::Value *requested) const {
     117void StreamSetBuffer::reserveBytes(Value * self, llvm::Value * position, llvm::Value *requested) const {
    118118    report_fatal_error("reserve() can only be used with ExtensibleBuffers");
    119119}
     
    157157    Type * ty = getType();
    158158    Value * instance = iBuilder->CreateCacheAlignedAlloca(ty);
    159     ConstantInt * const capacity = iBuilder->getSize(mBufferBlocks);
    160159    Value * const capacityPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    161     iBuilder->CreateStore(capacity, capacityPtr);
    162     Constant * const size = ConstantExpr::getMul(ConstantExpr::getSizeOf(ty), capacity);
    163     Value * addr = iBuilder->CreateAlignedMalloc(iBuilder->CreateMul(iBuilder->CreateShl(size, 1), size), iBuilder->getCacheAlignment());
    164     iBuilder->CreateMemZero(addr, size, iBuilder->getCacheAlignment());
     160    Constant * const initialSize = ConstantExpr::getMul(ConstantExpr::getSizeOf(ty->getStructElementType(1)->getPointerElementType()), iBuilder->getSize(mBufferBlocks));
     161    iBuilder->CreateStore(initialSize, capacityPtr);
     162    Value * addr = iBuilder->CreateAlignedMalloc(initialSize, iBuilder->getCacheAlignment());
     163    iBuilder->CreateMemZero(addr, initialSize, iBuilder->getCacheAlignment());
    165164    Value * const addrPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    166165    addr = iBuilder->CreatePointerCast(addr, addrPtr->getType()->getPointerElementType());
     
    173172}
    174173
    175 Value * ExtensibleBuffer::reserveItemCount(Value * self, llvm::Value * position, llvm::Value * requested) const {
    176 
     174void ExtensibleBuffer::reserveBytes(Value * const self, llvm::Value * const position, llvm::Value * const requested) const {
    177175    Value * const capacityPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    178     Value * const capacity = iBuilder->CreateLoad(capacityPtr);
    179     Type * const intTy = capacity->getType();
    180     Constant * const blockSize = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(getType()->getStructElementType(1)), intTy, false);
    181     Constant * const blockSize2 = ConstantExpr::getMul(blockSize, ConstantInt::get(intTy, 2));
    182 
     176    Value * const currentSize = iBuilder->CreateLoad(capacityPtr);
     177    Type * const intTy = currentSize->getType();
     178    assert (position->getType() == requested->getType());
     179    Constant * const blockSize = ConstantExpr::getIntegerCast(ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(getType()->getStructElementType(1)), intTy, false), requested->getType(), false);
    183180    BasicBlock * const entry = iBuilder->GetInsertBlock();
    184181    BasicBlock * const expand = BasicBlock::Create(iBuilder->getContext(), "expand", entry->getParent());
    185182    BasicBlock * const resume = BasicBlock::Create(iBuilder->getContext(), "resume", entry->getParent());
    186 
    187     Value * const reserved = iBuilder->CreateAdd(position, requested);
    188 
    189     iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(reserved, capacity), resume, expand);
     183    Value * const reserved = iBuilder->CreateAdd(iBuilder->CreateMul(position, blockSize), requested);
     184    iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(reserved, currentSize), resume, expand);
    190185
    191186    iBuilder->SetInsertPoint(expand);
    192 
    193     Value * const currentSize = iBuilder->CreateMul(capacity, blockSize);
    194     Value * const reservedSize = iBuilder->CreateMul(reserved, blockSize2);
    195 
     187    Value * const reservedSize = iBuilder->CreateShl(reserved, 1);
    196188    Value * newAddr = iBuilder->CreateAlignedMalloc(reservedSize, iBuilder->getCacheAlignment());
    197189    Value * const baseAddrPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    198190    Value * const baseAddr = iBuilder->CreateLoad(baseAddrPtr);
    199 
    200191    iBuilder->CreateMemCpy(newAddr, baseAddr, currentSize, iBuilder->getCacheAlignment());
    201192    iBuilder->CreateAlignedFree(baseAddr);
    202     iBuilder->CreateMemZero(iBuilder->CreateGEP(newAddr, currentSize), iBuilder->CreateSub(reservedSize, currentSize), iBuilder->getCacheAlignment());
    203 
     193    Value * const remainingSize = iBuilder->CreateSub(reservedSize, currentSize);
     194    iBuilder->CreateMemZero(iBuilder->CreateGEP(newAddr, currentSize), remainingSize, iBuilder->getBitBlockWidth() / 8);
    204195    newAddr = iBuilder->CreatePointerCast(newAddr, baseAddr->getType());
    205 
     196    iBuilder->CreateStore(reservedSize, capacityPtr);
    206197    iBuilder->CreateStore(newAddr, baseAddrPtr);
    207     iBuilder->CreateStore(iBuilder->CreateShl(capacity, 1), capacityPtr);
    208 
    209198    iBuilder->CreateBr(resume);
    210199
    211200    iBuilder->SetInsertPoint(resume);
    212 
    213     return iBuilder->CreateMul(requested, blockSize);
    214 }
    215 
    216 Value * ExtensibleBuffer::getBaseAddress(Value * self) const {
     201}
     202
     203Value * ExtensibleBuffer::getBaseAddress(Value * const self) const {
    217204    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)}));
    218205}
     
    220207// Circular Buffer
    221208
    222 Value * CircularBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
     209Value * CircularBuffer::getStreamSetBlockPtr(Value * const self, Value * const blockIndex) const {
    223210    return iBuilder->CreateGEP(self, modByBufferBlocks(blockIndex));
    224211}
Note: See TracChangeset for help on using the changeset viewer.