Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: MSVC .NET 2003 optimization bug [O.T]

Author: Christophe Theron

Date: 21:16:16 04/09/04

Go up one level in this thread


On April 09, 2004 at 18:04:10, Russell Reagan wrote:

>I'm posting this here because I know that some of the programmers here use MSVC
>.NET 2003, and in hopes that Eugene will read this :)
>
>Today I had a problem with a program I was writing, and I came across what I
>believe is an optimization bug. I wrote this little program to reproduce the
>bug. If I compile with optimizations set to "Disabled", there is no problem. If
>I compile with optimzations set to anything else (Maximize Speed, Minimize Size,
>Full Optimizations), the program crashes due to a loop never terminating. The
>source code is at the end of this message. The line where the problem occurs is:
>
>for (row = 11; row < 12; row--)
>
>The problem is the comparison: row < 12



Just a quick note:

  for (row=11; row>=0; row--) {
    ...
  }

is probably faster (at least I expect it to be not slower than your version).

I also find it more readable, but maybe that's just me.

  row=11;
  do {
    ...
  } while (row--);

is maybe even slightly faster. But it's less readable.

But with modern compilers and cache magic, I'm not so sure. :)



    Christophe




>
>When optimizations are turned off, this is the assembly output for that
>comparison:
>
>cmp DWORD PTR _row$[ebp], 12
>
>If optimizations are turned on, this is the assembly output:
>
>cmp ebx, OFFSET FLAT:_a+576
>
>I'm no assembly expert, but that looks like it is comparing the address of two
>pointers to me, and has nothing to do with comparing two values.
>
>Here is the example C source code. I compiled it under GCC with and without
>optimizations and it ran fine. Another person with MSVC .NET 2003 ran this code
>and he reported the same problem of crashing with optimizations turned on.
>
>Is this really an optimization bug, or is it possible that I am doing something
>wrong with the compiler settings? If this is indeed an optimization bug, how can
>I find out if Microsoft is already aware of it? If they are not aware of it, how
>can I report it to them?
>
>#include <stdio.h>
>
>unsigned int a[144];
>
>void init ()
>{
>    unsigned int i;
>    for (i = 0; i < 144; i++)
>        a[i] = rand();
>}
>
>void dump ()
>{
>    unsigned int row, col;
>    for (row = 11; row < 12; row--)     // <--- PROBLEM: row < 12
>    {
>        for (col = 0; col < 12; col++)
>            printf("%u ", a[(row * 12) + col]);
>        putchar('\n');
>    }
>}
>
>int main ()
>{
>    init();
>    dump();
>    return 0;
>}



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.