Menu

#47 mips build does not cast ints to longs correctly

open
nobody
None
5
2010-05-25
2010-05-25
Nick
No

The following code does not work on my mips build

int l2 = 10;
long l4 = l2;

System.out.println("Int value is 0x"+Integer.toHexString(l2));
System.out.println("Long value is 0x"+Long.toHexString(l4));

OUTPUT

Int value is 0xa
Long value is 0xa00000000

Version Info

java version "1.5.0"
JamVM version 1.5.4

Would it be something obvious in my build of jamvm

If you need any more info please just ask.

Discussion

  • Nick

    Nick - 2010-05-26

    I have created a patch to fix this but am at a loss to why it is needed, it seems the compiler is not casting correctly in the POP / PUSH STACK

    here is the patch

    --- /home/downloads/jamvm-1.5.4/src/interp/engine/interp.c 2009-12-31 18:40:46.000000000 +0000
    +++ interp.c 2010-05-26 12:37:41.000000000 +0000
    @@ -1094,6 +1094,7 @@ uintptr_t *executeJava() {
    PUSH_LONG(res, 1); \
    }

    +
    DEF_OPC_FLOAT(OPC_F2L,
    OPC_fp2long(float);
    )
    @@ -1102,8 +1103,18 @@ uintptr_t *executeJava() {
    OPC_fp2long(double);
    )

    +#define OPC_int2long(SRC_TYPE) \
    +{ \
    + int64_t res; \
    + SRC_TYPE value = STACK_POP(SRC_TYPE); \
    + \
    + res = (int64_t) value; \
    + \
    + PUSH_LONG(res, 1); \
    +}
    +
    DEF_OPC_210(OPC_I2L,
    - PUSH_LONG(STACK_POP(int), 1);
    + OPC_int2long(int);
    )

    DEF_OPC_210(OPC_I2B,

     
  • Nick

    Nick - 2010-05-28

    Have just compiles on a mipsel and got the same problem gcc for mips and mipsel is version is 4.3.3

     
  • Nils

    Nils - 2010-10-08

    I can confirm that this problem exists and this patch should work. Did a similar patch myself.

    In PUSH_LONG(STACK_POP(int), 1); STACK_POP(int) first has to be casted to u4, afterwards to u8. It's not surprising that this fails on Big Endian platforms, in my opinion it's more of a coincidence that it works on Little Endian ones.

     

Log in to post a comment.