dotgnu-libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libjit-developers] gen-apply problem


From: Aleksey Demakov
Subject: [Libjit-developers] gen-apply problem
Date: Wed, 30 Nov 2005 20:36:57 +0600

Hi all,

Occasionly gen-apply generates for me incorrect jit_apply_return union in
the jit-apply-rules.h file:

typedef union
{
        jit_nint int_value;
        jit_nuint uint_value;
        jit_long long_value;
        jit_ulong ulong_value;
        struct { jit_ubyte pad[64]; jit_apply_float inner_value; } f_value;
        jit_ubyte small_struct_value[8];

} jit_apply_return;

The size of the pad fiels is 64 bytes while it has to be 8 bytes. I believe
that this problems occurs because the detect_float_return() function
uses mem_cmp(.., ... sizeof (jit_nfloat)) to find the value in the stack.

The result of sizeof (jit_nfloat) is 12 while the size of extended floating
point numbers on x86 processors is 80 bits or 10 bytes. Apparently
the extra 2 bytes sometimes are initialized with garbage thus
mem_cpy is unable to match the numbers correctly.

I wrote a simple test program that shows that these two bytes
may indeed contain garbage:

#include <stdio.h>
#include <stdlib.h>

void
print_bytes(void* ptr, int n)
{
        unsigned char *cp = ptr;
        while(n-- > 0)
        {
                printf("%02x ", *cp++);
        }
        printf("\n");
}

int
main()
{
        long double n1, n2;

        printf("%d\n", sizeof(long double));

        memset(&n1, 0xab, sizeof n1);
        memset(&n2, 0xcd, sizeof n2);
        print_bytes(&n1, sizeof n1);
        print_bytes(&n2, sizeof n2);

        n1 = 123.0;
        n2 = 123.0;
        printf("%Lf\n", n1);
        printf("%Lf\n", n2);
        print_bytes(&n1, sizeof n1);
        print_bytes(&n2, sizeof n2);

        return 0;
}

When compiled with -02 flag this program produces the following
output:

12
ab ab ab ab ab ab ab ab ab ab ab ab
cd cd cd cd cd cd cd cd cd cd cd cd
123.000000
123.000000
00 00 00 00 00 00 00 f6 05 40 ab ab
00 00 00 00 00 00 00 f6 05 40 cd cd

It could be easily seen that the last two bytes of the long double
variables are left intact after assignment.

I made a small modification to gen-apply.c that takes into account
this problem. After this the generated union seems to be always
of the correct size. The patch is attached.

Regards,
Aleksey

Attachment: gen-apply.c.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]