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

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


Fixed up some comments/etc.



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/6c3f6923/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-APInt-Implement-tcDecrement-as-a-counterpart-to-tcIn.patch
Type: application/octet-stream
Size: 4426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130528/6c3f6923/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130528/6c3f6923/attachment-0001.html>


More information about the llvm-commits mailing list