<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-02 13:42 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>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On Wed, Jul 02, 2014 at 08:01:35AM +0200, Nicolas Cellier wrote:<br>
&gt;<br>
&gt; 2014-07-02 7:44 GMT+02:00 Nicolas Cellier &lt;<br>
&gt; <a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>&gt;:<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; 2014-07-02 0:28 GMT+02:00 David T. Lewis &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt;:<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;&gt; On Tue, Jul 01, 2014 at 09:21:00PM +0200, Nicolas Cellier wrote:<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; 2014-07-01 4:22 GMT+02:00 &lt;<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>&gt;:<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Item was changed:<br>
&gt; &gt;&gt; &gt; &gt;   ----- Method: LargeIntegersPlugin&gt;&gt;cDigitSub:len:with:len:into: (in<br>
&gt; &gt;&gt; &gt; &gt; category &#39;C core&#39;) -----<br>
&gt; &gt;&gt; &gt; &gt; + cDigitSub: pByteSmall len: smallLen with: pByteLarge len: largeLen<br>
&gt; &gt;&gt; into:<br>
&gt; &gt;&gt; &gt; &gt; pByteRes<br>
&gt; &gt;&gt; &gt; &gt; +       | z |<br>
&gt; &gt;&gt; &gt; &gt; - cDigitSub: pByteSmall<br>
&gt; &gt;&gt; &gt; &gt; -               len: smallLen<br>
&gt; &gt;&gt; &gt; &gt; -               with: pByteLarge<br>
&gt; &gt;&gt; &gt; &gt; -               len: largeLen<br>
&gt; &gt;&gt; &gt; &gt; -               into: pByteRes<br>
&gt; &gt;&gt; &gt; &gt; -       | z limit |<br>
&gt; &gt;&gt; &gt; &gt;         &lt;var: #pByteSmall type: &#39;unsigned char * &#39;&gt;<br>
&gt; &gt;&gt; &gt; &gt;         &lt;var: #pByteLarge type: &#39;unsigned char * &#39;&gt;<br>
&gt; &gt;&gt; &gt; &gt;         &lt;var: #pByteRes type: &#39;unsigned char * &#39;&gt;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; +       z := 0. &quot;Loop invariant is -1&lt;=z&lt;=1&quot;<br>
&gt; &gt;&gt; &gt; &gt; +       0 to: smallLen - 1 do:<br>
&gt; &gt;&gt; &gt; &gt; -       z := 0.<br>
&gt; &gt;&gt; &gt; &gt; -       &quot;Loop invariant is -1&lt;=z&lt;=1&quot;<br>
&gt; &gt;&gt; &gt; &gt; -       limit := smallLen - 1.<br>
&gt; &gt;&gt; &gt; &gt; -       0 to: limit do:<br>
&gt; &gt;&gt; &gt; &gt;                 [:i |<br>
&gt; &gt;&gt; &gt; &gt;                 z := z + (pByteLarge at: i) - (pByteSmall at: i).<br>
&gt; &gt;&gt; &gt; &gt; +               pByteRes at: i put: z - (z // 256 * 256).<br>
&gt; &gt;&gt; &quot;sign-tolerant<br>
&gt; &gt;&gt; &gt; &gt; form of (z bitAnd: 255)&quot;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; Frankly, having z declared unsigned int and just doing  pByteRes at: i<br>
&gt; &gt;&gt; put:<br>
&gt; &gt;&gt; &gt; (z bitAnd: 16rFF) as I suggested would be way way simpler and will<br>
&gt; &gt;&gt; ALWAYS<br>
&gt; &gt;&gt; &gt; work.<br>
&gt; &gt;&gt; &gt; Why the hell invoke the complications of signed arithmetic when the<br>
&gt; &gt;&gt; content<br>
&gt; &gt;&gt; &gt; pByteRes is unsigned???<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Nicolas,<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; This sounds right to me.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Do you have a final version of #cDigitSub:len:with:len:into: that you can<br>
&gt; &gt;&gt; recommend? The version in VMMaker-nice.342 produces failures in the<br>
&gt; &gt;&gt; KernelTests-Numbers tests when compiled in 64-bit mode, but I think that<br>
&gt; &gt;&gt; you have since suggested some other improvements in this email thread.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Dave<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt; Hi David,<br>
&gt; &gt; that&#39;s interesting. VMMaker-nice.342 contains all the 32bits LargeInteger<br>
&gt; &gt; modifications, not just the #cDigitSub:len:with:len:into:.<br>
&gt; &gt; I tried to declare everything as &lt;unsigned int&gt; rather than &lt;usqInt&gt; with<br>
&gt; &gt; the assumption that sizeof(unsigned int)*2==sizeof(unsigned long long).<br>
&gt; &gt; But I never tried to compile a 64 bits VM, I think I lost the recipe for<br>
&gt; &gt; brewing such a flavour.<br>
&gt; &gt; I&#39;m on MacOSX, could you provide a link to the shortest way to do it?<br>
&gt; &gt; Once I can check it, I&#39;ll publish a corrected version.<br>
&gt; &gt; Thanks<br>
&gt; &gt;<br>
&gt; &gt; Nicolas<br>
&gt; &gt;<br>
&gt;<br>
&gt; One thing I remember is that my modifications are full of hardcoded<br>
&gt; constants like 16rFFFFFFFF that are making the code hardly future proof.<br>
&gt; Normally, I would never code like that in C, but use standard macros like<br>
&gt; UINT_MAX.<br>
&gt; It&#39;s just that I don&#39;t know how to do it in SLANG...<br>
&gt; Any hint?<br>
&gt;<br>
&gt; As for our own constants, like SmallInteger minVal and maxVal, we should<br>
&gt; really have our own MACRO for this, there are way too many repetitions of<br>
&gt; these constants spreaded in the code.<br>
<br>
</div></div>In VMM trunk, see CCodeGenerator&gt;&gt;emitDefineBytesPerWordOn: as well as the<br>
methods in category &#39;constants&#39; in ObjectMemory. The constants defined in this<br>
manner form the basis for generating code that can be compiled for either<br>
32-bit or 64-bit images.<br>
<br>
BTW, this is what makes it is easy to test your #cDigitSub:len:with:len:into:<br>
change on various VM and image word sizes. The combination of 64-bit VM with<br>
32-bit image is by far the best for finding bugs, but a 64-bit image sometimes<br>
produces interesting results too.<br>
<br>
Dave<br>
<br>
</blockquote></div><br></div><div class="gmail_extra">Thanks both,<br></div><div class="gmail_extra">I had forgotten that we MUST have a way to simulate the VM, so C-Header only is a no go.<br></div><div class="gmail_extra">
I&#39;ll inquire as soon as I find time.<br><br></div><div class="gmail_extra">Nicolas<br></div></div>