[OT] Gosling on the object/primitive gap

John M McIntosh johnmci at smalltalkconsulting.com
Wed Aug 13 01:33:12 UTC 2003


On Tuesday, August 12, 2003, at 05:39  PM, George Bosworth wrote:
> //here is the addition
> 		int a = b+c;
>
> //0000006e  lea ebp,[edi+ebx] ; Here is the one generated instruction

In squeak of course it's a bit longer, mind there isn't any indication  
of how the values get into edi and ebx
so I'll skip that and show the C, which a nice C compiler would chew on  
quite nicely, assuming we
loaded the oops into rcvr and arg

bytecodePrimAdd
				if (((rcvr & arg) & 1) != 0) {
					result = ((rcvr >> 1)) + ((arg >> 1));
					if ((result ^ (result << 1)) >= 0) {
						/* begin internalPop:thenPush: */
						longAtput(localSP -= (2 - 1) * 4, ((result << 1) | 1));

So because we don't know anything about the types, see anamorphic  
smalltalk for typeless smalltalk  optimizations ,we need to check the  
type, that's the first if statement, convert small integers objects to  
integers, do the addition and check for overflow. On overflow the  
fallback is to invoke a send + message on the two objects resulting in  
a very complex path to resolve the large integer object we need to  
create.

Mmm an optimization here might be to feed the result to  
signed32BitIntegerFor in say Interpreter>>pop2AndPushIntegerIfOK: then  
we can ignore the failure case.

anyone care to try that and put together a benchmark case?

--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===



More information about the Squeak-dev mailing list