VM Maker: VMMaker.oscog-eem.2934.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.2934.mcz

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

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

Name: VMMaker.oscog-eem.2934
Author: eem
Time: 14 January 2021, 9:48:15.416798 pm
UUID: 8fba4a5b-3424-47bb-b2de-f632bd307408
Ancestors: VMMaker.oscog-eem.2933

Fix a slip in primitiveHighBit when #'__GNUC__' defined

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

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 >>> (objectMemory 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].
- [self primitiveFail].
  "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))]
  cppIf: #'_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].
  "Setting this variable is useless, but VMMaker will generate an automatic initialization at a worse place if this isn't initialized explicitly."
  highestBitZeroBased := 0.
  "We do not even test the return value, because integerReceiverOop is never zero"
  objectMemory wordSize = 4
  ifTrue: [self _BitScanReverse: (self addressOf: highestBitZeroBased) _: integerReceiverOop]
  ifFalse: [self _BitScanReverse64: (self addressOf: highestBitZeroBased) _: 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/ICC, you have to implement if your compiler provides useful builtins"
  self cCode:
  [self primitiveFail]
  inSmalltalk: "Simulate so that the simulator is closer to the actual VM"
  [integerReceiverOop < 0 ifTrue:
  [^self primitiveFail].
  self pop: 1 thenPushInteger: integerReceiverOop highBit - 1]]!