[Vm-dev] Primitive 40 (asFloat) fails for me

Christian Kellermann ckeen at pestilenz.org
Wed Feb 20 07:30:52 UTC 2019


* Eliot Miranda <eliot.miranda at gmail.com> [190219 18:18]:
>  

> First what is the result of
> 
>     | floats |
>     floats := Array new: 30.
>     1 to: floats size do: [:i| floats at: i put: -100 asFloat].
>     floats
> 
> ?

 #(100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0)

All 100's...

> If the result has the first several floats as 100.0 and the last few as
> -100.0 then...

omitted.

> static void
> primitiveAsFloat(void)
> {   DECL_MAYBE_SQ_GLOBAL_STRUCT
>     sqInt rcvr;
>     char *sp;
> 
>     rcvr = longAt(GIV(stackPointer));
>     assert((((rcvr) & 7) == 1));
>     /* begin pop:thenPushFloat: */
>     longAtput((sp = GIV(stackPointer) + ((1 - 1) * BytesPerWord)),
> floatObjectOf(((double) (((sqInt)rcvr >> 3)) )));
>     GIV(stackPointer) = sp;
> }
> 
> (I would expect not)

You are right:

diff --git a/spur64src/vm/gcc3x-cointerp.c b/spur64src/vm/gcc3x-cointerp.c
index c80be332c..0256a6585 100644
--- a/spur64src/vm/gcc3x-cointerp.c
+++ b/spur64src/vm/gcc3x-cointerp.c
@@ -25996,7 +25996,7 @@ primitiveAsFloat(void)
        rcvr = longAt(GIV(stackPointer));
        assert((((rcvr) & 7) == 1));
        /* begin pop:thenPushFloat: */
-       longAtput((sp = GIV(stackPointer) + ((1 - 1) * BytesPerWord)), floatObjectOf(((double) ((rcvr >> 3)) )));
+       longAtput((sp = GIV(stackPointer) + ((1 - 1) * BytesPerWord)), floatObjectOf(((double) (((sqInt)rcvr >> 3)) )));
        GIV(stackPointer) = sp;
 }

-100 asFloat → 100

This has been built with
$ gcc --version
gcc (GCC) 8.2.1 20181127

When I disable optimisations with -O0, I get the correct result.
So I guess, let's see why the compiler does what it does...

Kind regards,

Christian

-- 
May you be peaceful, may you live in safety, may you be free from
suffering, and may you live with ease.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20190220/41185da0/attachment.sig>


More information about the Vm-dev mailing list