Victory? (was Re: Mac Intel)

Joel Reymont <>
Tue Aug 15 13:28:58 CEST 2006


On a second thought, this has nothing to do with HiPE code  
generation. I think it's either a bug in gcc (unlikely?) or an  
alignment/operand size problem.

On Aug 15, 2006, at 11:30 AM, Joel Reymont wrote:

> It's crashing on this apparently.
>
> 0x000a4702 <hipe_bifs_get_hrvtime_0+74>:        movapd %xmm0,-56(%ebp)

The code below has a number of things that need to be investigated  
such as FLOAT_SIZE_OBJECT, make_float and PUT_DOUBLE. Full  
disassembler dump of hipe_bifs_get_hrvtime_0 is at the end.

The bug is clearly in this block of code and my hunch is that it  
somehow corresponds to PUT_DOUBLE. What do you think?

0x000a46e0 <hipe_bifs_get_hrvtime_0+40>:        call   0x45669  
<elapsed_time_both>
0x000a46e5 <hipe_bifs_get_hrvtime_0+45>:        movd   -12(%ebp),%xmm1
0x000a46ea <hipe_bifs_get_hrvtime_0+50>:        pxor   %xmm0,%xmm0
0x000a46ee <hipe_bifs_get_hrvtime_0+54>:        punpckldq %xmm1,%xmm0
0x000a46f2 <hipe_bifs_get_hrvtime_0+58>:        punpckldq 903040,%xmm0
0x000a46fa <hipe_bifs_get_hrvtime_0+66>:        subpd  903056,%xmm0
0x000a4702 <hipe_bifs_get_hrvtime_0+74>:        movapd %xmm0,-56(%ebp)
0x000a4707 <hipe_bifs_get_hrvtime_0+79>:        movapd %xmm0,%xmm2
0x000a470b <hipe_bifs_get_hrvtime_0+83>:        movhpd %xmm0,-56(%ebp)
0x000a4710 <hipe_bifs_get_hrvtime_0+88>:        addpd  -56(%ebp),%xmm2
0x000a4715 <hipe_bifs_get_hrvtime_0+93>:        movapd %xmm2,-56(%ebp)
0x000a471a <hipe_bifs_get_hrvtime_0+98>:        fldl   -56(%ebp)
0x000a471d <hipe_bifs_get_hrvtime_0+101>:       fstpl  -32(%ebp)

hipe_bif1.c:

BIF_RETTYPE hipe_bifs_get_hrvtime_0(BIF_ALIST_0)
{
     Eterm *hp;
     Eterm res;
     FloatDef f;

     if( !hrvtime_is_started() ) {
         start_hrvtime();
         if( !hrvtime_is_started() )
             BIF_ERROR(BIF_P, BADARG);
     }
     f.fd = get_hrvtime();
     hp = HAlloc(BIF_P, FLOAT_SIZE_OBJECT);
     res = make_float(hp);
     PUT_DOUBLE(f, hp);
     BIF_RET(res);
}

erl_term.h:

/* Float definition for byte and word access */
typedef double ieee754_8;

typedef union float_def
{
     ieee754_8 fd;
     byte   fb[sizeof(ieee754_8)];
     Uint16 fs[sizeof(ieee754_8) / sizeof(Uint16)];
     Uint32 fw[sizeof(ieee754_8) / sizeof(Uint32)];
#ifdef ARCH_64
     Uint   fdw;
#endif
} FloatDef;

#ifdef ARCH_64
#define GET_DOUBLE(x, f) (f).fdw = *(float_val(x)+1)

#define PUT_DOUBLE(f, x)  *(x) = HEADER_FLONUM, \
                           *((x)+1) = (f).fdw
#define GET_DOUBLE_DATA(p, f) (f).fdw = *((Uint *) (p))
#define PUT_DOUBLE_DATA(f,p) *((Uint *) (p)) = (f).fdw
#else
#define GET_DOUBLE(x, f) (f).fw[0] = *(float_val(x)+1), \
                          (f).fw[1] = *(float_val(x)+2)

#define PUT_DOUBLE(f, x)  *(x) = HEADER_FLONUM, \
                           *((x)+1) = (f).fw[0], \
			  *((x)+2) = (f).fw[1]
#define GET_DOUBLE_DATA(p, f) (f).fw[0] = *((Uint *) (p)),\
                               (f).fw[1] = *(((Uint *) (p))+1)
#define PUT_DOUBLE_DATA(f,p) *((Uint *) (p)) = (f).fw[0],\
                              *(((Uint *) (p))+1) = (f).fw[1]
#endif
#define DOUBLE_DATA_WORDS (sizeof(ieee754_8)/sizeof(Eterm))
#define FLOAT_SIZE_OBJECT (DOUBLE_DATA_WORDS+1)

Full disassembler dump of hipe_bifs_get_hrvtime_0:

Dump of assembler code for function hipe_bifs_get_hrvtime_0:
0x000a46b8 <hipe_bifs_get_hrvtime_0+0>: push   %ebp
0x000a46b9 <hipe_bifs_get_hrvtime_0+1>: mov    %esp,%ebp
0x000a46bb <hipe_bifs_get_hrvtime_0+3>: push   %ebx
0x000a46bc <hipe_bifs_get_hrvtime_0+4>: sub    $0x44,%esp
0x000a46bf <hipe_bifs_get_hrvtime_0+7>: mov    8(%ebp),%ebx
0x000a46c2 <hipe_bifs_get_hrvtime_0+10>:        movl   $0x0,12(%esp)
0x000a46ca <hipe_bifs_get_hrvtime_0+18>:        movl   $0x0,8(%esp)
0x000a46d2 <hipe_bifs_get_hrvtime_0+26>:        movl   $0x0,4(%esp)
0x000a46da <hipe_bifs_get_hrvtime_0+34>:        lea    -12(%ebp),%eax
0x000a46dd <hipe_bifs_get_hrvtime_0+37>:        mov    %eax,(%esp)
0x000a46e0 <hipe_bifs_get_hrvtime_0+40>:        call   0x45669  
<elapsed_time_both>
0x000a46e5 <hipe_bifs_get_hrvtime_0+45>:        movd   -12(%ebp),%xmm1
0x000a46ea <hipe_bifs_get_hrvtime_0+50>:        pxor   %xmm0,%xmm0
0x000a46ee <hipe_bifs_get_hrvtime_0+54>:        punpckldq %xmm1,%xmm0
0x000a46f2 <hipe_bifs_get_hrvtime_0+58>:        punpckldq 903040,%xmm0
0x000a46fa <hipe_bifs_get_hrvtime_0+66>:        subpd  903056,%xmm0
0x000a4702 <hipe_bifs_get_hrvtime_0+74>:        movapd %xmm0,-56(%ebp)
0x000a4707 <hipe_bifs_get_hrvtime_0+79>:        movapd %xmm0,%xmm2
0x000a470b <hipe_bifs_get_hrvtime_0+83>:        movhpd %xmm0,-56(%ebp)
0x000a4710 <hipe_bifs_get_hrvtime_0+88>:        addpd  -56(%ebp),%xmm2
0x000a4715 <hipe_bifs_get_hrvtime_0+93>:        movapd %xmm2,-56(%ebp)
0x000a471a <hipe_bifs_get_hrvtime_0+98>:        fldl   -56(%ebp)
0x000a471d <hipe_bifs_get_hrvtime_0+101>:       fstpl  -32(%ebp)
0x000a4720 <hipe_bifs_get_hrvtime_0+104>:       mov    (%ebx),%edx
0x000a4722 <hipe_bifs_get_hrvtime_0+106>:       mov    4(%ebx),%eax
0x000a4725 <hipe_bifs_get_hrvtime_0+109>:       sub    %edx,%eax
0x000a4727 <hipe_bifs_get_hrvtime_0+111>:       sar    $0x2,%eax
0x000a472a <hipe_bifs_get_hrvtime_0+114>:       cmp    $0x3,%eax
0x000a472d <hipe_bifs_get_hrvtime_0+117>:       jbe    0xa4751  
<hipe_bifs_get_hrvtime_0+153>
0x000a472f <hipe_bifs_get_hrvtime_0+119>:       lea    12(%edx),%eax
0x000a4732 <hipe_bifs_get_hrvtime_0+122>:       mov    %eax,(%ebx)
0x000a4734 <hipe_bifs_get_hrvtime_0+124>:       mov    %edx,%eax
0x000a4736 <hipe_bifs_get_hrvtime_0+126>:       movl   $0x98,(%eax)
0x000a473c <hipe_bifs_get_hrvtime_0+132>:       mov    -32(%ebp),%edx
0x000a473f <hipe_bifs_get_hrvtime_0+135>:       mov    %edx,4(%eax)
0x000a4742 <hipe_bifs_get_hrvtime_0+138>:       mov    -28(%ebp),%edx
0x000a4745 <hipe_bifs_get_hrvtime_0+141>:       mov    %edx,8(%eax)
0x000a4748 <hipe_bifs_get_hrvtime_0+144>:       add    $0x2,%eax
0x000a474b <hipe_bifs_get_hrvtime_0+147>:       add    $0x44,%esp
0x000a474e <hipe_bifs_get_hrvtime_0+150>:       pop    %ebx
0x000a474f <hipe_bifs_get_hrvtime_0+151>:       pop    %ebp
0x000a4750 <hipe_bifs_get_hrvtime_0+152>:       ret
0x000a4751 <hipe_bifs_get_hrvtime_0+153>:       movl   $0x3,4(%esp)
0x000a4759 <hipe_bifs_get_hrvtime_0+161>:       mov    %ebx,(%esp)
0x000a475c <hipe_bifs_get_hrvtime_0+164>:       call   0x2ce3a  
<erts_heap_alloc>0x000a4761 <hipe_bifs_get_hrvtime_0+169>:        
movl   $0x98,(%eax)
0x000a4767 <hipe_bifs_get_hrvtime_0+175>:       mov    -32(%ebp),%edx
0x000a476a <hipe_bifs_get_hrvtime_0+178>:       mov    %edx,4(%eax)
0x000a476d <hipe_bifs_get_hrvtime_0+181>:       mov    -28(%ebp),%edx
0x000a4770 <hipe_bifs_get_hrvtime_0+184>:       mov    %edx,8(%eax)
0x000a4773 <hipe_bifs_get_hrvtime_0+187>:       add    $0x2,%eax
0x000a4776 <hipe_bifs_get_hrvtime_0+190>:       add    $0x44,%esp
0x000a4779 <hipe_bifs_get_hrvtime_0+193>:       pop    %ebx
0x000a477a <hipe_bifs_get_hrvtime_0+194>:       pop    %ebp
0x000a477b <hipe_bifs_get_hrvtime_0+195>:       ret
End of assembler dump.

--
http://wagerlabs.com/








More information about the erlang-questions mailing list