<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div><br>On Jul 1, 2014, at 11:01 PM, Nicolas Cellier &lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><span></span></div></blockquote><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">2014-07-02 7:44 GMT+02:00 Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>&gt;</span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-02 0:28 GMT+02:00 David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span>:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br>
On Tue, Jul 01, 2014 at 09:21:00PM +0200, Nicolas Cellier wrote:<br>
&gt;<br>
&gt; 2014-07-01 4:22 GMT+02:00 &lt;<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>&gt;:<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt; Item was changed:<br>
&gt; &gt; &nbsp; ----- Method: LargeIntegersPlugin&gt;&gt;cDigitSub:len:with:len:into: (in<br>
&gt; &gt; category 'C core') -----<br>
&gt; &gt; + cDigitSub: pByteSmall len: smallLen with: pByteLarge len: largeLen into:<br>
&gt; &gt; pByteRes<br>
&gt; &gt; + &nbsp; &nbsp; &nbsp; | z |<br>
&gt; &gt; - cDigitSub: pByteSmall<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len: smallLen<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with: pByteLarge<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len: largeLen<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; into: pByteRes<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; | z limit |<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;var: #pByteSmall type: 'unsigned char * '&gt;<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;var: #pByteLarge type: 'unsigned char * '&gt;<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;var: #pByteRes type: 'unsigned char * '&gt;<br>
&gt; &gt;<br>
&gt; &gt; + &nbsp; &nbsp; &nbsp; z := 0. "Loop invariant is -1&lt;=z&lt;=1"<br>
&gt; &gt; + &nbsp; &nbsp; &nbsp; 0 to: smallLen - 1 do:<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; z := 0.<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; "Loop invariant is -1&lt;=z&lt;=1"<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; limit := smallLen - 1.<br>
&gt; &gt; - &nbsp; &nbsp; &nbsp; 0 to: limit do:<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [:i |<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z := z + (pByteLarge at: i) - (pByteSmall at: i).<br>
&gt; &gt; + &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pByteRes at: i put: z - (z // 256 * 256). "sign-tolerant<br>
&gt; &gt; form of (z bitAnd: 255)"<br>
&gt; &gt;<br>
&gt;<br>
&gt; Frankly, having z declared unsigned int and just doing &nbsp;pByteRes at: i put:<br>
&gt; (z bitAnd: 16rFF) as I suggested would be way way simpler and will ALWAYS<br>
&gt; work.<br>
&gt; Why the hell invoke the complications of signed arithmetic when the content<br>
&gt; pByteRes is unsigned???<br>
<br>
</div></div>Nicolas,<br>
<br>
This sounds right to me.<br>
<br>
Do you have a final version of #cDigitSub:len:with:len:into: that you can<br>
recommend? The version in VMMaker-nice.342 produces failures in the<br>
KernelTests-Numbers tests when compiled in 64-bit mode, but I think that<br>
you have since suggested some other improvements in this email thread.<br>
<br>
Dave<br>
<br>
</blockquote></div></div></div><br></div><div class="gmail_extra">Hi David,<br></div><div class="gmail_extra">that's interesting. VMMaker-nice.342 contains all the 32bits LargeInteger modifications, not just the #cDigitSub:len:with:len:into:.<br>

</div><div class="gmail_extra">I tried to declare everything as &lt;unsigned int&gt; rather than &lt;usqInt&gt; with the assumption that sizeof(unsigned int)*2==sizeof(unsigned long long).<br></div><div class="gmail_extra">

But I never tried to compile a 64 bits VM, I think I lost the recipe for brewing such a flavour.<br></div><div class="gmail_extra">I'm on MacOSX, could you provide a link to the shortest way to do it?<br></div><div class="gmail_extra">

Once I can check it, I'll publish a corrected version.<br></div><div class="gmail_extra">Thanks<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra">
Nicolas<br></div></font></span></div></blockquote><div><br></div><div>One thing I remember is that my modifications are full of hardcoded constants like 16rFFFFFFFF that are making the code hardly future proof.<br></div><div>
Normally, I would never code like that in C, but use standard macros like UINT_MAX.<br></div></div>It's just that I don't know how to do it in SLANG...<br></div><div class="gmail_extra">Any hint?<br></div></div></div></blockquote><div><br></div>You can use a symbol, e.g.<div>&nbsp; &nbsp; self cCode: [#'<span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">UINT_MAX'] inSmalltalk: [CUIntMax]</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">(assuming some global called&nbsp;</span><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">CUIntMax).</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">You can use a macro:</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">uintMax</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">&nbsp; &nbsp; &lt;cmacro: '()&nbsp;</span><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">UINT_MAX'&gt;</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">&nbsp; &nbsp; ^1024*</span><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">1024*</span><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">1024*2-1</span></div><div><div><br></div><div>In fact the second one's not bad cuz if you implement it in e.g. Spur32BitMemoryManager &amp;&nbsp;<span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">Spur64BitMemoryManager you can answer different values depending on assumed platform word size. &nbsp;Getting to that from a plugin however isn't easy.</span></div><div><br></div><div>There are loads if other ways too. &nbsp;e.g. adding support to CCodeGenerator for a well-defined set of C library constants. &nbsp;Or creating a SharedPool of C constants and adding special support for declaring them (ie /not/ declaring them).</div><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra">As for our own constants, like SmallInteger minVal and maxVal, we should really have our own MACRO for this, there are way too many repetitions of these constants spreaded in the code.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
Nicolas<br></div></div>
</div></blockquote></div></div></body></html>