VM Maker: VMMaker.oscog-eem.2722.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker.oscog-eem.2722.mcz

commits-2
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2722.mcz

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

Name: VMMaker.oscog-eem.2722
Author: eem
Time: 4 March 2020, 3:53:28.328412 pm
UUID: 53079d01-9f06-4934-8aa2-6a6ecc80dc4e
Ancestors: VMMaker.oscog-eem.2721

Interpreter: Fix compilation of primitiveHighBit on MSVC.  We take the address of a variable by using (self addressOf: var), not "var address".

=============== Diff against VMMaker.oscog-eem.2721 ===============

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"
+ objectMemory numSmallIntegerTagBits > 1 ifTrue:
+ [integerReceiverOop := (integerReceiverOop >>> (self numSmallIntegerTagBits-1) bitOr: 1)].
- objectMemory numSmallIntegerTagBits > 1
- ifTrue: [integerReceiverOop := (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))].
  ^self].
  self cppIf: #'__GNUC__' defined not & (#'_MSC_VER' defined | #'__ICC' 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 an automatic initialization at a worse place if this isn't initialized explicitly."
- "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"
  self cCode: [objectMemory wordSize = 4
+ ifTrue: [self _BitScanReverse: (self addressOf: highestBitZeroBased) _: integerReceiverOop]
+ ifFalse: [self _BitScanReverse64: (self addressOf: highestBitZeroBased) _: integerReceiverOop]]
- ifTrue: [self _BitScanReverse: highestBitZeroBased address _: integerReceiverOop]
- ifFalse: [self _BitScanReverse64: highestBitZeroBased address _: integerReceiverOop]]
  inSmalltalk: [highestBitZeroBased := integerReceiverOop highBit - 1].
  "thanks to the tag bit, the +1 operation for getting 1-based rank is not necessary"
  self pop: 1 thenPushInteger: highestBitZeroBased].
  ^self].
  self cppIf:  #'__GNUC__' defined not & #'_MSC_VER' defined not & #'__ICC' defined not
  ifTrue:
  ["not gcc/clang, nor MSVC/ICC, you have to implement if your compiler provide useful builtins"
  self cCode:
  [self primitiveFail]
  inSmalltalk: "Simulate so that the simulatror is closer to the actual VM"
  [integerReceiverOop < 0
  ifTrue: [self primitiveFail]
  ifFalse: [self pop: 1 thenPushInteger: integerReceiverOop highBit - 1]]]!