On 03.02 Mattias Eriksson wrote:
> 
> For you who haven't read about the use of gcc 2.96 you can read the this
> by Linus Torvalds.
> http://boudicca.tux.org/hypermail/linux-kernel/2000week51/0868.html 
> 

Well, don't tell only the begin of the story, tell also the end.
If people see the date of the post, it is of Dec 14 2000. Many things
have happend since then.

Everybody agrees that 2.96 was veru broken at his inital release. But now
it is as good as 2.95.3, if not even better. I think it generates the
best code in all gcc (pseudo)releases. And the initial problems with the
optimizer are solved. I have been building kernels with 2.96 since many
relases of kernel ago. Even Linus (dont have the url at hand) recommended
start using 2.96 in kernel builds to catch KERNEL SOURCE DEFFECTS, because
it is stricter. And this all applies much more if you think about g++.
Even the last known bit of code in kernel that was surely know to be
miscompiled by gcc is now correct:

werewolf:~> rpm -q --changelog gcc | more
* Sat Feb 17 2001 Chmouel Boudjnah <[EMAIL PROTECTED]> 2.96-0.38mdk
..
* Thu Feb 15 2001 Chmouel Boudjnah <[EMAIL PROTECTED]> 2.96-0.36mdk
..
  - fix layout of __attribute((packed)) enums in bitfields (showing up
    in Linux DAC960 driver)


And about compilers being broken, none is sane. This ten lines example
was posted in kernel list recently. Try compiling it with -O2.
egcs miscompiles it, also 2.95.2, 2.95.3 and 2.96. It seems a bug in
x86 scpecific optimizations, because it does not happen in other archs
(I have tested IRIX and Solaris). The problem is solved using
-fno-strenght-reduce.

#include <stdio.h>

#define SMALL_N  2
#define NUM_ELEM 4

int main(void)
{
  int listElem[NUM_ELEM]={30,2,10,5};
  int listSmall[SMALL_N];
  int i, j;
  int posGreatest=-1, greatest=-1;

  for (i=0; i<SMALL_N; i++) { 
    listSmall[i] = listElem[i];
    if (listElem[i] > greatest) {
      posGreatest = i;
      greatest = listElem[i];
    }
  }
  
  for (i=SMALL_N; i<NUM_ELEM; i++) { 
    if (listElem[i] < greatest) {
      listSmall[posGreatest] = listElem[i];
      posGreatest = 0;
      greatest = listSmall[0];
      for (j=1; j<SMALL_N; j++) 
          {
        if (listSmall[j] > greatest) {
          posGreatest = j;
          greatest = listSmall[j];
        }
          }
      //printf("%d\n", posGreatest);
    }
  }
 
  printf("Correct output: 5 2\n");
  printf("GCC output: ");
  for (i=0; i<SMALL_N; i++) printf(" %.1d", listSmall[i]);
  printf("\n");
  return (1);
}


-- 
J.A. Magallon                                                      $> cd pub
mailto:[EMAIL PROTECTED]                                          $> more beer

Linux werewolf 2.4.2-ac8 #2 SMP Fri Mar 2 12:12:45 CET 2001 i686


Reply via email to