<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 1, 2014 at 12:21 PM, Nicolas Cellier <span dir="ltr"><<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-01 4:22 GMT+02:00 <span dir="ltr"><<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Item was changed:<br>
----- Method: LargeIntegersPlugin>>cDigitSub:len:with:len:into: (in category 'C core') -----<br>
+ cDigitSub: pByteSmall len: smallLen with: pByteLarge len: largeLen into: pByteRes<br>
+ | z |<br>
- cDigitSub: pByteSmall<br>
- len: smallLen<br>
- with: pByteLarge<br>
- len: largeLen<br>
- into: pByteRes<br>
- | z limit |<br>
<var: #pByteSmall type: 'unsigned char * '><br>
<var: #pByteLarge type: 'unsigned char * '><br>
<var: #pByteRes type: 'unsigned char * '><br>
<br>
+ z := 0. "Loop invariant is -1<=z<=1"<br>
+ 0 to: smallLen - 1 do:<br>
- z := 0.<br>
- "Loop invariant is -1<=z<=1"<br>
- limit := smallLen - 1.<br>
- 0 to: limit do:<br>
[:i |<br>
z := z + (pByteLarge at: i) - (pByteSmall at: i).<br>
+ pByteRes at: i put: z - (z // 256 * 256). "sign-tolerant form of (z bitAnd: 255)"<br></blockquote><div><br></div><div>Frankly, having z declared unsigned int and just doing pByteRes at: i put: (z bitAnd: 16rFF) as I suggested would be way way simpler and will ALWAYS work.<br>
</div><div>Why the hell invoke the complications of signed arithmetic when the content pByteRes is unsigned???<br></div></div></div></div></blockquote><div><br></div><div>I'm not maintaining the plugin. But I broke it in fixing the unsigned division anomaly. I just wanted it to work again as quickly as possibly without expending effort. I made the minimum changes I could to keep it working. I'm much happier to have you maintain the plugin. You have the expertise and experience.</div>
<div><br></div><div>Nicolas, my priority is to have Spur working. I don't want to have to expend lots of energy changing plugins to get Spur working. My submitting this fix is not an endorsement of any kind. It's merely expediency.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Even if z is declared signed, (z bitAnd: 255) would work on a vast majority of compiler/processor because most compiler/processor would use a 2-complement representation.<br>
</div><div>But it's technically implementation-defined.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ z := z signedBitShift: -8].<br></blockquote><div><br></div><div>i think this one is OK too on a vast majority of machines, but this is as well technically implementation defined.<br></div><div>Some weird compiler/processor pair may as well fill left bits with zeroes, or not even use 2-complement...<br>
<br></div><div>z here is a carry and should contain either 0, or -1 (that is UINT_MAX) after this operation.<br></div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ smallLen to: largeLen - 1 do:<br>
- pByteRes at: i put: z - (z // 256 * 256).<br>
- "sign-tolerant form of (z bitAnd: 255)"<br>
- z := z // 256].<br>
- limit := largeLen - 1.<br>
- smallLen to: limit do:<br>
[:i |<br>
z := z + (pByteLarge at: i) .<br>
+ pByteRes at: i put: z - (z // 256 * 256). "sign-tolerant form of (z bitAnd: 255)"<br>
+ z := z signedBitShift: -8].<br>
- pByteRes at: i put: z - (z // 256 * 256).<br>
- "sign-tolerant form of (z bitAnd: 255)"<br>
- z := z // 256].<br>
!<br></blockquote></div><br></div><div class="gmail_extra">Isn't there another funny signed shift in Large Integer division?<br></div><div class="gmail_extra">This would deserve a review too, because division is inlining its own sort of subtraction...<br>
</div></div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>