[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h

Chris Lattner clattner at apple.com
Sat Mar 24 16:41:23 PDT 2007


On Mar 24, 2007, at 4:36 PM, Reid Spencer wrote:
>    /// @brief Get a value with high bits set
>    static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) {
>      assert(hiBitsSet <= numBits && "Too many bits to set!");
> -    uint32_t mvBits = numBits - hiBitsSet;
> +    uint32_t shiftAmt = numBits - hiBitsSet;
>      // For small values, return quickly
>      if (numBits <= APINT_BITS_PER_WORD)
> +      return APInt(numBits, ~0ULL << shiftAmt);

Now we get undefined behavior if hibitsset = 0, no?

-Chris

> +    return (~APInt(numBits, 0)).shl(shiftAmt);
>    }
>
>    /// Constructs an APInt value that has the bottom loBitsSet bits  
> set.
> @@ -371,10 +370,11 @@
>    /// @brief Get a value with low bits set
>    static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) {
>      assert(loBitsSet <= numBits && "Too many bits to set!");
> +    uint32_t shiftAmt = numBits - loBitsSet;
>      // For small values, return quickly
>      if (numBits <= APINT_BITS_PER_WORD)
> -      return APInt(numBits, (1ULL << loBitsSet) - 1ULL);
> -    return APInt(numBits, 1).shl(loBitsSet) - APInt(numBits, 1);
> +      return APInt(numBits, ~0ULL >> shiftAmt);
> +    return (~APInt(numBits, 0)).lshr(shiftAmt);
>    }
>
>    /// The hash value is computed as the sum of the words and the  
> bit width.
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list