[Vm-dev] VM Maker: VMMaker.oscog-eem.3254.mcz
commits at source.squeak.org
commits at source.squeak.org
Fri Oct 7 01:01:58 UTC 2022
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3254.mcz
==================== Summary ====================
Name: VMMaker.oscog-eem.3254
Author: eem
Time: 6 October 2022, 6:01:40.95799 pm
UUID: 3b74b441-2801-46f6-ae88-40b662719aed
Ancestors: VMMaker.oscog-eem.3253
Further simplify ThreadedFFIPlugin>>ffiIntegerValueOf:; given that it now answers 64-bit results we can subsume all the isLargePositiveIntegerObject:, isLargeNegativeIntegerObject: & signedMachineIntegerValueOf: cases by a single signed64BitValueOf: case.
Simplify signed64BitValueOf:; it can answer the magnitude related result expression directly, an dthere is no need for the 64-bit magnitude test unless the byte length is 8 (i.e. > 4).
=============== Diff against VMMaker.oscog-eem.3253 ===============
Item was changed:
----- Method: InterpreterPrimitives>>signed64BitValueOf: (in category 'primitive support') -----
signed64BitValueOf: oop
"Convert the given object into an integer value.
The object may be either a positive SmallInteger or a eight-byte LargeInteger."
+ | sz negative ok magnitude |
- | sz value negative ok magnitude |
<inline: false>
<returnTypeC: #sqLong>
- <var: #value type: #sqLong>
<var: #magnitude type: #usqLong>
(objectMemory isIntegerObject: oop) ifTrue:
[^self cCoerce: (objectMemory integerValueOf: oop) to: #sqLong].
(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]].
sz := objectMemory numBytesOfBytes: oop.
- sz > (self sizeof: #sqLong) ifTrue:
- [self primitiveFail.
- ^0].
+ sz > 4
- "self cppIf: SPURVM
ifTrue:
+ [magnitude := objectMemory byteSwapped64IfBigEndian: (objectMemory fetchLong64: 0 ofObject: oop).
+ (sz > (self sizeof: #sqLong)
+ or: [negative
+ ifTrue: [magnitude > 16r8000000000000000]
+ ifFalse: [magnitude >= 16r8000000000000000]]) ifTrue:
+ [self primitiveFail.
+ ^0]]
- [""Memory is 8 byte aligned in Spur and oversized bytes are set to zero, so we can safely fetch 8 bytes""
- magnitude := objectMemory byteSwapped64IfBigEndian: (objectMemory fetchLong64: 0 ofObject: oop)]
ifFalse:
+ [magnitude := self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int'].
- ["sz > 4
- ifTrue: [magnitude := objectMemory byteSwapped64IfBigEndian: (objectMemory fetchLong64: 0 ofObject: oop)]
- ifFalse: [magnitude := self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int']"]".
+ ^negative
+ ifTrue: [0 - magnitude]
+ ifFalse: [magnitude]!
- (negative
- ifTrue: [magnitude > 16r8000000000000000]
- ifFalse: [magnitude >= 16r8000000000000000])
- ifTrue: [self primitiveFail.
- ^0].
- negative
- ifTrue: [value := 0 - magnitude]
- ifFalse: [value := magnitude].
- ^value!
Item was changed:
----- Method: InterpreterPrimitives>>signedMachineIntegerValueOf: (in category 'primitive support') -----
signedMachineIntegerValueOf: oop
"Answer a signed value of an integer up to the size of a machine word.
The object may be either a positive SmallInteger or a LargeInteger of size <= word size."
<returnTypeC: #'sqIntptr_t'>
| negative ok bs value limit magnitude |
<var: #value type: #sqInt>
<var: #magnitude type: #'usqIntptr_t'>
<var: #limit type: #'usqIntptr_t'>
(objectMemory isIntegerObject: oop) ifTrue:
[^objectMemory integerValueOf: oop].
(objectMemory isNonIntegerImmediate: oop) ifTrue:
[^self primitiveFail].
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]].
bs := objectMemory numBytesOf: oop.
bs > (self sizeof: #'usqIntptr_t') ifTrue:
[^self primitiveFail].
+ ((self sizeof: #'sqIntptr_t') = 8
+ and: [bs > 4])
- "self cppIf: SPURVM
ifTrue:
+ [magnitude := objectMemory byteSwapped64IfBigEndian: (objectMemory fetchLong64: 0 ofObject: oop)]
- [""Memory is 8 byte aligned in Spur and oversized bytes are set to zero, so we can safely fetch 8 bytes""
- magnitude := objectMemory byteSwapped64IfBigEndian: (objectMemory fetchLong64: 0 ofObject: oop)]
ifFalse:
+ [magnitude := self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int'].
- ["((self sizeof: #'sqIntptr_t') = 8
- and: [bs > 4])
- ifTrue:
- [magnitude := objectMemory byteSwapped64IfBigEndian: (objectMemory fetchLong64: 0 ofObject: oop)]
- ifFalse:
- [magnitude := self cCoerceSimple: (objectMemory byteSwapped32IfBigEndian: (objectMemory fetchLong32: 0 ofObject: oop)) to: #'unsigned int']"]".
limit := 1 asUnsignedIntegerPtr << ((self sizeof: #'sqIntptr_t') * 8 - 1).
(negative
ifTrue: [magnitude > limit]
ifFalse: [magnitude >= limit])
ifTrue: [self primitiveFail.
^0].
negative
ifTrue: [value := 0 - magnitude]
ifFalse: [value := magnitude].
^value!
Item was changed:
----- Method: ThreadedFFIPlugin>>ffiIntegerValueOf: (in category 'callout support') -----
ffiIntegerValueOf: oop
"Support for generic callout. Answer an integer value that is coerced as C would do."
<inline: true>
<returnTypeC: #sqLong> "Support up to int64_t or uint64_t, at least intptr_t; type *MUST* be signed for e.g. correct float conversion."
"Cheat with a tag test"
(oop anyMask: BytesPerWord - 1)
ifTrue:
[self cppIf: SPURVM
ifTrue:
[(interpreterProxy isIntegerObject: oop) ifTrue:
[^interpreterProxy integerValueOf: oop].
(interpreterProxy isCharacterObject: oop) ifTrue: "Immediate in Spur"
[^interpreterProxy characterValueOf: oop].
(BytesPerWord >= 8 and: [interpreterProxy isFloatObject: oop]) ifTrue: "Immediate in 64-bit Spur"
[^interpreterProxy floatValueOf: oop]]
ifFalse:
[^interpreterProxy integerValueOf: oop]] "only one kind of immediate in v3"
ifFalse:
[self cppIf: SPURVM
+ ifFalse: "No non-immediate characters in Spur"
- ifTrue: "No non-immediate characters in Spur"
- []
- ifFalse:
[(interpreterProxy isCharacterObject: oop) ifTrue:
[^interpreterProxy characterValueOf: oop]].
(interpreterProxy isFloatObject: oop) ifTrue:
[^interpreterProxy floatValueOf: oop].
"In Squeak nil, true & false are always contiguous at the start of old space..."
(self oop: oop isGreaterThanOrEqualTo: interpreterProxy nilObject andLessThanOrEqualTo: interpreterProxy trueObject) ifTrue:
["i.e. cheaper than but equivalent to:
oop = interpreterProxy nilObject ifTrue: [^0]. @@: should we really allow this????
oop = interpreterProxy falseObject ifTrue: [^0].
oop = interpreterProxy trueObject ifTrue: [^1]."
^oop = interpreterProxy trueObject ifTrue: [1] ifFalse: [0]].
(interpreterProxy isLargePositiveIntegerObject: oop) ifTrue:
+ [^interpreterProxy positive64BitValueOf: oop]].
+ ^interpreterProxy signed64BitValueOf: oop "<- will fail if not integer"!
- [^interpreterProxy positive64BitValueOf: oop].
- (interpreterProxy isLargeNegativeIntegerObject: oop) ifTrue:
- [^interpreterProxy signed64BitValueOf: oop]].
- ^interpreterProxy signedMachineIntegerValueOf: oop "<- will fail if not integer"!
More information about the Vm-dev
mailing list