Changeset 5117 for icGREP/icgrep-devel


Ignore:
Timestamp:
Aug 5, 2016, 8:57:51 PM (3 years ago)
Author:
cameron
Message:

bitblock_advance

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

Legend:

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

    r5116 r5117  
    11/*
    2  *  Copyright (c) 2015 International Characters.
     2 *  Copyright (c) 2016 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    1313#include <llvm/IR/TypeBuilder.h>
    1414#include <llvm/Support/raw_ostream.h>
     15#include <iostream>
    1516
    1617namespace IDISA {
     
    375376}
    376377
    377 #define SHIFT_FIELDWIDTH 64
    378378// full shift producing {shiftout, shifted}
    379379std::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
    383380    Value * shiftin_bitblock = CreateBitCast(shiftin, getIntNTy(mBitBlockWidth));
    384381    Value * a_bitblock = CreateBitCast(a, getIntNTy(mBitBlockWidth));
    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
     382    Value * shifted = bitCast(CreateOr(CreateShl(a_bitblock, shift), shiftin_bitblock));
     383    Value * shiftout = bitCast(CreateLShr(a_bitblock, mBitBlockWidth - shift));
    423384    return std::pair<Value *, Value *>(shiftout, shifted);
    424385}
    425386
    426                  
    427387Value * IDISA_Builder::simd_and(Value * a, Value * b) {
    428388    return a->getType() == b->getType() ? CreateAnd(a, b) : CreateAnd(bitCast(a), bitCast(b));
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_sse_builder.cpp

    r5037 r5117  
    11/*
    2  *  Copyright (c) 2015 International Characters.
     2 *  Copyright (c) 2016 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    1010#include <llvm/IR/Intrinsics.h>
    1111#include <llvm/IR/Function.h>
     12#include <iostream>
    1213
    1314namespace IDISA {
     
    9697    return IDISA_Builder::hsimd_signmask(fw, a);
    9798}
    98    
     99
     100#define SHIFT_FIELDWIDTH 64
     101#define LEAVE_CARRY_UNNORMALIZED
     102
     103// full shift producing {shiftout, shifted}
     104std::pair<Value *, Value *> IDISA_SSE2_Builder::bitblock_advance(Value * a, Value * shiftin, unsigned shift) {
     105    Value * shifted = nullptr;
     106    Value * shiftout = nullptr;
     107    Type * shiftTy = shiftin->getType();
     108    if (LLVM_UNLIKELY(shift == 0)) {
     109        return std::pair<Value *, Value *>(Constant::getNullValue(shiftTy), a);
     110    }
     111    Value * si = shiftin;
     112    if (shiftTy != mBitBlockType) {
     113        si = bitCast(CreateZExt(shiftin, getIntNTy(mBitBlockWidth)));
     114    }
     115    if (LLVM_UNLIKELY(shift == mBitBlockWidth)) {
     116        return std::pair<Value *, Value *>(CreateBitCast(a, shiftTy), si);
     117    }
     118#ifndef LEAVE_CARRY_UNNORMALIZED
     119    if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
     120        shifted = simd_or(mvmd_slli(8, a, shift / 8), si);
     121        shiftout = mvmd_srli(8, a, (mBitBlockWidth - shift) / 8);
     122        return std::pair<Value *, Value *>(shiftout, shifted);
     123    }
     124    Value * shiftback = simd_srli(SHIFT_FIELDWIDTH, a, SHIFT_FIELDWIDTH - (shift % SHIFT_FIELDWIDTH));
     125    Value * shiftfwd = simd_slli(SHIFT_FIELDWIDTH, a, shift % SHIFT_FIELDWIDTH);
     126    if (LLVM_LIKELY(shift < SHIFT_FIELDWIDTH)) {
     127        shiftout = mvmd_srli(SHIFT_FIELDWIDTH, shiftback, mBitBlockWidth/SHIFT_FIELDWIDTH - 1);
     128        shifted = simd_or(simd_or(shiftfwd, si), mvmd_slli(SHIFT_FIELDWIDTH, shiftback, 1));
     129    }
     130    else {
     131        shiftout = simd_or(shiftback, mvmd_srli(SHIFT_FIELDWIDTH, shiftfwd, 1));
     132        shifted = simd_or(si, mvmd_slli(SHIFT_FIELDWIDTH, shiftfwd, (mBitBlockWidth - shift) / SHIFT_FIELDWIDTH));
     133        if (shift < mBitBlockWidth - SHIFT_FIELDWIDTH) {
     134            shiftout = mvmd_srli(SHIFT_FIELDWIDTH, shiftout, (mBitBlockWidth - shift) / SHIFT_FIELDWIDTH);
     135            shifted = simd_or(shifted, mvmd_slli(SHIFT_FIELDWIDTH, shiftback, shift/SHIFT_FIELDWIDTH + 1));
     136        }
     137    }
     138#endif
     139#ifdef LEAVE_CARRY_UNNORMALIZED
     140    shiftout = a;
     141    if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
     142        shifted = mvmd_dslli(8, a, shiftin, (mBitBlockWidth - shift) / 8);
     143    }
     144    else if (LLVM_LIKELY(shift < SHIFT_FIELDWIDTH)) {
     145        Value * ahead = mvmd_dslli(SHIFT_FIELDWIDTH, a, shiftin, mBitBlockWidth / SHIFT_FIELDWIDTH - 1);
     146        shifted = simd_or(simd_srli(SHIFT_FIELDWIDTH, ahead, SHIFT_FIELDWIDTH - shift), simd_slli(SHIFT_FIELDWIDTH, a, shift));
     147    }
     148    else {
     149        throw std::runtime_error("Unsupported shift.");
     150    }
     151#endif
     152    if (shiftTy != mBitBlockType) {
     153        shiftout = CreateBitCast(shiftout, shiftTy);
     154    }
     155    //CallPrintRegister("shifted", shifted);
     156    //CallPrintRegister("shiftout", shiftout);
     157    return std::pair<Value *, Value *>(shiftout, shifted);
    99158}
     159
     160}
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_sse_builder.h

    r4998 r5117  
    3535    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
    3636    Value * hsimd_packl(unsigned fw, Value * a, Value * b) override;
     37    std::pair<Value *, Value *> bitblock_advance(Value * a, Value * shiftin, unsigned shift) override;
     38
    3739    ~IDISA_SSE2_Builder() {};
    3840
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5115 r5117  
    1414#include <llvm/IR/CallingConv.h>
    1515#include <llvm/IR/Function.h>
    16 
    17 #define DSSLI_FIELDWIDTH 64
     16#include <iostream>
     17
    1818
    1919namespace pablo {
     
    117117    Value * const carryIn = getCarryPack(index);
    118118    assert (index < mCarryOutPack.size());
    119     mCarryOutPack[index] = value;
     119    std::pair<Value *, Value *> adv = iBuilder->bitblock_advance(value, carryIn, shiftAmount);
     120    mCarryOutPack[index] = std::get<0>(adv);
    120121    if (mCarryInfo->getWhileDepth() == 0) {
    121122        storeCarryOut(index);
    122123    }
    123     if (LLVM_UNLIKELY((shiftAmount % 8) == 0)) { // Use a single whole-byte shift, if possible.
    124         result = iBuilder->mvmd_dslli(8, value, carryIn, (iBuilder->getBitBlockWidth() / 8) - (shiftAmount / 8));
    125     } else if (LLVM_LIKELY(shiftAmount < DSSLI_FIELDWIDTH)) {
    126         Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, value, carryIn, iBuilder->getBitBlockWidth() / DSSLI_FIELDWIDTH - 1);
    127         result = iBuilder->simd_or(iBuilder->simd_srli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH - shiftAmount), iBuilder->simd_slli(DSSLI_FIELDWIDTH, value, shiftAmount));
    128     } else {
    129         Value* advanceq_longint = iBuilder->CreateBitCast(carryIn, iBuilder->getIntNTy(mBitBlockWidth));
    130         Value* strm_longint = iBuilder->CreateBitCast(value, iBuilder->getIntNTy(mBitBlockWidth));
    131         Value* adv_longint = iBuilder->CreateOr(iBuilder->CreateShl(strm_longint, shiftAmount), iBuilder->CreateLShr(advanceq_longint, mBitBlockWidth - shiftAmount), "advance");
    132         result = iBuilder->CreateBitCast(adv_longint, mBitBlockType);
    133     }
    134124    if (LLVM_LIKELY(hasSummary())) {
    135125        addToSummary(value);
    136126    }
    137     return result;
     127    return std::get<1>(adv);
    138128}
    139129
  • icGREP/icgrep-devel/icgrep/toolchain.cpp

    r5110 r5117  
    116116
    117117    builder.setTargetOptions(opts);
     118    builder.setVerifyModules(true);
    118119    CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
    119120    switch (codegen::OptLevel) {
Note: See TracChangeset for help on using the changeset viewer.