<div dir="ltr">Hi Juan,<div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 28, 2017 at 4:32 AM, Juan Vuletich <span dir="ltr"><<a href="mailto:JuanVuletich@zoho.com" target="_blank">JuanVuletich@zoho.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Hi Folks,<br>
<br>
In 32 bit Cog VMs, `Time primHighResClock` answers LargePositiveInteger, presumably up to 64 bits. This would mean a rollover in 167 years on a 3.5GHz machine.<br>
<br>
But on 64 bit Cog and Stack Spur VMs, it answers a SmallInteger that is truncated to 32 bits. This means a rollover in about one second.<br></blockquote><div><br></div><div>Are you sure?  What's a test case?  When I look at the source I don't see where this is happening:</div><div><br></div><div>platforms/Cross/vm/sq.h:sqLong ioHighResClock(void);</div><div><br></div><div>InterpreterPrimitives>>primitiveHighResClock</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>"Return the value of the high resolution clock if this system has any. The exact frequency of the high res clock is undefined specifically so that we can use processor dependent instructions (like RDTSC). The only use for the high res clock is for profiling where we can allocate time based on sub-msec resolution of the high res clock. If no high-resolution counter is available, the platform should return zero."</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span><export: true></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>self pop: 1.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>self push: (self positive64BitIntegerFor: self ioHighResClock).</div><div><br></div><div>And positive64BitIntegerFor: does not truncate to 32-bits:</div><div><br></div><div><div>StackInterpreter>>positive64BitIntegerFor: integerValue</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span><api></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span><var: 'integerValue' type: #usqLong></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span><var: 'highWord' type: #'unsigned int'></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>"Answer a Large Positive Integer object for the given integer value.  N.B. will *not* cause a GC."</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>| newLargeInteger highWord sz |</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>objectMemory hasSixtyFourBitImmediates</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">         </span>ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>[(self cCode: [integerValue] inSmalltalk: [integerValue bitAnd: 1 << 64 - 1]) <= objectMemory maxSmallInteger ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                         </span>[^objectMemory integerObjectOf: integerValue].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                 </span> sz := 8]</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">              </span>ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>[(highWord := integerValue >> 32) = 0 ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                            </span>[^self positive32BitIntegerFor: integerValue].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                 </span> sz := 5.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                      </span> (highWord := highWord >> 8) = 0 ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>[sz := sz + 1.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                         </span> (highWord := highWord >> 8) = 0 ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span>[sz := sz + 1.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                 </span> (highWord := highWord >> 8) = 0 ifFalse:[sz := sz + 1]]]].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>newLargeInteger := objectMemory</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                                        </span>eeInstantiateSmallClassIndex: ClassLargePositiveIntegerCompactIndex</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                                    </span>format: (objectMemory byteFormatForNumBytes: sz)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                                       </span>numSlots: 8 / objectMemory bytesPerOop.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>objectMemory storeLong64: 0 ofObject: newLargeInteger withValue: (objectMemory byteSwapped64IfBigEndian: integerValue).</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>^newLargeInteger</div></div><div><br></div><div><br></div><div>So on my reading, on 64-bits this answers un-truncated non-negative SmallIntegers up to 60 bits in length, and then overflows into 8 byte LargePositiveIntegers.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
I guesss this is a bug. Answering a SmallInteger, truncating the CPU 64 bit counter to 60 bits would be ok. I think it makes sense to restrict answer to SmallInteger to avoid allocation, and a rollover every 41 years is not too much :)<br>
<br>
Thanks,<span class="gmail-HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Juan Vuletich<br>
<a href="http://www.cuis-smalltalk.org" rel="noreferrer" target="_blank">www.cuis-smalltalk.org</a><br>
<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev" rel="noreferrer" target="_blank">https://github.com/Cuis-Smallt<wbr>alk/Cuis-Smalltalk-Dev</a><br>
@JuanVuletich<br>
<br>
<br>
</font></span></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>