[Vm-dev] VM Maker: VMMaker.oscog-nice.1985.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Nov 7 23:44:41 UTC 2016


Nicolas Cellier uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.1985.mcz

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

Name: VMMaker.oscog-nice.1985
Author: nice
Time: 8 November 2016, 12:43:20.98015 am
UUID: 7c12723c-9f09-4d4e-832b-f01fd783899b
Ancestors: VMMaker.oscog-eem.1984

Fix generation of signed32BitIntegerFor: for 64 bits VM.

signed32BitIntegerFor: must work for any 32bit int, but current version will overflow if this int is large, for example -16r80000000.

Indeed, not only constants must be extended to sqInt, but any expression whose type is shorter.

Also, use unsigned usqInt, rather than signed sqInt, because it's well defined behavior (sign extension will occur during the conversion).

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

Item was changed:
  ----- Method: CCodeGenerator>>generateIntegerObjectOf:on:indent: (in category 'C translation') -----
  generateIntegerObjectOf: msgNode on: aStream indent: level
  	"Generate the C code for this message onto the given stream."
+ 	| expr mustCastToUnsigned type typeIsUnsigned |
- 	| expr castToSqint |
  	expr := msgNode args first.
  	aStream nextPutAll: '(('.
  	"Note that the default type of an integer constant in C is int.  Hence we /must/
+ 	 cast expression to long if in the 64-bit world, since e.g. in 64-bits
- 	 cast constants to long if in the 64-bit world, since e.g. in 64-bits
  		(int)(16r1FFFFF << 3) = (int)16rFFFFFFF8 = -8
  	 whereas
  		(long)(16r1FFFFF << 3) = (long) 16rFFFFFFF8 = 4294967288."
+ 	type := self typeFor: expr in: currentMethod.
+ 	typeIsUnsigned := type first = $u.
+ 	mustCastToUnsigned := typeIsUnsigned not
+ 		or: [(self sizeOfIntegralCType: type) < (self sizeOfIntegralCType: #usqInt)].
+ 	mustCastToUnsigned ifTrue:
+ 		[aStream nextPutAll: '(usqInt)'].
- 	castToSqint := expr isConstant and: [vmClass isNil or: [vmClass objectMemoryClass wordSize = 8]].
- 	castToSqint ifTrue:
- 		[aStream nextPutAll: '(sqInt)'].
  	self emitCExpression: expr on: aStream.
  	aStream
  		nextPutAll: ' << ';
  		print: vmClass objectMemoryClass numSmallIntegerTagBits;
  		nextPutAll: ') | 1)'!



More information about the Vm-dev mailing list