cloud9_root/src/third_party/stp/src/simplifier/simplifier.cpp
// If the rhs of a left or right shift is known.
If the rhs of a left or right shift is known.
If the rhs of a left or right shift is known .
ASTNode
  Simplifier::convertKnownShiftAmount(const Kind k, const ASTVec& children, STPMgr& bm, NodeFactory *nf)
  {
    const ASTNode a = children[0];
    const ASTNode b = children[1];
    const int width = children[0].GetValueWidth();
    ASTNode output;
    assert(b.isConstant());
    assert(k == BVLEFTSHIFT || BVRIGHTSHIFT ==k);
    if (CONSTANTBV::Set_Max(b.GetBVConst()) > 1 + log2(width))
      {
        output = bm.CreateZeroConst(width);
      }
    else
      {
        const unsigned int shift = b.GetUnsignedConst();
        if (shift >= width)
          {
            output = bm.CreateZeroConst(width);
          }
        else if (shift == 0)
          {
            output = a; 
          }
        else
          {
            if (k == BVLEFTSHIFT)
              {
                CBV cbv = CONSTANTBV::BitVector_Create(width, true);
                CONSTANTBV::BitVector_Bit_On(cbv, shift);
                ASTNode c = bm.CreateBVConst(cbv, width);
                output = nf->CreateTerm(BVMULT, width, a, c);
                BVTypeCheck(output);
              }
            else if (k == BVRIGHTSHIFT)
              {
                ASTNode zero = bm.CreateZeroConst(shift);
                ASTNode hi = bm.CreateBVConst(32, width - 1);
                ASTNode low = bm.CreateBVConst(32, shift);
                ASTNode extract = nf->CreateTerm(BVEXTRACT, width - shift, a, hi, low);
                BVTypeCheck(extract);
                output = nf->CreateTerm(BVCONCAT, width, zero, extract);
                BVTypeCheck(output);
              }
            else
              FatalError("herasdf");
          }
      }
    return output;
  }
ASTNode Simplifier :: convertKnownShiftAmount ( const Kind k , const ASTVec & children , STPMgr & bm , NodeFactory * nf ) { const ASTNode a = children [ 0 ] ; const ASTNode b = children [ 1 ] ; const int width = children [ 0 ] . GetValueWidth ( ) ; ASTNode output ; assert ( b . isConstant ( ) ) ; assert ( k == BVLEFTSHIFT || BVRIGHTSHIFT == k ) ; if ( CONSTANTBV :: Set_Max ( b . GetBVConst ( ) ) > 1 + log2 ( width ) ) { output = bm . CreateZeroConst ( width ) ; } else { const unsigned int shift = b . GetUnsignedConst ( ) ; if ( shift >= width ) { output = bm . CreateZeroConst ( width ) ; } else if ( shift == 0 ) { output = a ; } else { if ( k == BVLEFTSHIFT ) { CBV cbv = CONSTANTBV :: BitVector_Create ( width , true ) ; CONSTANTBV :: BitVector_Bit_On ( cbv , shift ) ; ASTNode c = bm . CreateBVConst ( cbv , width ) ; output = nf -> CreateTerm ( BVMULT , width , a , c ) ; BVTypeCheck ( output ) ; } else if ( k == BVRIGHTSHIFT ) { ASTNode zero = bm . CreateZeroConst ( shift ) ; ASTNode hi = bm . CreateBVConst ( 32 , width - 1 ) ; ASTNode low = bm . CreateBVConst ( 32 , shift ) ; ASTNode extract = nf -> CreateTerm ( BVEXTRACT , width - shift , a , hi , low ) ; BVTypeCheck ( extract ) ; output = nf -> CreateTerm ( BVCONCAT , width , zero , extract ) ; BVTypeCheck ( output ) ; } else FatalError ( " " ) ; } } return output ; }
If the rhs of a left or right shift is known.
If the rhs of a left or right shift is known .
// Intended to remove shifts by very large amounts // that don't fit into the unsigned.  at thhe start // of the "else" branch. // unchanged. //cout << output; //cout << a << b << endl;