Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2552.mcz
==================== Summary ====================
Name: VMMaker.oscog-eem.2552
Author: eem
Time: 5 September 2019, 2:47:36.304555 pm
UUID: ce35a940-f745-405c-8ecd-0f890493b657
Ancestors: VMMaker.oscog-eem.2551
And implement the primitiveDoMixedArithmetic accessor macro correctly for the interpreter-variables-in-struct regime.
=============== Diff against VMMaker.oscog-eem.2551 ===============
Item was changed:
----- Method: StackInterpreter>>primitiveDoMixedArithmetic (in category 'primitive support') -----
primitiveDoMixedArithmetic
"If primitiveDoMixedArithmetic is true, then primitive can handle the conversions:
SmallInteger arithmeticOp: Float (Small or Boxed)
SmallInteger compareOp: Float (Small or Boxed)
Else, the primitive fail in case of mixed arithmetic, and conversion should be performed at image side"
<api>
+ <cmacro: '() GIV(primitiveDoMixedArithmetic)'>
- <cmacro: '() primitiveDoMixedArithmetic'>
^primitiveDoMixedArithmetic!
Nicolas Cellier uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2548.mcz
==================== Summary ====================
Name: VMMaker.oscog-nice.2548
Author: nice
Time: 5 September 2019, 11:45:21.497902 am
UUID: 7e9a5859-39bb-054c-9e30-ecb8fab97761
Ancestors: VMMaker.oscog-nice.2547
Provide a more simulator friendly primitiveHighBit.
If the simulator can fake a '__GNUC__' defined, or '_MSC_VER', , then it should be able to emulate the primitive behavior.
Eliot, I hope it helps...
=============== Diff against VMMaker.oscog-nice.2547 ===============
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)].
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 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
- 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]]
+ 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 primitiveFail].!
- 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]].!
Item was changed:
----- Method: VMBasicConstants class>>namesDefinedAtCompileTime (in category 'C translation') -----
namesDefinedAtCompileTime
"Answer the set of names for variables that should be defined at compile time.
Some of these get default values during simulation, and hence get defaulted in
the various initializeMiscConstants methods. But that they have values should
/not/ cause the code generator to do dead code elimination based on their
default values. In particular, methods marked with <option: ANameDefinedAtCompileTime>
will be emitted within #if defined(ANameDefinedAtCompileTime)...#endif."
^#( VMBIGENDIAN
IMMUTABILITY
STACKVM COGVM COGMTVM SPURVM
PharoVM "Pharo vs Squeak"
TerfVM "Terf vs Squeak"
EnforceAccessControl "Newspeak"
CheckRememberedInTrampoline "IMMUTABILITY"
LLDB "As of lldb-370.0.42 Swift-3.1, passing funciton parameters to printOopsSuchThat fails with Internal error [IRForTarget]: Couldn't rewrite one of the arguments of a function call. Turning off link time optimization with -fno-lto has no effect. hence we define some debugging functions as being <option: LLDB>"
"processor related"
__ARM_ARCH__ __arm__ __arm32__ ARM32 __arm64__ ARM64
_M_I386 _X86_ i386 i486 i586 i686 __i386__ __386__ X86 I386
x86_64 __amd64 __x86_64 __amd64__ __x86_64__ _M_AMD64 _M_X64
+ "Compiler brand related"
+ __GNUC__
+ _MSC_VER
+ __ICC
+
"os related"
ACORN
- __GNUC__
__linux__
__MINGW32__
__OpenBSD__
__osf__
UNIX
WIN32 _WIN32 _WIN32_WCE
WIN64 _WIN64 _WIN64_WCE)!
Item was added:
+ ----- Method: VMClass>>__builtin_clz: (in category 'C library simulation') -----
+ __builtin_clz: anInteger
+ <doNotGenerate>
+ anInteger < 0 ifTrue: [^0].
+ ^32 - anInteger highBit!
Item was added:
+ ----- Method: VMClass>>__builtin_clzll: (in category 'C library simulation') -----
+ __builtin_clzll: anInteger
+ <doNotGenerate>
+ anInteger < 0 ifTrue: [^0].
+ ^64 - anInteger highBitOfMagnitude!
Nicolas Cellier uploaded a new version of VMMaker to project VM Maker Inbox:
http://source.squeak.org/VMMakerInbox/VMMaker.oscog-nice.2547.mcz
==================== Summary ====================
Name: VMMaker.oscog-nice.2547
Author: nice
Time: 31 August 2019, 2:02:51.22464 am
UUID: 66e4c466-c54c-4035-a7fa-6078386cbc66
Ancestors: VMMaker.oscog-nice.2546
Fix genPrimitiveHighBit
We must not modify ReceiverResultReg when we CompletePrimitive (in case of negative receiver).
Hence, like in WIN64, we must better use TempReg.
=============== Diff against VMMaker.oscog-nice.2546 ===============
Item was changed:
----- Method: CogObjectRepresentation>>genPrimitiveHighBit (in category 'primitive generators') -----
genPrimitiveHighBit
+ "Implementation notes: there are two reasons to use TempReg
+ -1) if primitive fails, ReceiverResultReg must remain unchanged (we CompletePrimitive)
+ -2) CLZ/BSR only work on 64bits for registers R0-R7 on Intel X64. But Win64 uses R9
+ Normally, this should be backEnd dependent, but for now we have a single 64bits target..."
+
| jumpNegativeReceiver |
<var: #jumpNegativeReceiver type: #'AbstractInstruction *'>
"remove excess tag bits from the receiver oop"
+ cogit MoveR: ReceiverResultReg R: TempReg.
self numSmallIntegerTagBits > 1
ifTrue:
+ [cogit OrCq: 1 << self numSmallIntegerTagBits - 1 R: TempReg.
+ cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: TempReg].
- [cogit OrCq: 1 << self numSmallIntegerTagBits - 1 R: ReceiverResultReg.
- cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: ReceiverResultReg].
"and use the abstract cogit facility for case of single tag-bit"
+ jumpNegativeReceiver := cogit genHighBitIn: TempReg ofSmallIntegerOopWithSingleTagBit: TempReg.
- jumpNegativeReceiver := cogit genHighBitIn: ReceiverResultReg ofSmallIntegerOopWithSingleTagBit: ReceiverResultReg.
"Jump is NULL if above operation is not implemented, else return the result"
jumpNegativeReceiver = 0
ifFalse:
+ [cogit MoveR: TempReg R: ReceiverResultReg.
+ cogit genConvertIntegerToSmallIntegerInReg: ReceiverResultReg.
- [cogit genConvertIntegerToSmallIntegerInReg: ReceiverResultReg.
cogit genPrimReturn.
jumpNegativeReceiver jmpTarget: cogit Label].
^CompletePrimitive!
Item was removed:
- ----- Method: CogObjectRepresentation>>genPrimitiveHighBitgenPrimitiveHighBit (in category 'primitive generators') -----
- genPrimitiveHighBitgenPrimitiveHighBit
- | jumpNegativeReceiver |
- <var: #jumpNegativeReceiver type: #'AbstractInstruction *'>
- "remove excess tag bits from the receiver oop"
- self numSmallIntegerTagBits > 1
- ifTrue:
- [cogit OrCw: 1 << self numSmallIntegerTagBits - 1 R: ReceiverResultReg.
- cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: ReceiverResultReg].
- "and use the abstract cogit facility for case of single tag-bit"
- jumpNegativeReceiver := cogit genHighBitIn: ReceiverResultReg ofSmallIntegerOopWithSingleTagBit: ReceiverResultReg.
- "The jump instruction is NULL when backend does not really has a jitted implementation: fallback to normal primitive"
- jumpNegativeReceiver = 0 ifTrue: [^CompletePrimitive].
- cogit genPrimReturn.
- jumpNegativeReceiver jmpTarget: cogit Label.
- ^UnimplementedPrimitive!
Item was removed:
- ----- Method: CogObjectRepresentationFor64BitSpur>>genPrimitiveHighBit (in category 'primitive generators') -----
- genPrimitiveHighBit
- "Implementation notes: same as super, but CLZ/BSR only work on 64bits for registers R0-R7 on Intel X64.
- Normally, this should be backEnd dependent, but for now we have a single 64bits target..."
- | jumpNegativeReceiver reg |
- <var: #jumpNegativeReceiver type: #'AbstractInstruction *'>
- "remove excess tag bits from the receiver oop"
-
- ReceiverResultReg > 7
- ifTrue: [cogit MoveR: ReceiverResultReg R: (reg := TempReg)]
- ifFalse: [reg := ReceiverResultReg].
- self numSmallIntegerTagBits > 1
- ifTrue:
- [cogit OrCw: 1 << self numSmallIntegerTagBits - 1 R: reg.
- cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: reg].
- "and use the abstract cogit facility for case of single tag-bit"
- jumpNegativeReceiver := cogit genHighBitIn: reg ofSmallIntegerOopWithSingleTagBit: reg.
- "Jump is NULL if above operation is not implemented, else return the result"
- jumpNegativeReceiver = 0
- ifFalse:
- [ReceiverResultReg > 7
- ifTrue: [cogit MoveR: reg R: ReceiverResultReg].
- cogit genConvertIntegerToSmallIntegerInReg: ReceiverResultReg.
- cogit genPrimReturn.
- jumpNegativeReceiver jmpTarget: cogit Label].
- ^CompletePrimitive!
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2547.mcz
==================== Summary ====================
Name: VMMaker.oscog-nice.2547
Author: nice
Time: 31 August 2019, 2:02:51.22464 am
UUID: 66e4c466-c54c-4035-a7fa-6078386cbc66
Ancestors: VMMaker.oscog-nice.2546
Fix genPrimitiveHighBit
We must not modify ReceiverResultReg when we CompletePrimitive (in case of negative receiver).
Hence, like in WIN64, we must better use TempReg.
=============== Diff against VMMaker.oscog-nice.2546 ===============
Item was changed:
----- Method: CogObjectRepresentation>>genPrimitiveHighBit (in category 'primitive generators') -----
genPrimitiveHighBit
+ "Implementation notes: there are two reasons to use TempReg
+ -1) if primitive fails, ReceiverResultReg must remain unchanged (we CompletePrimitive)
+ -2) CLZ/BSR only work on 64bits for registers R0-R7 on Intel X64. But Win64 uses R9
+ Normally, this should be backEnd dependent, but for now we have a single 64bits target..."
+
| jumpNegativeReceiver |
<var: #jumpNegativeReceiver type: #'AbstractInstruction *'>
"remove excess tag bits from the receiver oop"
+ cogit MoveR: ReceiverResultReg R: TempReg.
self numSmallIntegerTagBits > 1
ifTrue:
+ [cogit OrCq: 1 << self numSmallIntegerTagBits - 1 R: TempReg.
+ cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: TempReg].
- [cogit OrCq: 1 << self numSmallIntegerTagBits - 1 R: ReceiverResultReg.
- cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: ReceiverResultReg].
"and use the abstract cogit facility for case of single tag-bit"
+ jumpNegativeReceiver := cogit genHighBitIn: TempReg ofSmallIntegerOopWithSingleTagBit: TempReg.
- jumpNegativeReceiver := cogit genHighBitIn: ReceiverResultReg ofSmallIntegerOopWithSingleTagBit: ReceiverResultReg.
"Jump is NULL if above operation is not implemented, else return the result"
jumpNegativeReceiver = 0
ifFalse:
+ [cogit MoveR: TempReg R: ReceiverResultReg.
+ cogit genConvertIntegerToSmallIntegerInReg: ReceiverResultReg.
- [cogit genConvertIntegerToSmallIntegerInReg: ReceiverResultReg.
cogit genPrimReturn.
jumpNegativeReceiver jmpTarget: cogit Label].
^CompletePrimitive!
Item was removed:
- ----- Method: CogObjectRepresentation>>genPrimitiveHighBitgenPrimitiveHighBit (in category 'primitive generators') -----
- genPrimitiveHighBitgenPrimitiveHighBit
- | jumpNegativeReceiver |
- <var: #jumpNegativeReceiver type: #'AbstractInstruction *'>
- "remove excess tag bits from the receiver oop"
- self numSmallIntegerTagBits > 1
- ifTrue:
- [cogit OrCw: 1 << self numSmallIntegerTagBits - 1 R: ReceiverResultReg.
- cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: ReceiverResultReg].
- "and use the abstract cogit facility for case of single tag-bit"
- jumpNegativeReceiver := cogit genHighBitIn: ReceiverResultReg ofSmallIntegerOopWithSingleTagBit: ReceiverResultReg.
- "The jump instruction is NULL when backend does not really has a jitted implementation: fallback to normal primitive"
- jumpNegativeReceiver = 0 ifTrue: [^CompletePrimitive].
- cogit genPrimReturn.
- jumpNegativeReceiver jmpTarget: cogit Label.
- ^UnimplementedPrimitive!
Item was removed:
- ----- Method: CogObjectRepresentationFor64BitSpur>>genPrimitiveHighBit (in category 'primitive generators') -----
- genPrimitiveHighBit
- "Implementation notes: same as super, but CLZ/BSR only work on 64bits for registers R0-R7 on Intel X64.
- Normally, this should be backEnd dependent, but for now we have a single 64bits target..."
- | jumpNegativeReceiver reg |
- <var: #jumpNegativeReceiver type: #'AbstractInstruction *'>
- "remove excess tag bits from the receiver oop"
-
- ReceiverResultReg > 7
- ifTrue: [cogit MoveR: ReceiverResultReg R: (reg := TempReg)]
- ifFalse: [reg := ReceiverResultReg].
- self numSmallIntegerTagBits > 1
- ifTrue:
- [cogit OrCw: 1 << self numSmallIntegerTagBits - 1 R: reg.
- cogit ArithmeticShiftRightCq: self numSmallIntegerTagBits - 1 R: reg].
- "and use the abstract cogit facility for case of single tag-bit"
- jumpNegativeReceiver := cogit genHighBitIn: reg ofSmallIntegerOopWithSingleTagBit: reg.
- "Jump is NULL if above operation is not implemented, else return the result"
- jumpNegativeReceiver = 0
- ifFalse:
- [ReceiverResultReg > 7
- ifTrue: [cogit MoveR: reg R: ReceiverResultReg].
- cogit genConvertIntegerToSmallIntegerInReg: ReceiverResultReg.
- cogit genPrimReturn.
- jumpNegativeReceiver jmpTarget: cogit Label].
- ^CompletePrimitive!
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2546.mcz
==================== Summary ====================
Name: VMMaker.oscog-nice.2546
Author: nice
Time: 29 August 2019, 1:17:48.054344 am
UUID: a6a8d0a3-4f7c-4927-85c1-e99f2c7b2591
Ancestors: VMMaker.oscog-nice.2545
Grrr, fixup
What this invert: dance really serve for?
Due to this, I reread the method twice or thrice, and still make a mistake from time to time...
=============== Diff against VMMaker.oscog-nice.2545 ===============
Item was changed:
----- Method: CogObjectRepresentation>>genPrimitiveLessOrEqual (in category 'primitive generators') -----
genPrimitiveLessOrEqual
^self getPrimitiveDoMixedArithmetic
ifTrue: [self
genSmallIntegerComparison: JumpLessOrEqual
orDoubleComparison: #JumpFPGreaterOrEqual:
+ invert: true]
- invert: false]
ifFalse: [self genSmallIntegerComparison: JumpLessOrEqual]!