[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

Chris Lattner clattner at apple.com
Sun May 13 17:05:07 PDT 2007


On May 13, 2007, at 4:57 PM, Reid Spencer wrote:

> On Sun, 2007-05-13 at 16:49 -0700, Chris Lattner wrote:
>> On May 13, 2007, at 4:45 PM, Reid Spencer wrote:
>>
>>> +APInt APInt::rotl(uint32_t rotateAmt) const {
>>> +  // Don't get too fancy, just use existing shift/or facilities
>>> +  APInt hi(*this);
>>> +  APInt lo(*this);
>>> +  hi.shl(rotateAmt);
>>> +  lo.lshr(BitWidth - rotateAmt);
>>> +  return hi | lo;
>>> +}
>>> +
>>> +APInt APInt::rotr(uint32_t rotateAmt) const {
>>> +  // Don't get too fancy, just use existing shift/or facilities
>>> +  APInt hi(*this);
>>> +  APInt lo(*this);
>>> +  lo.lshr(rotateAmt);
>>> +  hi.shl(BitWidth - rotateAmt);
>>> +  return hi | lo;
>>> +}
>>
>> Do these work for rotamt = 0 ?
>
> Yes, but results are undefined (in our case value 0). This behavior is
> implemented in lshr and shl.

I don't understand.  Rotate by 0 is well defined.  Rotate by "32"  
isn't.  does lshl/lshr do the 'right' thing with "32" ?

-Chris




More information about the llvm-commits mailing list