Odd

Tim Olson tim at jumpnet.com
Tue Apr 21 14:09:14 UTC 1998


>>The 
>>Compiler generates special bytecodes that attempt to perform SmallInteger 
>>arithmetic (and sometimes Float arithmetic, if that fails) directly 
>>without going through the standard method lookup that message sends 
>>normally do.  Only if those fail is the standard lookup performed.  
>
>Say, it checks if the receiver of the #* message is an immediate 
>smallinteger or float, doesn't it?

Yes, it checks both the receiver and its argument, and fails if they are 
not both SmallIntegers or Floats.

>Could it be 
>possible to copy that neat behaviour for my old good friend bitShift:?

Well, surprise: #bitShift: is already implemented as an arithmetic 
bytecode primitive!  It appears that the original supposition was wrong 
-- #bitShift: is not slower because it has to first go through the 
standard method lookup; rather, it looks like it is a bit slower than #* 
because the VM implementation of bytecodePrimBitShift just isn't as 
highly optimized as bytecodePrimMultiply.  #<< *is* much slower because 
it has to go through the standard method lookup.  FYI, here are some 
timings from my machine:

t1 _ Time millisecondsToRun:
	[1 to: 1000000 do: [:i | 1 * 256]].
t2 _ Time millisecondsToRun:
	[1 to: 1000000 do: [:i | 1 bitShift: 8]].
t3 _ Time millisecondsToRun:
	[1 to: 1000000 do: [:i | 1 << 8]].
Array with: t1 with: t2 with: t3.

-> (2633 3234 9083 )



     -- tim





More information about the Squeak-dev mailing list