public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Glen Nakamura <glen@imodulo.com>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c/6893: gcc generates invalid code for x86 subarches.
Date: Sat, 01 Jun 2002 08:56:00 -0000	[thread overview]
Message-ID: <20020601155601.15236.qmail@sources.redhat.com> (raw)

The following reply was made to PR c/6893; it has been noted by GNATS.

From: Glen Nakamura <glen@imodulo.com>
To: warp@debian.org
Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org
Subject: Re: c/6893: gcc generates invalid code for x86 subarches.
Date: Sat, 1 Jun 2002 05:48:44 -1000

 --vkogqOf2sHV7VnPd
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6893
 
 Aloha,
 
 Looks like the testcase you provided has an aliasing problem:
 icolor = (int *) tmp;
 
 Strict aliasing does not allow casting from (float *) to (int *)...
 You will need to fix your code or compile w/ -fno-strict-aliasing.
 See the GCC documentation on -fstrict-aliasing for more information.
 
 Please check if your problem persists with the attached testcase.
 
 - Glen Nakamura
 
 
 --vkogqOf2sHV7VnPd
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="6893.c"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #define min(a,b) ((a) < (b) ? (a) : (b))
 
 typedef union {
     float f;
     int   i;
 } tmp_t;
 
 float source[4];
 tmp_t tmp[4];
 unsigned char out[4];
 
 extern void inline FtoUB (float *in, char *out, int num)
 {
     int         i;
     tmp_t       *icolor;
     tmp_t       *fcolor_to;
 
     fcolor_to = tmp;
 
     // shift float to have 8bit fraction at base of number
     for (i = 0; i < num; i += 4) {
         fcolor_to[i    ].f = in[i    ] + 32768.0f;
         fcolor_to[i + 1].f = in[i + 1] + 32768.0f;
         fcolor_to[i + 2].f = in[i + 2] + 32768.0f;
         fcolor_to[i + 3].f = in[i + 3] + 32768.0f;
     }
 
     icolor = tmp;
 
     // then read as integer and kill float bits...
     for (i = 0; i < num; i += 4) {
         out[i    ] = (char) min(icolor[i    ].i & 0x7FFFFF, 255);
         out[i + 1] = (char) min(icolor[i + 1].i & 0x7FFFFF, 255);
         out[i + 2] = (char) min(icolor[i + 2].i & 0x7FFFFF, 255);
         out[i + 3] = (char) min(icolor[i + 3].i & 0x7FFFFF, 255);
     }
 }
 
 int
 main (int argc, char *argv[])
 {
     source[0] = atof(argv[1]);
     source[1] = atof(argv[2]);
     source[2] = atof(argv[3]);
     source[3] = atof(argv[4]);
 
     FtoUB(source, out, 4);
 
     printf("in: %f %f %f %f\n", source[0], source[1], source[2], source[3]);
     printf("out: %d %d %d %d\n", out[0], out[1], out[2], out[3]);
     exit (0);
 }
 
 --vkogqOf2sHV7VnPd--


             reply	other threads:[~2002-06-01 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-01  8:56 Glen Nakamura [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-06-01 23:55 rth
2002-06-01 11:36 Zephaniah E. Hull
2002-06-01  6:16 warp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020601155601.15236.qmail@sources.redhat.com \
    --to=glen@imodulo.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).