[PATCH 1/2] IEEE-754R 2008 nextUp/nextDown implementation: tcDecrement

Michael Gottesman mgottesman at apple.com
Tue May 28 12:51:12 PDT 2013


I thought you weren't going to mention that in this medium = p. Someone like Chris might read it and who knows what will happen after that ("svn rm --force -m 'oops' $LLVM_SVN_URL" anyone?). Committed in r182801.

On May 28, 2013, at 12:41 PM, Stephen Canon <scanon at apple.com> wrote:

> LGTM now that my Top Secret Offline Comments have been addressed.
> 
> On May 28, 2013, at 3:36 PM, Michael Gottesman <mgottesman at apple.com> wrote:
> 
>> Fixed up some comments/etc.
>> 
>> <0001-APInt-Implement-tcDecrement-as-a-counterpart-to-tcIn.patch>
>> 
>> On May 28, 2013, at 11:40 AM, Michael Gottesman <mgottesman at apple.com> wrote:
>> 
>>> Truth.
>>> 
>>> See attached revised patch:
>>> 
>>> <0001-APInt-Implement-tcDecrement-as-a-counterpart-to-tcIn.patch>
>>> 
>>> On May 28, 2013, at 3:57 AM, Stephen Canon <scanon at apple.com> wrote:
>>> 
>>>> Hi Michael —
>>>> 
>>>> +  integerPart carry = 0;
>>>> +  const integerPart allones = ~integerPart(0);
>>>> +  for (unsigned int i = 0; i < parts; i++) {
>>>> +    integerPart oldvalue = dst[i];
>>>> +    if (carry) {
>>>> +      dst[i] += allones + 1;
>>>> +      carry = (dst[i] <= oldvalue);
>>>> +    } else {
>>>> +      dst[i] += allones;
>>>> +      carry = (dst[i] < oldvalue);
>>>> +    }
>>>> +  }
>>>> +
>>>> +  // We only borrow when dst == 0. Conclude since:
>>>> +  //   1. dst != 0 => dst + ~0 will overflow.
>>>> +  //   2. dst == 0 => dst + ~0 = ~0 no overflow.
>>>> +  // that if the ``carry'' flag is not set, we need to borrow.
>>>> +  return !carry;
>>>> +}
>>>> 
>>>> While this is correct, it can be made much, much simpler by taking advantage of the fact that the addend is -1.  Once you get a carry-out, the result of the operation is a no-op:
>>>> 
>>>> 	for (unsigned int i = 0; i < parts; i++) {
>>>> 		// If the current word is non-zero, then the decrement has no effect on
>>>> 		// higher-order words of the integer, and there is no borrow.
>>>> 		if (dst[i]--) return 0; 
>>>> 	}
>>>> 	// If every word was zero, then there is a borrow.
>>>> 	return 1;
>>>> 
>>>> – Steve
>>>> 
>>>> On May 27, 2013, at 9:50 PM, Michael Gottesman <mgottesman at apple.com> wrote:
>>>> 
>>>>> The attached patch is the first in a series of 2 patches which implement IEEE-754R 2008 nextUp/nextDown via the function APFloat::next.
>>>>> 
>>>>> This first patch implements the static function tcDecrement on APInt which decrements a bignum represented by a part count and an integerPart and returns the borrow flag. Unittests are included as well.
>>>>> 
>>>>> Please Review,
>>>>> Michael
>>>>> 
>>>>> <0001-APInt-Implement-tcDecrement-as-a-counterpart-to-tcIn.patch>_______________________________________________
>>>>> llvm-commits mailing list
>>>>> llvm-commits at cs.uiuc.edu
>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>> 
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130528/03ef4cff/attachment.html>


More information about the llvm-commits mailing list