[Vm-dev] Cog Primitive Performance

Andres Valloud avalloud at smalltalk.comcastbiz.net
Tue Apr 18 02:02:35 UTC 2017


On 4/17/17 16:45 , Eliot Miranda wrote:
> FYI, hash multiply is
> hashMultiply
> | low |
> low := self bitAnd: 16383.
> ^(16r260D * low + ((16r260D * (self bitShift: -14) + (16r0065 * low)
> bitAnd: 16383) * 16384))
> bitAnd: 16r0FFFFFFF
>
> and when written as a primitive is
> hashMultiply
> | low |
> low := self bitAnd: 16383.
> ^(16r260D * low + (16r260D * (self bitShift: -14) + (16r0065 * low) *
> 16384))
> bitAnd: 16r0FFFFFFF
> because we don't care about the multiply by 16384 overflowing; when
> written as a primitive it won't overflow into a LargePositiveInteger.

Hopefully this doesn't mean the primitive got implemented by actually 
doing these operations verbatim.  As you have probably seen, that 
convoluted arithmetic is done this way in Smalltalk only to simulate a 
32x32 multiplication bit-anded down to 28 bits without overflowing into 
large integers (the original code from August 2000 had my initials).

At a sufficiently low level such as C, all that complexity is just an 
unsigned multiplication by 1664525.  The image code should still have a 
comment to that effect, did it get lost?

Andres.


More information about the Vm-dev mailing list