<div dir="ltr">Hi Levente,<div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 18, 2017 at 3:13 PM, Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@caesar.elte.hu" target="_blank">leves@caesar.elte.hu</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"><span class="gmail-">On Tue, 18 Apr 2017, <a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a> wrote:<br>
<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">
Eliot Miranda uploaded a new version of Collections to project The Trunk:<br>
<a href="http://source.squeak.org/trunk/Collections-eem.746.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/trunk<wbr>/Collections-eem.746.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Collections-eem.746<br>
Author: eem<br>
Time: 18 April 2017, 2:10:45.148995 pm<br>
UUID: 8d9adaca-1401-4323-974f-1aed16<wbr>ae3688<br>
Ancestors: Collections-eem.745<br>
<br>
Nuke the pointless override of ByteSString class>>stringHash:initialHash: in ByteSymbol class. Rewrite the non-byte version to use the hashMultiply primitive.<br>
</blockquote>
<br></span>
Do you mean that the Smalltalk code is as quick as the primitive?<br></blockquote><div><br></div><div>No. I mean that the non-primitive version for WideString should use the hashMultiply primitive, not the decomposed non-primitive hashMultiply.</div><div> </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">
Because without the VM changes, the primitive is 3-4 times quicker than<br>
<br>
hash := speciesHash bitAnd: 16rFFFFFFF.<br>
1 to: aString size do: [:pos |<br>
hash := hash + (aString basicAt: pos) * 1664525 bitAnd: 16rFFFFFFF ].<br>
^ hash<br>
<br>
So, I presume such loop will still be slower even with the primitive for #hashMultiply.</blockquote><div><br></div><div>That's right. But</div><div><span style="white-space:pre"> </span>hash := (hash + (aString basicAt: pos)) hashMultiply<br></div><div>is much faster than</div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>hash := hash + (aString basicAt: pos).</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>"Begin hashMultiply"</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>low := hash bitAnd: 16383.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>hash := (16r260D * low + ((16r260D * (hash bitShift: -14) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF.</div></div><div><br></div><div>in the latest VMs which have a machine code primitive for hashMultiply. Im the measurements I posted yesterday they're twice as fast.</div><div> </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"><span class="gmail-HOEnZb"><font color="#888888"><br>
<br>
Levente</font></span><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<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>
=============== Diff against Collections-eem.745 ===============<br>
<br>
Item was removed:<br>
- ----- Method: ByteSymbol class>>stringHash:initialHash: (in category 'primitives') -----<br>
- stringHash: aString initialHash: speciesHash<br>
- ^ByteString stringHash: aString initialHash: speciesHash!<br>
<br>
Item was changed:<br>
----- Method: String class>>stringHash:initialHash: (in category 'primitives') -----<br>
stringHash: aString initialHash: speciesHash<br>
+ "Answer the hash of a byte-indexed string, using speciesHash as the initial value.<br>
+ See SmallInteger>>hashMultiply."<br>
+ | hash |<br>
- - | stringSize hash low |<br>
- stringSize := aString size.<br>
hash := speciesHash bitAnd: 16r0FFFFFFF.<br>
+ 1 to: aString size do:<br>
+ [:pos |<br>
+ hash := (hash + (aString basicAt: pos)) hashMultiply].<br>
+ ^hash!<br>
- 1 to: stringSize do: [ :pos |<br>
- hash := hash + (aString basicAt: pos).<br>
- "Begin hashMultiply"<br>
- low := hash bitAnd: 16383.<br>
- hash := (16r260D * low + ((16r260D * (hash // 16384) + (16r0065 * low) bitAnd: 16383) * 16384)) bitAnd: 16r0FFFFFFF ].<br>
- ^hash.<br>
- - - !<br>
</blockquote>
<br>
</div></div></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>