[Vm-dev] VM Maker: VMMaker.oscog-eem.3315.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Mar 28 18:19:24 UTC 2023


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

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

Name: VMMaker.oscog-eem.3315
Author: eem
Time: 28 March 2023, 11:19:04.757315 am
UUID: 9f1219c6-2ad5-4cb2-9e1d-572ad6ec934b
Ancestors: VMMaker.oscog-eem.3314

Fix a regression in the ARM64 (non-Apple) and RISCV64 FFI plugins introduced by VMMaker.oscog-eem.3309/VMMaker.oscog-eem.3310. I forgot to push up alignCurrentArgOf:to:

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

Item was removed:
- ----- Method: ThreadedARM64AppleFFIPlugin>>alignCurrentArgOf:to: (in category 'marshalling') -----
- alignCurrentArgOf: calloutState to: boundary
- 	<var: #calloutState type: #'CalloutState *'>
- 	<inline: #always>
- 	| misAlignedBytes |
- 	misAlignedBytes := calloutState currentArg asInteger bitAnd: boundary - 1.
- 	misAlignedBytes ~= 0 ifTrue:
- 		[calloutState currentArg: calloutState currentArg + (boundary - misAlignedBytes)]!

Item was added:
+ ----- Method: ThreadedARM64FFIPlugin>>alignCurrentArgOf:to: (in category 'marshalling') -----
+ alignCurrentArgOf: calloutState to: boundary
+ 	<var: #calloutState type: #'CalloutState *'>
+ 	<inline: #always>
+ 	| misAlignedBytes |
+ 	misAlignedBytes := calloutState currentArg asInteger bitAnd: boundary - 1.
+ 	misAlignedBytes ~= 0 ifTrue:
+ 		[calloutState currentArg: calloutState currentArg + (boundary - misAlignedBytes)]!

Item was changed:
  ----- Method: ThreadedARM64FFIPlugin>>ffiPushStructure:ofSize:typeSpec:ofLength:in: (in category 'marshalling') -----
  ffiPushStructure: pointer ofSize: structSize typeSpec: argSpec ofLength: argSpecSize in: calloutState
  	<var: #pointer type: #'void *'>
  	<var: #argSpec type: #'unsigned int *'>
  	<var: #calloutState type: #'CalloutState *'>
  	<inline: #always>
  	| availableRegisterSpace roundedSize |
  	"Stage B
  		B.1 If the argument type is a Composite Type whose size cannot be statically determined by both the caller
  			and the callee, the argument is copied to memory and the argument is replaced by a pointer to the copy.
  			(There are no such types in C/C++ but they exist in other languages or in language extensions).
  		B.2 If the argument type is an HFA or an HVA, then the argument is used unmodified.
  		B.3 If the argument type is a Composite Type that is larger than 16 bytes, then the argument is copied to
  			memory allocated by the caller and the argument is replaced by a pointer to the copy.
  		B.4 If the argument type is a Composite Type then the size of the argument is rounded up to the nearest
  			multiple of 8 bytes."
  
  	"See IHI0055B_aapcs64.pdf sections 4.3.5 & 5.4.2 Stage C"
  	(self structIsHomogenousFloatArrayOfSize: structSize typeSpec: argSpec ofLength: argSpecSize)
  		ifTrue:
  			[availableRegisterSpace := (NumFloatRegArgs - calloutState floatRegisterIndex) * self wordSize.
  			 structSize <= availableRegisterSpace ifTrue: "Stage C, step C.2, all in floating-point registers (!!!!)"
  				[self 
  					memcpy: (self cCoerceSimple: (self addressOf: (calloutState floatRegisters at: calloutState floatRegisterIndex)) to: #'void *') 
  					_: pointer 
  					_: structSize.
  					"Round structSize up and divide by 8 ( NB: _not_ 4 !!)"
  				 calloutState floatRegisterIndex: calloutState floatRegisterIndex + (structSize + 7 bitShift: -3).
  				 ^0].
  			 "Stage C, step C.3"
  			 availableRegisterSpace := 0.
  			 calloutState floatRegisterIndex: 8]
  
  		ifFalse:
  			[availableRegisterSpace := (NumIntRegArgs - calloutState integerRegisterIndex) * self wordSize].
  
  	"If it's small (16 bytes or less) and will fit in registers it is passed in registers, otherwise it is copied to memory.
  	 If it is a Homogenous Short Vector (HVA) (up to 32 bytes long) and will fit it is passed in registers."
  	(structSize <= availableRegisterSpace "all in integer registers; we have no way of getting to SIMD registers"
  	 and: [structSize <= 16
  		or: [self structIsHomogenousIntegerArrayOfSize: structSize typeSpec: argSpec ofLength: argSpecSize]]) ifTrue: 
  		[structSize <= availableRegisterSpace ifTrue:"all in integer registers"
  			[self 
  				memcpy: (self cCoerceSimple: (self addressOf: (calloutState integerRegisters at: calloutState integerRegisterIndex)) to: #'void *') 
  				_: pointer 
  				_: structSize.
  				"Round structSize up and divide by 8 ( NB: _not_ 4 !!)"
  			 calloutState integerRegisterIndex: calloutState integerRegisterIndex + (structSize + 7 bitShift: -3).
  			 ^0]].
  
  	"If small and won't fit in registers, copy to the stack.
  	 N.B. my (eem) reading of IHI0055B_aapcs64.pdf  is that unlike the 32-bit PCS, aggregates are never split between memory and registers."
  	structSize <= 16 ifTrue: 
  		[roundedSize := structSize + 7 bitClear: 7.
  		 calloutState currentArg + roundedSize > calloutState limit ifTrue:
  			 [^FFIErrorCallFrameTooBig].
+ 		 self alignCurrentArgOf: calloutState to: self wordSize.
- 		 self alignCurrentArgOf: calloutState to: 8.
  		 self memcpy: calloutState currentArg _: pointer _: structSize.
  		 calloutState currentArg: calloutState currentArg + roundedSize].
  
  	"If it is not small it is passed as a pointer. N.B. Spur guarantees only 8-byte alignment. IHI0055B_aapcs64.pdf is vague on the memory's alignment.
  	 Arguably the memory should be pinned in case of a callback. Don't bother for now. eem 3/11/2023"
  	^self ffiPushPointer: pointer in: calloutState!



More information about the Vm-dev mailing list