[Vm-dev] VM Maker: VMMaker.oscog-nice.1986.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Nov 8 21:07:33 UTC 2016
Nicolas Cellier uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.1986.mcz
==================== Summary ====================
Name: VMMaker.oscog-nice.1986
Author: nice
Time: 8 November 2016, 9:59:38.206628 pm
UUID: e06214fe-0e06-4c33-9132-03ffe9351cbb
Ancestors: VMMaker.oscog-nice.1985
Like already the case for the #positive32BitIntegerFor: and #signed32BitIntegerFor: , #positive32BitValueOf: and #signed32BitValueOf: can be simplified with separate 32/64 bits branches.
Indeed, we know that any 32bits signed/unsigned int will fit into a SmallInteger when hasSixtyFourBitImmediates,.
No need to perform any superfluous testing...
The previous implementation produces a lot of dead code in 64bits VM and prevents inlining unecessarily.
=============== Diff against VMMaker.oscog-nice.1985 ===============
Item was added:
+ ----- Method: InterpreterPrimitives>>maybeInlinePositive32BitValueOf: (in category 'primitive support') -----
+ maybeInlinePositive32BitValueOf: oop
+ "Convert the given object into an integer value.
+ The object may be either a positive SmallInteger or a four-byte LargePositiveInteger."
+ <notOption: #Spur64BitMemoryManager>
+ <returnTypeC: #'unsigned int'>
+ | value ok sz |
+ (objectMemory isIntegerObject: oop) ifTrue:
+ [value := objectMemory integerValueOf: oop.
+ (value < 0) ifTrue:
+ [self primitiveFail. value := 0].
+ ^value].
+
+ (objectMemory isNonIntegerImmediate: oop)
+ ifTrue:
+ [self primitiveFail.
+ ^0]
+ ifFalse:
+ [ok := objectMemory
+ isClassOfNonImm: oop
+ equalTo: (objectMemory splObj: ClassLargePositiveInteger)
+ compactClassIndex: ClassLargePositiveIntegerCompactIndex.
+ ok ifFalse:
+ [self primitiveFail.
+ ^0].
+ sz := objectMemory numBytesOfBytes: oop.
+ sz > 4 ifTrue:
+ [self primitiveFail.
+ ^0].
+ ^self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int']!
Item was added:
+ ----- Method: InterpreterPrimitives>>noInlineSigned32BitValueOf: (in category 'primitive support') -----
+ noInlineSigned32BitValueOf: oop
+ "Convert the given object into an integer value.
+ The object may be either a SmallInteger or a four-byte LargeInteger."
+ | value negative ok magnitude |
+ <notOption: #Spur64BitMemoryManager>
+ <inline: false>
+ <returnTypeC: #int>
+ <var: #value type: #int>
+ <var: #magnitude type: #'unsigned int'>
+ self deny: objectMemory hasSixtyFourBitImmediates.
+ (objectMemory isIntegerObject: oop) ifTrue:
+ [^objectMemory integerValueOf: oop].
+
+ (objectMemory isNonIntegerImmediate: oop) ifTrue:
+ [self primitiveFail.
+ ^0].
+
+ ok := objectMemory
+ isClassOfNonImm: oop
+ equalTo: (objectMemory splObj: ClassLargePositiveInteger)
+ compactClassIndex: ClassLargePositiveIntegerCompactIndex.
+ ok
+ ifTrue: [negative := false]
+ ifFalse:
+ [negative := true.
+ ok := objectMemory isClassOfNonImm: oop
+ equalTo: (objectMemory splObj: ClassLargeNegativeInteger)
+ compactClassIndex: ClassLargeNegativeIntegerCompactIndex.
+ ok ifFalse:
+ [self primitiveFail.
+ ^0]].
+ (objectMemory numBytesOfBytes: oop) > 4 ifTrue:
+ [^self primitiveFail].
+
+ magnitude := self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int'.
+
+ (negative
+ ifTrue: [magnitude > 16r80000000]
+ ifFalse: [magnitude >= 16r80000000])
+ ifTrue:
+ [self primitiveFail.
+ ^0].
+ negative
+ ifTrue: [value := 0 - magnitude]
+ ifFalse: [value := magnitude].
+ ^value!
Item was changed:
----- Method: InterpreterPrimitives>>positive32BitValueOf: (in category 'primitive support') -----
positive32BitValueOf: oop
"Convert the given object into an integer value.
The object may be either a positive SmallInteger or a four-byte LargePositiveInteger."
+ <returnTypeC: #'unsigned int'>
+ objectMemory hasSixtyFourBitImmediates
- <returnTypeC: #usqInt>
- | value ok sz |
- (objectMemory isIntegerObject: oop) ifTrue:
- [value := objectMemory integerValueOf: oop.
- (value < 0
- or: [objectMemory wordSize > 4
- and: [self cCode: [(self cCoerceSimple: value to: #'unsigned int') ~= value]
- inSmalltalk: [value >> 32 ~= 0]]]) ifTrue:
- [self primitiveFail. value := 0].
- ^value].
-
- (objectMemory hasSixtyFourBitImmediates
- or: [objectMemory isNonIntegerImmediate: oop])
ifTrue:
+ [(objectMemory isIntegerObject: oop) ifTrue:
+ [| value64 |
+ value64 := objectMemory integerValueOf: oop.
+ (value64 < 0
+ or: [self cCode: [(self cCoerceSimple: value64 to: #'unsigned int') ~= value64]
+ inSmalltalk: [value64 >> 32 ~= 0]]) ifTrue:
+ [self primitiveFail. value64 := 0].
+ ^value64].
+ self primitiveFail.
+ ^0]
- [self primitiveFail.
- ^0]
ifFalse:
+ [^self maybeInlinePositive32BitValueOf: oop]!
- [ok := objectMemory
- isClassOfNonImm: oop
- equalTo: (objectMemory splObj: ClassLargePositiveInteger)
- compactClassIndex: ClassLargePositiveIntegerCompactIndex.
- ok ifFalse:
- [self primitiveFail.
- ^0].
- sz := objectMemory numBytesOfBytes: oop.
- sz > 4 ifTrue:
- [self primitiveFail.
- ^0].
- ^self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int']!
Item was changed:
----- Method: InterpreterPrimitives>>signed32BitValueOf: (in category 'primitive support') -----
signed32BitValueOf: oop
"Convert the given object into an integer value.
+ The object may be either a SmallInteger or a four-byte LargeInteger."
- The object may be either a positive SmallInteger or a four-byte LargeInteger."
- | value negative ok magnitude |
- <inline: false>
<returnTypeC: #int>
+
+ objectMemory hasSixtyFourBitImmediates
+ ifTrue:
+ [(objectMemory isIntegerObject: oop) ifTrue:
- <var: #value type: #int>
- <var: #magnitude type: #'unsigned int'>
- <var: #value64 type: #long>
- (objectMemory isIntegerObject: oop) ifTrue:
- [objectMemory wordSize = 4
- ifTrue:
- [^objectMemory integerValueOf: oop]
- ifFalse: "Must fail for SmallIntegers with digitLength > 4"
[| value64 |
value64 := objectMemory integerValueOf: oop.
(self cCode: [(self cCoerceSimple: value64 to: #int) ~= value64]
inSmalltalk: [value64 >> 31 ~= 0 and: [value64 >> 31 ~= -1]]) ifTrue:
[self primitiveFail. value64 := 0].
+ ^value64].
+ self primitiveFail.
+ ^0]
- ^value64]].
-
- (objectMemory isNonIntegerImmediate: oop) ifTrue:
- [self primitiveFail.
- ^0].
-
- ok := objectMemory
- isClassOfNonImm: oop
- equalTo: (objectMemory splObj: ClassLargePositiveInteger)
- compactClassIndex: ClassLargePositiveIntegerCompactIndex.
- ok
- ifTrue: [negative := false]
ifFalse:
+ [^self noInlineSigned32BitValueOf: oop]!
- [negative := true.
- ok := objectMemory isClassOfNonImm: oop
- equalTo: (objectMemory splObj: ClassLargeNegativeInteger)
- compactClassIndex: ClassLargeNegativeIntegerCompactIndex.
- ok ifFalse:
- [self primitiveFail.
- ^0]].
- (objectMemory numBytesOfBytes: oop) > 4 ifTrue:
- [^self primitiveFail].
-
- magnitude := self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int'.
-
- (negative
- ifTrue: [magnitude > 16r80000000]
- ifFalse: [magnitude >= 16r80000000])
- ifTrue:
- [self primitiveFail.
- ^0].
- negative
- ifTrue: [value := 0 - magnitude]
- ifFalse: [value := magnitude].
- ^value!
More information about the Vm-dev
mailing list