Switching to use foo struct on Windows VM

John M McIntosh johnmci at smalltalkconsulting.com
Sun Jul 15 21:33:54 UTC 2007

> While you, people, fighting with different GCC compilers to force them
> produce optimal code, my intent is to PROVIDE this optimal code
> written by hands and compiled by Exupery. And in my case, if things go
> well, example above will prove nothing, because i will be able to
> reimplement any VM function (even interpret() ) and have much better
> control on how to avoid producing extra jumps/calls.

Well sure all you need to do is take


	self fetchNextBytecode.
	"this bytecode will be expanded so that refs to currentBytecode  
below will be constant"
	self pushReceiverVariable: (currentBytecode bitAnd: 16rF).

which requires all these routines

	"This method fetches the next instruction (bytecode). Each bytecode  
method is responsible for fetching the next bytecode, preferably as  
early as possible to allow the memory system time to process the  
request before the next dispatch."

	currentBytecode := self fetchByte.

	"This method uses the preIncrement builtin function which has no  
Smalltalk equivalent. Thus, it must be overridden in the simulator."

	^ self byteAtPointer: localIP preIncrement

pushReceiverVariable: fieldIndex

	self internalPush:
		(self fetchPointer: fieldIndex ofObject: receiver).

fetchPointer: fieldIndex ofObject: oop
	"index by word size, and return a pointer as long as the word size"

	^ self longAt: oop + BaseHeaderSize + (fieldIndex << ShiftForWord)

internalPush: object

	self longAtPointer: (localSP := localSP + BytesPerWord) put: object.

longAtPointer: pointer put: longValue
	"This gets implemented by Macros in C, where its types will also be  
	pointer is a raw address, and longValue is the width of a machine  

	^ self longAt: pointer put: longValue

which SLANG mushes into

			/* pushReceiverVariableBytecode */
				/* begin fetchNextBytecode */
				currentBytecode = byteAtPointer(++localIP);
				/* begin pushReceiverVariable: */
				/* begin internalPush: */
				longAtPointerput(localSP += BytesPerWord, longAt((foo->receiver +  
BaseHeaderSize) + ((0 & 15) << ShiftForWord)));

Then provide proper assembler for Intel (AMD/variations), powerpc,  
Risc, unknown. Although you can argue you could ignore 10% or less of  
population and just do intel, but the compiler and instruction  
purists would argue not all intel like CPUS like the same sequence of  
instruction mixes.

LIkely of course hand coded assembler *might* be better, although I  
think people now seem to think with multiple execution unit hardware and
smarter compilers that statement is becoming difficult to prove.

John M. McIntosh <johnmci at smalltalkconsulting.com>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com

More information about the Squeak-dev mailing list