[Vm-dev] Integer comparition primitive failures on Cog

Henrik Sperre Johansen henrik.s.johansen at veloxit.no
Mon May 2 11:06:53 UTC 2011


On 02.05.2011 12:48, Igor Stasenko wrote:
>
> Hmm.. that's really strange, because as far as i can see,
> the code there are the same:
>
> (primitive: 3)
>
> Interpreter>>primitiveLessThan
> 	| integerReceiver integerArgument |
> 	integerArgument := self popInteger.
> 	integerReceiver := self popInteger.
> 	self checkBooleanResult: integerReceiver<  integerArgument
>
> InterpreterPrimitives>>primitiveLessThan
> 	| integerReceiver integerArgument |
> 	integerArgument := self popInteger.
> 	integerReceiver := self popInteger.
> 	self checkBooleanResult: integerReceiver<  integerArgument
>
> and #popInteger also same (it fails if value on stack are not smallinteger).
> So, in Squeak VM comparison primitive also fails,
> which should lead to evaluating failure code.
Cog has translation methods for those primitives in cogit.c, see 
genSmallIntegerComparison.


> Also, a primitives for floats accepting a smallintegers as arguments,
> so by rewriting:
>
>
> SmallInteger>>  <  aNumber
> 	"Primitive. Compare the receiver with the argument and answer with
> 	true if the receiver is less than the argument. Otherwise answer false.
> 	Fail if the argument is not a SmallInteger. Essential. No Lookup. See
> 	Object documentation whatIsAPrimitive."
>
> 	<primitive: 3>
>         ^ aNumber>=  self
>
>
>   [1 to: 2000000 do: [:i |
>      i<  2354.234. ] timeToRun
>
> before:
>
> 8223
>
> after:
> 20
>
> so... 421 times faster :)
Yes, that's basically what I proposed to do in image, albeit in a 
different place.

Cheers,
Henry


More information about the Vm-dev mailing list