Hi David,

On Sat, Jul 18, 2015 at 3:49 PM, David T. Lewis <lewis@mail.msen.com> wrote:

On Sat, Jul 18, 2015 at 08:55:27PM +0000, commits@source.squeak.org wrote:
>
> Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
> http://source.squeak.org/VMMaker/VMMaker.oscog-eem.1426.mcz
>
> ==================== Summary ====================
>
> Name: VMMaker.oscog-eem.1426
> Author: eem
> Time: 18 July 2015, 1:54:29.051 pm
> UUID: 94ab92ba-c5c4-4953-8566-a4cd9c38df1f
> Ancestors: VMMaker.oscog-eem.1425
>
> Fix at least one set of 64-bit issues caused by Slang.  In particular the integerObjectOf: code resulted in (objectMemory integerObjectOf: MillisecondClockMask) evaluating to the -1 object, instead of the 16r1FFFFFFF object, which was the cause of the initially nresponsive 64-bit image on the real VM (no problem in the simulator).
>

I can't test now to verify, but I wonder if this change is fixing the
right problem.

I'm pretty sure it is.  It only bites in a 64-bit implementation with > 31-bit integers.  In the "standard" 64-bit image SmallIntegers are still only 31-bits so the issue never occurs.  The issue is that the default type of an integer constant in C is int.  So if one has to shift any constant such that a non-zero bit will occupy bit 31 (0 relative), it must be cast to a long type to avoid sign extension.

Now of course I could generate all Integer constants with the L or UL suffix, e.g.

#define MillisecondClockMask 0x1FFFFFFFL

instead of

#define MillisecondClockMask 0x1FFFFFFF

but that's a much more pervasive change than only generating the cast in integerObjectOf when on 64-bits.  So I'm happy with the change that I've made.  Experience can of course prove me wrong...



The CCodeGenerator>>generateIntegerObjectOf:on:indent: in VMM trunk has
been in use long enough that it has no author initials. I have found it
to work correctly on all combinations of 32/64 bit image and VM. If it
does not work correctly, I would be inclined to suspect type declaration
issues elsewhere.

Original implementation:

CCodeGenerator>>generateIntegerObjectOf: msgNode on: aStream indent: level
        "Generate the C code for this message onto the given stream."

        aStream nextPutAll: '(('.
        self emitCExpression: msgNode args first on: aStream.
        aStream nextPutAll: ' << 1) | 1)'.

Dave


> =============== Diff against VMMaker.oscog-eem.1425 ===============
>
> 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 castToSqint |
> +     expr := msgNode args first.
> +     aStream nextPutAll: '(('.
> +     "Note that the default type of an integer constant in C is int.  Hence we /must/
> +      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."
> +     castToSqint := expr isConstant and: [vmClass isNil or: [vmClass objectMemoryClass wordSize = 8]].
> +     castToSqint ifTrue:
> +             [aStream nextPutAll: '(sqInt)'].
> +     self emitCExpression: expr on: aStream.
> -
>       aStream
> -             nextPutAll: '(('.
> -     self emitCExpression: msgNode args first on: aStream.
> -     aStream
>               nextPutAll: ' << ';
>               print: vmClass objectMemoryClass numSmallIntegerTagBits;
>               nextPutAll: ') | 1)'!



--
_,,,^..^,,,_
best, Eliot