This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: issues with doubles and -fno-schedule-insns2


On Friday 26 Nov 2004 2:27 pm, Nathan Sidwell wrote:
> Matthew J Fletcher wrote:
> > Hi
> >
> > i have a C code snipit that causes problems with gcc 3.3.4 and 3.4.1, i
> > have not tried the v4 snapshots, in all cases are am hosted and targeting
> > on i386.
> >
> >
> > am i doing something wrong ?
>
> yes. You are breaking the type based aliasing rules.  Your second example
> 'happens' to work, but don't rely on it doing so for later releases
> or other slightly different uses.

thats good to know,..

however i forgot to mention that i am targeting (march=i486) for my embedded 
sc520, dont know if its relivant to the following. i dont understand what 
'schedule-insns2' is doing, but it seems to be doing the wrong thing, again i 
could be very wrong.

int main()
{
        unsigned int Value[2] = { 0x7FF00000, 0x7FF00000 };
        double *ValueD = (double *)&Value[0];

        //(*ValueD) == nan(0x07ff00000)
        printf("Value = %g\n",(*ValueD));

        return 0;
}

 // gcc 3.3.4 -O3 -fno-schedule-insns2 -march=486
 // produces correct result
 08048370 <main>:
 8048370:       55                      push   %ebp
 8048371:       89 e5                   mov    %esp,%ebp
 8048373:       83 ec 08                sub    $0x8,%esp
 8048376:       83 e4 f0                and    $0xfffffff0,%esp
 8048379:       c7 45 f8 00 00 f0 7f    movl   $0x7ff00000,0xfffffff8(%ebp)
 8048380:       c7 45 fc 00 00 f0 7f    movl   $0x7ff00000,0xfffffffc(%ebp)
 8048387:       51                      push   %ecx
 8048388:       8b 45 fc                mov    0xfffffffc(%ebp),%eax
 804838b:       50                      push   %eax
 804838c:       8b 55 f8                mov    0xfffffff8(%ebp),%edx
 804838f:       52                      push   %edx
 8048390:       68 84 84 04 08          push   $0x8048484
 8048395:       e8 ee fe ff ff          call   8048288 <_init+0x38>
 
 // gcc 3.3.4 -O3 -march=486
 // produces wrong result
 08048370 <main>:
 8048370:       55                      push   %ebp
 8048371:       89 e5                   mov    %esp,%ebp
 8048373:       83 ec 08                sub    $0x8,%esp
 8048376:       83 e4 f0                and    $0xfffffff0,%esp
 8048379:       8b 45 fc                mov    0xfffffffc(%ebp),%eax
 804837c:       51                      push   %ecx
 804837d:       50                      push   %eax
 804837e:       8b 55 f8                mov    0xfffffff8(%ebp),%edx
 8048381:       52                      push   %edx
 8048382:       68 84 84 04 08          push   $0x8048484
 8048387:       c7 45 f8 00 00 f0 7f    movl   $0x7ff00000,0xfffffff8(%ebp)
 804838e:       c7 45 fc 00 00 f0 7f    movl   $0x7ff00000,0xfffffffc(%ebp)
 8048395:       e8 ee fe ff ff          call   8048288 <_init+0x38>

 note, movl's after push's which, i think just pushed crap onto the stack.


 so i tried a diffrent example.

int main()
{
        unsigned long long Value = 0x7FF000007FF00000;
        double *ValueD = (double *)&Value;

        //(*ValueD) == nan(0x07ff00000)
        printf("Value = %g\n",(*ValueD));

        return 0;
}

// gcc 3.3.4 -O3 -march=486
// produces correct result

 8048370:       55                      push   %ebp
 8048371:       89 e5                   mov    %esp,%ebp
 8048373:       83 ec 08                sub    $0x8,%esp
 8048376:       83 e4 f0                and    $0xfffffff0,%esp
 8048379:       50                      push   %eax
 804837a:       68 00 00 f0 7f          push   $0x7ff00000
 804837f:       68 00 00 f0 7f          push   $0x7ff00000
 8048384:       68 84 84 04 08          push   $0x8048484
 8048389:       e8 fa fe ff ff          call   8048288 <_init+0x38>

which works,..

any pointers to 'type based aliasing rules' ? docs for simple folk ?

regards
---
Matthew J Fletcher
Embedded Software
Serck Controls Ltd
---
**********************************************************************
Serck Controls Ltd, Rowley Drive, Coventry, CV3 4FH, UK
Tel: +44 (0) 24 7630 5050   Fax: +44 (0) 24 7630 2437
Web: www.serck-controls.com  Admin: post@serck-controls.co.uk
A subsidiary of Serck Controls Pty. Ltd. Reg. in England No. 4353634
**********************************************************************
This email and files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the above. Any views or opinions presented are those of the author
and do not necessarily represent those of Serck Controls Ltd.


This message has been checked by MessageLabs
******************************************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]