Changeset 4542 for icGREP


Ignore:
Timestamp:
Apr 28, 2015, 11:09:35 AM (4 years ago)
Author:
cameron
Message:

Named print register function, field size in genShiftHighbitToLow

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4541 r4542  
    5151
    5252extern "C" {
    53   void wrapped_print_register(BitBlock bit_block) {
    54       print_register<BitBlock>("", bit_block);
     53  void wrapped_print_register(char * regName, BitBlock bit_block) {
     54      print_register<BitBlock>(regName, bit_block);
    5555  }
    5656}
     
    9292}
    9393
     94void PabloCompiler::genPrintRegister(std::string regName, Value * bitblockValue) {
     95    IRBuilder <> b(mBasicBlock);
     96    Constant * regNameData = ConstantDataArray::getString(mMod->getContext(), regName);
     97    GlobalVariable *regStrVar = new GlobalVariable(*mMod,
     98                                                   ArrayType::get(IntegerType::get(mMod->getContext(), 8), regName.length()+1),
     99                                                   /*isConstant=*/ true,
     100                                                   /*Linkage=*/ GlobalValue::PrivateLinkage,
     101                                                   /*Initializer=*/ regNameData);
     102    Value * regStrPtr = b.CreateGEP(regStrVar, {b.getInt64(0), b.getInt32(0)});
     103    b.CreateCall(mPrintRegisterFunction, {regStrPtr, bitblockValue});
     104}
    94105
    95106CompiledPabloFunction PabloCompiler::compile(PabloBlock & pb)
     
    207218{
    208219    //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    209     mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), mBitBlockType, NULL);
     220    mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), Type::getInt8PtrTy(getGlobalContext()), mBitBlockType, NULL);
    210221    mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    211222    // to call->  b.CreateCall(mFunc_print_register, unicode_category);
     
    847858
    848859    Value* sum = b.CreateAdd(partial, mid_carry_in, "sum");
    849     Value* carry_out = genShiftHighbitToLow(b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(sum))), "carry_out");
     860    Value* carry_out = genShiftHighbitToLow(BLOCK_SIZE, b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(sum))));
    850861#else
    851862    //BLOCK_SIZE == 256, there is no other implementation
     
    856867    return sum;
    857868}
    858 
     869#define CARRY_DEBUG
    859870Value* PabloCompiler::genCarryDataLoad(const unsigned index) {
    860871    assert (index < mCarryDataVector.size());
     
    863874        mCarryDataVector[index] = b.CreateAlignedLoad(b.CreateGEP(mCarryDataPtr, b.getInt64(index)), BLOCK_SIZE/8, false);
    864875    }
     876#ifdef CARRY_DEBUG
     877    genPrintRegister("carry_in_" + std::to_string(index), mCarryDataVector[index]);
     878#endif
    865879    return mCarryDataVector[index];
    866880}
     
    874888    }
    875889    mCarryDataSummaryIdx[index] = -1;
     890#ifdef CARRY_DEBUG
     891    genPrintRegister("carry_out_" + std::to_string(index), mCarryVector[index]);
     892#endif
    876893    mCarryDataVector[index] = carryOut;
    877894}
     
    883900}
    884901
    885 Value* PabloCompiler::genShiftHighbitToLow(Value* e, const Twine &namehint) {
     902Value * PabloCompiler::genShiftHighbitToLow(unsigned FieldWidth, Value * op) {
     903    unsigned FieldCount = BLOCK_SIZE/FieldWidth;
    886904    IRBuilder<> b(mBasicBlock);
    887     Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    888     return b.CreateBitCast(b.CreateLShr(i128_val, BLOCK_SIZE - 1, namehint), mBitBlockType);
     905    VectorType * vType = VectorType::get(IntegerType::get(mMod->getContext(), FieldWidth), FieldCount);
     906    Value * v = b.CreateBitCast(op, vType);
     907    return b.CreateBitCast(b.CreateLShr(v, FieldWidth - 1), mBitBlockType);
    889908}
    890909
     
    915934#if (BLOCK_SIZE == 128) && !defined(USE_LONG_INTEGER_SHIFT)
    916935        if (block_shift == 1) {
    917             Value* advanceq_value = genShiftHighbitToLow(genCarryDataLoad(loadIdx));
     936            Value* advanceq_value = genShiftHighbitToLow(BLOCK_SIZE, genCarryDataLoad(loadIdx));
    918937            Value* srli_1_value = b.CreateLShr(strm_value, 63);
    919938            Value* packed_shuffle;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4541 r4542  
    104104    void SetOutputValue(Value * marker, const unsigned index);
    105105
     106    void genPrintRegister(std::string regName, Value * bitblockValue);
    106107    void compileBlock(const PabloBlock & blk);
    107108    void compileStatement(const Statement * stmt);
     
    114115    Value* genAdvanceWithCarry(Value* e1, int shift_amount, unsigned localIndex, const PabloBlock * blk);
    115116    Value* genBitBlockAny(Value* test);
    116     Value* genShiftHighbitToLow(Value* e, const Twine & namehint = "");
     117    Value* genShiftHighbitToLow(unsigned FieldWidth, Value * op);
    117118    Value* genShiftLeft64(Value* e, const Twine & namehint = "") ;
    118119    Value* genNot(Value* expr);
Note: See TracChangeset for help on using the changeset viewer.