当前位置: 首页>>代码示例>>C++>>正文


C++ APInt::countLeadingOnes方法代码示例

本文整理汇总了C++中APInt::countLeadingOnes方法的典型用法代码示例。如果您正苦于以下问题:C++ APInt::countLeadingOnes方法的具体用法?C++ APInt::countLeadingOnes怎么用?C++ APInt::countLeadingOnes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在APInt的用法示例。


在下文中一共展示了APInt::countLeadingOnes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ComputeMaskedBits


//.........这里部分代码省略.........
    // Output known-1 are known to be set if set in either the LHS | RHS.
    KnownOne |= KnownOne2;
    return;
  }
  case Instruction::Xor: {
    ComputeMaskedBits(I->getOperand(1), Mask, KnownZero, KnownOne, TD, Depth+1);
    ComputeMaskedBits(I->getOperand(0), Mask, KnownZero2, KnownOne2, TD,
                      Depth+1);
    assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); 
    assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); 
    
    // Output known-0 bits are known if clear or set in both the LHS & RHS.
    APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2);
    // Output known-1 are known to be set if set in only one of the LHS, RHS.
    KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2);
    KnownZero = KnownZeroOut;
    return;
  }
  case Instruction::Mul: {
    APInt Mask2 = APInt::getAllOnesValue(BitWidth);
    ComputeMaskedBits(I->getOperand(1), Mask2, KnownZero, KnownOne, TD,Depth+1);
    ComputeMaskedBits(I->getOperand(0), Mask2, KnownZero2, KnownOne2, TD,
                      Depth+1);
    assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); 
    assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); 
    
    // If low bits are zero in either operand, output low known-0 bits.
    // Also compute a conserative estimate for high known-0 bits.
    // More trickiness is possible, but this is sufficient for the
    // interesting case of alignment computation.
    KnownOne.clear();
    unsigned TrailZ = KnownZero.countTrailingOnes() +
                      KnownZero2.countTrailingOnes();
    unsigned LeadZ =  std::max(KnownZero.countLeadingOnes() +
                               KnownZero2.countLeadingOnes(),
                               BitWidth) - BitWidth;

    TrailZ = std::min(TrailZ, BitWidth);
    LeadZ = std::min(LeadZ, BitWidth);
    KnownZero = APInt::getLowBitsSet(BitWidth, TrailZ) |
                APInt::getHighBitsSet(BitWidth, LeadZ);
    KnownZero &= Mask;
    return;
  }
  case Instruction::UDiv: {
    // For the purposes of computing leading zeros we can conservatively
    // treat a udiv as a logical right shift by the power of 2 known to
    // be less than the denominator.
    APInt AllOnes = APInt::getAllOnesValue(BitWidth);
    ComputeMaskedBits(I->getOperand(0),
                      AllOnes, KnownZero2, KnownOne2, TD, Depth+1);
    unsigned LeadZ = KnownZero2.countLeadingOnes();

    KnownOne2.clear();
    KnownZero2.clear();
    ComputeMaskedBits(I->getOperand(1),
                      AllOnes, KnownZero2, KnownOne2, TD, Depth+1);
    unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
    if (RHSUnknownLeadingOnes != BitWidth)
      LeadZ = std::min(BitWidth,
                       LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);

    KnownZero = APInt::getHighBitsSet(BitWidth, LeadZ) & Mask;
    return;
  }
  case Instruction::Select:
开发者ID:blickly,项目名称:llvm-clang-PRETC,代码行数:67,代码来源:ValueTracking.cpp

示例2: determineLiveOperandBits


//.........这里部分代码省略.........
                    AB |= APInt::getHighBitsSet(BitWidth, ShiftAmt);
            }
        break;
    case Instruction::LShr:
        if (OperandNo == 0)
            if (ConstantInt *CI =
                        dyn_cast<ConstantInt>(UserI->getOperand(1))) {
                uint64_t ShiftAmt = CI->getLimitedValue(BitWidth-1);
                AB = AOut.shl(ShiftAmt);

                // If the shift is exact, then the low bits are not dead
                // (they must be zero).
                if (cast<LShrOperator>(UserI)->isExact())
                    AB |= APInt::getLowBitsSet(BitWidth, ShiftAmt);
            }
        break;
    case Instruction::AShr:
        if (OperandNo == 0)
            if (ConstantInt *CI =
                        dyn_cast<ConstantInt>(UserI->getOperand(1))) {
                uint64_t ShiftAmt = CI->getLimitedValue(BitWidth-1);
                AB = AOut.shl(ShiftAmt);
                // Because the high input bit is replicated into the
                // high-order bits of the result, if we need any of those
                // bits, then we must keep the highest input bit.
                if ((AOut & APInt::getHighBitsSet(BitWidth, ShiftAmt))
                        .getBoolValue())
                    AB.setBit(BitWidth-1);

                // If the shift is exact, then the low bits are not dead
                // (they must be zero).
                if (cast<AShrOperator>(UserI)->isExact())
                    AB |= APInt::getLowBitsSet(BitWidth, ShiftAmt);
            }
        break;
    case Instruction::And:
        AB = AOut;

        // For bits that are known zero, the corresponding bits in the
        // other operand are dead (unless they're both zero, in which
        // case they can't both be dead, so just mark the LHS bits as
        // dead).
        if (OperandNo == 0) {
            ComputeKnownBits(BitWidth, I, UserI->getOperand(1));
            AB &= ~KnownZero2;
        } else {
            if (!isa<Instruction>(UserI->getOperand(0)))
                ComputeKnownBits(BitWidth, UserI->getOperand(0), I);
            AB &= ~(KnownZero & ~KnownZero2);
        }
        break;
    case Instruction::Or:
        AB = AOut;

        // For bits that are known one, the corresponding bits in the
        // other operand are dead (unless they're both one, in which
        // case they can't both be dead, so just mark the LHS bits as
        // dead).
        if (OperandNo == 0) {
            ComputeKnownBits(BitWidth, I, UserI->getOperand(1));
            AB &= ~KnownOne2;
        } else {
            if (!isa<Instruction>(UserI->getOperand(0)))
                ComputeKnownBits(BitWidth, UserI->getOperand(0), I);
            AB &= ~(KnownOne & ~KnownOne2);
        }
        break;
    case Instruction::Xor:
    case Instruction::PHI:
        AB = AOut;
        break;
    case Instruction::Trunc:
        AB = AOut.zext(BitWidth);
        break;
    case Instruction::ZExt:
        AB = AOut.trunc(BitWidth);
        break;
    case Instruction::SExt:
        AB = AOut.trunc(BitWidth);
        // Because the high input bit is replicated into the
        // high-order bits of the result, if we need any of those
        // bits, then we must keep the highest input bit.
        if ((AOut & APInt::getHighBitsSet(AOut.getBitWidth(),
                                          AOut.getBitWidth() - BitWidth))
                .getBoolValue())
            AB.setBit(BitWidth-1);
        break;
    case Instruction::Select:
        if (OperandNo != 0)
            AB = AOut;
        break;
    case Instruction::ICmp:
        // Count the number of leading zeroes in each operand.
        ComputeKnownBits(BitWidth, I, UserI->getOperand(1));
        auto NumLeadingZeroes = std::min(KnownZero.countLeadingOnes(),
                                         KnownZero2.countLeadingOnes());
        AB = ~APInt::getHighBitsSet(BitWidth, NumLeadingZeroes);
        break;
    }
}
开发者ID:zhiyongLee,项目名称:llvm,代码行数:101,代码来源:DemandedBits.cpp


注:本文中的APInt::countLeadingOnes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。