[Vm-dev] VM Maker: VMMaker.oscog-nice.2543.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Sep 4 19:29:05 UTC 2019


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2543.mcz

==================== Summary ====================

Name: VMMaker.oscog-nice.2543
Author: nice
Time: 27 August 2019, 5:42:55.856384 am
UUID: 4d58051c-e032-4926-851a-e04c8f477aa2
Ancestors: VMMaker.oscog-nice.2542

Fixup stupid refactoring bug...

=============== Diff against VMMaker.oscog-nice.2542 ===============

Item was changed:
  ----- Method: InterpreterPrimitives>>primitiveHighBit (in category 'arithmetic integer primitives') -----
  primitiveHighBit
  	| integerReceiverOop leadingZeroCount highestBitZeroBased |
  	integerReceiverOop := self stackTop.
  	"Convert the receiver Oop to use a single tag bit"
  	self numSmallIntegerTagBits > 1
+ 		ifTrue: [integerReceiverOop := (integerReceiverOop >>> (self numSmallIntegerTagBits-1) bitOr: 1)].
- 		ifTrue: [integerReceiverOop := objectMemory integerValueOf: (integerReceiverOop >>> (self numSmallIntegerTagBits-1) bitOr: 1)].
  	self cppIf: #'__GNUC__' defined
  		ifTrue:
  			["Note: in gcc, result is undefined if input is zero (for compatibility with BSR fallback when no CLZ instruction available).
  			but input is never zero because we pass the oop with tag bits set, so we are safe"
  			objectMemory wordSize = 4
  				ifTrue: [leadingZeroCount := self __builtin_clz: integerReceiverOop]
  				ifFalse: [leadingZeroCount := self __builtin_clzll: integerReceiverOop].
  			leadingZeroCount = 0
  				ifTrue:
  					["highBit is not defined for negative Integer"
  					self primitiveFail]
  				ifFalse:
  					["Nice bit trick: 1-based high-bit is (32 - clz) - 1 to account for tag bit.
  					This is like two-complement - clz - 1 on 5 bits, or in other words a bit-invert operation clz ^16r1F"
  					self pop: 1 thenPushInteger: (leadingZeroCount bitXor: (BytesPerWord * 8 - 1))]]
  		ifFalse: [self cppIf: #'_MSC_VER' defined
  			ifTrue:
  				["In MSVC, _lzcnt and _lzcnt64 builtins do not fallback to BSR when not supported by CPU
  				Instead of messing with __cpuid() we always use the BSR intrinsic"
  				
  				"Trick: we test the oop sign rather than the integerValue. Assume oop are signed (so far, they are, sqInt are signed)"
  				integerReceiverOop < 0 ifTrue: [self primitiveFail] ifFalse: [		
  				"Setting this variable is useless, but VMMaker will generate it at a worse place"
  				highestBitZeroBased := 0.
  				"We do not even test the return value, because integerReceiverOop is never zero"
  				objectMemory wordSize = 4
  					ifTrue: [self _BitScanReverse: highestBitZeroBased address _: integerReceiverOop]
  					ifFalse: [self _BitScanReverse64: highestBitZeroBased address _: integerReceiverOop].
  				"thanks to the tag bit, the +1 operation for getting 1-based rank is not necessary"
  				self pop: 1 thenPushInteger: highestBitZeroBased]]
  			ifFalse:
  				["not gcc/clang, nor MSVC, you have to implement if your compiler provide useful builtins"
  				self primitiveFail]].!



More information about the Vm-dev mailing list