<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 20, 2015 at 7:04 PM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On Mon, Jul 20, 2015 at 04:48:35PM -0400, David T. Lewis wrote:<br>
&gt; Eliot,<br>
&gt;<br>
&gt; Thanks for this explanation. I had not spotted the discrepancy in the<br>
&gt; sqComplexEvent struct. Yikes! no way that could work.<br>
<br>
... except that sqComplexEvent does not appear to be used anywhere except<br>
the iOS code base, either in oscog or trunk platform sources. The declaration<br>
of sqComplexEvent was definitely not right, since it would work only for<br>
the case of sizeof(sqInt) == 4. But I don&#39;t see how that would impact a<br>
VM that does not make any reference to sqComplexEvent.<br>
<br>
I tried applying the change to make event fields long rather than int,<br>
checking for the effect on a format 68002 image (64 bit, 64-bit interpreter<br>
VM). Everything still works (as expected), but the annoying problem I have<br>
been seeing (need to wiggle the mouse to keep background unit tests active,<br>
hence my hunch that the issue is related to event structures) is not affected.<br>
<br>
The original declaration of sqComplexEvent was wrong. The approach of<br>
changing the fields from int to long would be a reasonable fix for that<br>
problem. But I thing it&#39;s a red herring, and I still suspect that the<br>
64-bit Spur image issue addressed in VMMaker.oscog-eem.1417 was actually<br>
caused by time stamp conversion, and fixed in your later VMMaker.oscog-eem.1426<br>
update.<br>
<br>
I&#39;m sorry I can&#39;t test to confirm, but I&#39;ll bet that if you revert the<br>
sqInputEvent fields to be int (original declaration) rather than long,<br>
the 64-bit Spur VM will still work just fine.<br></blockquote><div><br></div><div>That&#39;s right.  But that doesn&#39;t mean evtBuf shouldn&#39;t be changed.  Since I need an iOS VM, and the change is correct, I&#39;m not about to revert this change.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Dave<br>
<br>
<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Dave<br>
&gt;<br>
&gt; &gt;  Hi David,<br>
&gt; &gt;<br>
&gt; &gt; On Sun, Jul 19, 2015 at 8:52 PM, David T. Lewis &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt;<br>
&gt; &gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; On Sun, Jul 19, 2015 at 11:35:46AM -0400, David T. Lewis wrote:<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; On Sat, Jul 18, 2015 at 09:51:30PM -0700, Eliot Miranda wrote:<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; On Sat, Jul 18, 2015 at 8:10 PM, David T. Lewis<br>
&gt; &gt;&gt; &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt;<br>
&gt; &gt;&gt; wrote:<br>
&gt; &gt;&gt; &gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; &gt; I may be missing something, but I do not see anything about the<br>
&gt; &gt;&gt; Spur<br>
&gt; &gt;&gt; &gt; &gt; &gt; 64-bit image format that should require special handling for this.<br>
&gt; &gt;&gt; &gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Yes, I think you&#39;re missing something.  let me take you through it.<br>
&gt; &gt;&gt; We&#39;re<br>
&gt; &gt;&gt; &gt; &gt; talking about evaluating, in a 64-bit C, sizeof(long) == 8,<br>
&gt; &gt;&gt; sizeof(int) ==<br>
&gt; &gt;&gt; &gt; &gt; 4, the following two variants:<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; #define MillisecondClockMask 0x1FFFFFFF<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; (sqInt)((MillisecondClockMask &lt;&lt; 3) + 1L)<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; (sqInt)(((sqInt)MillisecondClockMask &lt;&lt; 3) + 1L)<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; So let&#39;s take the first.  The type of MillisecondClockMask is int.<br>
&gt; &gt;&gt; The<br>
&gt; &gt;&gt; &gt; &gt; type of MillisecondClockMask &lt;&lt; 3 is int.  It&#39;s bit-pattern is<br>
&gt; &gt;&gt; 0xFFFFFFF8,<br>
&gt; &gt;&gt; &gt; &gt; and hence its value is, incorrectly, -8.  So it evaluates to the<br>
&gt; &gt;&gt; &gt; &gt; SmallInteger -1, not 16r1FFFFFFF as desired.<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; In the second, the type of MillisecondClockMask is int. The type of<br>
&gt; &gt;&gt; &gt; &gt; (sqInt) MillisecondClockMask is long.  The type<br>
&gt; &gt;&gt; &gt; &gt; of ((sqInt)MillisecondClockMask &lt;&lt; 3).  It&#39;s bit pattern is also<br>
&gt; &gt;&gt; 0xFFFFFFF8<br>
&gt; &gt;&gt; &gt; &gt; but its value is 0xFFFFFFF8, /not/ -8, and so it evaluates to the<br>
&gt; &gt;&gt; &gt; &gt; SMallInteger 16r1FFFFFFF as desired.<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Does that make sense?<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; Yes, the shift left 3 (rather that 1 in the old object format) is what<br>
&gt; &gt;&gt; I<br>
&gt; &gt;&gt; &gt; was missing.<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; I suspect that a cast to usqInt would accomplish the same thing<br>
&gt; &gt;&gt; without<br>
&gt; &gt;&gt; &gt; the ifTrue: test. Sorry I can&#39;t try it right now but it might be worth<br>
&gt; &gt;&gt; a<br>
&gt; &gt;&gt; &gt; look.<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; At the risk of further annoyance, here is one more question/observation:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; In VMMaker.oscog-eem.1417 (and sq.h in platforms sources), we change the<br>
&gt; &gt;&gt; type of the event buffer from int[8] to long[8], which corrects a<br>
&gt; &gt;&gt; failure<br>
&gt; &gt;&gt; in starting in the 64-bit Spur image. I don&#39;t know exactly what was<br>
&gt; &gt;&gt; failing,<br>
&gt; &gt;&gt; but I am suspecting perhaps the time stamp field in the event struct was<br>
&gt; &gt;&gt; being incorrectly converted from its 32 bit int value to an integer<br>
&gt; &gt;&gt; object<br>
&gt; &gt;&gt; in primitiveGetNextEvent, and that using long rather than int fields<br>
&gt; &gt;&gt; prevented this from happening.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Later, in VMMaker.oscog-eem.1426 we have the fix for conversion of<br>
&gt; &gt;&gt; integer<br>
&gt; &gt;&gt; value to integer object, which particularly affected conversion of<br>
&gt; &gt;&gt; millisecond clock values. So I wonder if the fix in<br>
&gt; &gt;&gt; VMMaker.oscog-eem.1426<br>
&gt; &gt;&gt; might make the changes in VMMaker.oscog-eem.1417 unnecessary? And if so,<br>
&gt; &gt;&gt; can the fields of the sqInputEvent struct be changed back from long to<br>
&gt; &gt;&gt; int (possibly with some performance advantage)?<br>
&gt; &gt;&gt;<br>
&gt; &gt;<br>
&gt; &gt; Well, indeed the commit comment on  VMMaker.oscog-eem.1417 is wrong, in<br>
&gt; &gt; that the size of the evtBuf wasn&#39;t the cause of the bug.  But there /is/ a<br>
&gt; &gt; bug here with 64-bits.  Look at platforms/Cross/vm/sq.h:<br>
&gt; &gt;<br>
&gt; &gt; The generic input event conforms to int evtBuf[8]:<br>
&gt; &gt;<br>
&gt; &gt; /* generic input event */<br>
&gt; &gt; typedef struct sqInputEvent<br>
&gt; &gt; {<br>
&gt; &gt;   int type;         /* type of event; either one of EventTypeXXX */<br>
&gt; &gt;   unsigned int timeStamp;   /* time stamp */<br>
&gt; &gt;   /* the interpretation of the following fields depend on the type of the<br>
&gt; &gt; event */<br>
&gt; &gt;   int unused1;<br>
&gt; &gt;   int unused2;<br>
&gt; &gt;   int unused3;<br>
&gt; &gt;   int unused4;<br>
&gt; &gt;   int unused5;<br>
&gt; &gt;   int windowIndex;      /* SmallInteger used in image to identify a host<br>
&gt; &gt; window structure */<br>
&gt; &gt; } sqInputEvent;<br>
&gt; &gt;<br>
&gt; &gt; But the complex event *does not*:<br>
&gt; &gt;<br>
&gt; &gt; typedef struct sqComplexEvent<br>
&gt; &gt;     {<br>
&gt; &gt;         int type;           /* type of event;  EventTypeComplex */<br>
&gt; &gt;         unsigned int timeStamp; /* time stamp */<br>
&gt; &gt;         /* the interpretation of the following fields depend on the type<br>
&gt; &gt;  of the event */<br>
&gt; &gt;         int action;             /* one of ComplexEventXXX (see below) */<br>
&gt; &gt;         usqInt objectPointer;   /* used to point to object */<br>
&gt; &gt;         int unused1;            /*  */<br>
&gt; &gt;         int unused2;            /*  */<br>
&gt; &gt;         int unused3;            /*  */<br>
&gt; &gt;         int windowIndex;    /* host window structure */<br>
&gt; &gt;     } sqComplexEvent;<br>
&gt; &gt;<br>
&gt; &gt; In 64-bits usqInt objectPointer occupies 64-bits, not 32, and so<br>
&gt; &gt; a sqComplexEvent does not conform to int evtBuf[8].<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Hence my solution is to change evtBuf to long evtBuf[8], and change all<br>
&gt; &gt; the<br>
&gt; &gt; fields in the events from (unsigned) int to (unsigned) long.  There is no<br>
&gt; &gt; performance issue with 32-bits; sizeof(long) == sizeof(int), and in 64<br>
&gt; &gt; bits<br>
&gt; &gt; it won&#39;t make any difference either; events are simply not that frequent<br>
&gt; &gt; for this to be an issue.<br>
&gt; &gt;<br>
&gt; &gt; HTH<br>
&gt; &gt;<br>
&gt; &gt; _,,,^..^,,,_<br>
&gt; &gt; best, Eliot<br>
&gt; &gt;<br>
&gt;<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>