[Vm-dev] Integer comparition primitive failures on Cog

Igor Stasenko siguctua at gmail.com
Mon May 2 13:46:16 UTC 2011


Btw,

i don't like this code:

	self assertClassOf: floatOrInt
		is: (objectMemory splObj: ClassFloat)
		compactClassIndex: ClassFloatCompactIndex.

the purpose of it is to check if given object is an instance of compact class,
and if it is ,then you don't have to fetch class (because you only
need to check that compact index is same
as compact index for class you are checking for).

So, it says that (objectMemory splObj: ClassFloat) will be optimized away
if comparison successfull..
but i think it would be better to use different assertion to be not
dependent from compiler optimizations:

is: oop instanceOfClass: classObjectIndex compactClassIndex: compactClassIndex
	"Answer if oop is an instance of the given class. If the class has a (non-zero)
	 compactClassIndex use that to speed up the check.  N.B. Inlining should
	 result in classOop not being accessed if compactClassIndex is non-zero."

	| ccIndex |
	<inline: true>
	(self isIntegerObject: oop) ifTrue:
		[^false].

	ccIndex := self compactClassIndexOf: oop.
	compactClassIndex ~= 0 ifTrue:
		[^compactClassIndex == ccIndex].

	^ccIndex = 0
	  and: [((self classHeader: oop) bitAnd: AllButTypeMask) = (self
splObj: classObjectIndex)]


so the difference that you passing a class index as argument, but not
class itself.
So even if compiler will fail to optimize it, it won't cost you extra
load from special objects array.
So instead of writing:

	self assertClassOf: floatOrInt
		is: (objectMemory splObj: ClassFloat)
		compactClassIndex: ClassFloatCompactIndex.

the code can be refactored to use:

	self assertClassOf: floatOrInt
		isSplObj: ClassFloat
		compactClassIndex: ClassFloatCompactIndex.

(which calls #is:instanceOfClass:compactClassIndex: above)

-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list