public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/26474]  New: compiling 'long long' math with optimization gives bad results
@ 2006-02-26 17:19 eran dot nissenhaus at mobileye dot com
  2006-02-26 18:39 ` [Bug other/26474] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eran dot nissenhaus at mobileye dot com @ 2006-02-26 17:19 UTC (permalink / raw)
  To: gcc-bugs

Hello,

Tested with two compilers:
1. powerpc-7400-linux-gnu-g++ version 3.3.4
2. powerpc-linux-g++ version 3.3.2

the following code gives correct results when compiled with no optimization:
"Add siy: -3252329895"

Compiling with any of the optimization levels gives bad results:
"Add siy: 39697343065"

it looks like a sign-extension problem.
turning on the #define works-around the problem in a mysterious way.

Regrds,
Eran.

#include <cstdio>

void add(long* yy, long* xx, int n);

int main() {
  const int N = 10;
  long yy[N] = {-5,-1,-2,-3,-4,-5,-6,-7,-8,-9};
  long xx[N] = {-1,-2,-3,-4,-5,-6,-7,-8,-9,10};

  add(yy, xx, N);

  return 0;
}


void add(long* yy, long* xx, int n) {
  long long siy=0;

  for(int i = 0; i < n; i++) {
    long y = yy[i];
#if 0 // workaround
    long ipy = -(1<<30)/y;
    long long iy = ipy;
    iy = -iy;
#else
    long iy = (1<<30)/y;
#endif
    siy  += iy;
  }
  printf("Add siy: %lld \n",siy);
}


-- 
           Summary: compiling 'long long' math with optimization gives bad
                    results
           Product: gcc
           Version: 3.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eran dot nissenhaus at mobileye dot com
 GCC build triplet: 3.2.1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26474


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug other/26474] compiling 'long long' math with optimization gives bad results
  2006-02-26 17:19 [Bug other/26474] New: compiling 'long long' math with optimization gives bad results eran dot nissenhaus at mobileye dot com
@ 2006-02-26 18:39 ` pinskia at gcc dot gnu dot org
  2006-02-27  8:35 ` eran dot nissenhaus at mobileye dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-26 18:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-26 17:22 -------
Can you give the full output of:
powerpc-7400-linux-gnu-g++ -v
and
powerpc-linux-g++ -v
?
Thanks,
Andrew


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26474


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug other/26474] compiling 'long long' math with optimization gives bad results
  2006-02-26 17:19 [Bug other/26474] New: compiling 'long long' math with optimization gives bad results eran dot nissenhaus at mobileye dot com
  2006-02-26 18:39 ` [Bug other/26474] " pinskia at gcc dot gnu dot org
@ 2006-02-27  8:35 ` eran dot nissenhaus at mobileye dot com
  2006-02-27 11:48 ` [Bug target/26474] " rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: eran dot nissenhaus at mobileye dot com @ 2006-02-27  8:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from eran dot nissenhaus at mobileye dot com  2006-02-27 06:46 -------
(In reply to comment #1)
> Can you give the full output of:
> powerpc-7400-linux-gnu-g++ -v
> and
> powerpc-linux-g++ -v
> ?
> Thanks,
> Andrew
> 
Here goes:
% /opt/Arabella/bin/powerpc-linux-g++ -v
Reading specs from /opt/Arabella/lib/gcc-lib/powerpc-linux/3.3.2/specs
Configured with: ../../../SRC/gcc-3.3.2/configure --target=powerpc-linux
--with-gnu-as --with-gnu-ld --prefix=/opt/Arabella
--mandir=/opt/Arabella/share/man --infodir=/opt/Arabella/share/info
--with-gxx-include-dir=/opt/Arabella/include/c++/3.3.2 --disable-nls
--enable-shared --enable-languages=c,c++ --enable-threads=posix
--enable-multilib --enable-__cxa_atexit --enable-clocale=gnu --enable-c-mbchar
--enable-version-specific-runtime-libs --with-dwarf2 --with-headers
Thread model: posix
gcc version 3.3.2

 %
/opt/crosstool/gcc-3.3.4-glibc-2.2.5/powerpc-7400-linux-gnu/bin/powerpc-7400-linux-gnu-g++
-v
Reading specs from
/opt/crosstool/gcc-3.3.4-glibc-2.2.5/powerpc-7400-linux-gnu/lib/gcc-lib/powerpc-7400-linux-gnu/3.3.4/specs
Configured with:
/homes/avrozen/downloads/crosstool-0.37/build/powerpc-7400-linux-gnu/gcc-3.3.4-glibc-2.2.5/gcc-3.3.4/configure
--target=powerpc-7400-linux-gnu --host=i686-host_pc-linux-gnu
--prefix=/opt/crosstool/gcc-3.3.4-glibc-2.2.5/powerpc-7400-linux-gnu
--with-cpu=7400 --enable-altivec --enable-cxx-flags=-mcpu=7400
--disable-libunwind-exceptions --disable-c-mbchar
--with-headers=/opt/crosstool/gcc-3.3.4-glibc-2.2.5/powerpc-7400-linux-gnu/powerpc-7400-linux-gnu/include
--with-local-prefix=/opt/crosstool/gcc-3.3.4-glibc-2.2.5/powerpc-7400-linux-gnu/powerpc-7400-linux-gnu
--disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit
--enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.3.4



Thanks,
Eran


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26474


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/26474] compiling 'long long' math with optimization gives bad results
  2006-02-26 17:19 [Bug other/26474] New: compiling 'long long' math with optimization gives bad results eran dot nissenhaus at mobileye dot com
  2006-02-26 18:39 ` [Bug other/26474] " pinskia at gcc dot gnu dot org
  2006-02-27  8:35 ` eran dot nissenhaus at mobileye dot com
@ 2006-02-27 11:48 ` rguenth at gcc dot gnu dot org
  2006-02-27 12:03 ` rguenth at gcc dot gnu dot org
  2006-02-27 13:48 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-27 11:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2006-02-27 11:42 -------
Works for me on i686 for all gcc > 3.3.3 and 2.95.  Works for me on ppc64 with
4.1.0.  So this is at least ppc specific.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|other                       |target
  GCC build triplet|3.2.1                       |
 GCC target triplet|                            |ppc-linux
           Keywords|                            |wrong-code
      Known to work|                            |4.1.0
            Version|3.2.1                       |3.3.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26474


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/26474] compiling 'long long' math with optimization gives bad results
  2006-02-26 17:19 [Bug other/26474] New: compiling 'long long' math with optimization gives bad results eran dot nissenhaus at mobileye dot com
                   ` (2 preceding siblings ...)
  2006-02-27 11:48 ` [Bug target/26474] " rguenth at gcc dot gnu dot org
@ 2006-02-27 12:03 ` rguenth at gcc dot gnu dot org
  2006-02-27 13:48 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-27 12:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2006-02-27 11:47 -------
Confirmed for 3.3.3-hammer on ppc32 (ppc64 works).  4.0.2 is fine.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|                            |3.3.3
      Known to work|4.1.0                       |4.0.2 4.1.0
   Last reconfirmed|0000-00-00 00:00:00         |2006-02-27 11:47:58
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26474


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/26474] compiling 'long long' math with optimization gives bad results
  2006-02-26 17:19 [Bug other/26474] New: compiling 'long long' math with optimization gives bad results eran dot nissenhaus at mobileye dot com
                   ` (3 preceding siblings ...)
  2006-02-27 12:03 ` rguenth at gcc dot gnu dot org
@ 2006-02-27 13:48 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-27 13:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2006-02-27 13:28 -------
Fixed at least on the 3.4 branch.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
      Known to work|4.0.2 4.1.0                 |3.4.6 4.0.2 4.1.0
         Resolution|                            |FIXED
   Target Milestone|---                         |3.4.6


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26474


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-27 13:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-26 17:19 [Bug other/26474] New: compiling 'long long' math with optimization gives bad results eran dot nissenhaus at mobileye dot com
2006-02-26 18:39 ` [Bug other/26474] " pinskia at gcc dot gnu dot org
2006-02-27  8:35 ` eran dot nissenhaus at mobileye dot com
2006-02-27 11:48 ` [Bug target/26474] " rguenth at gcc dot gnu dot org
2006-02-27 12:03 ` rguenth at gcc dot gnu dot org
2006-02-27 13:48 ` rguenth at gcc dot gnu dot org

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).