VC7 optimizer problem

I’m getting corrupted blits in VC7 with optimizations on in
BlitNtoNKeyCopyAlpha. It turns out that the "assume no aliasing"
optimization is getting turned on somehow. I have no idea how. (If it
was on by default, it’d cause global, catastrophic problems, so
something somewhere has to be turning it on.)

It can be disabled explicitly with:

#pragma optimize(“a”, off)

I’m not sure where to put it; it shouldn’t go in a public header (since
an app might actually want to use this optimization).

Unless anyone has a hint as to where this is getting turned on. (Or, if
SDL is actually written with this in mind–which I doubt–then a fix
for BlitNtoNKeyCopyAlpha.)–
Glenn Maynard

Ack. After another recompile, this stopped working, and “g” fixed it.
I believe I screwed up when testing it; I’ve had to compile and copy the
DLL to a working directory and test it, and I might not have copied it
when my binary search on these options went from “agp” to “a”.

It makes far more sense, though; it’s just a standard optimizer bug, not
turning on the strange “no aliasing” optimization. The attached patch
fixes it, but it turns off “global optimizations” for all of blit_N,
which may be overkill (it may only be needed for one or two blits, or
there may be a workaround not involving disabling optimizations), or
underkill (there may be blits in other files that also have this problem;
I certainly don’t use them all). I don’t feel like comparing optimized
assembly output right now, though.

Of course, this could still just be a blitter bug, but I can’t find one.

I’ve also changed the build to generate SDLd.{dll,lib} and SDLmaind.{dll,lib},
which is much more convenient for debugging, and made it output all four to
lib/, instead of VisualC/SDL(main)/{Debug,Release}/. Any reason not to
do that (or at least the first half) upstream?On Tue, Oct 22, 2002 at 11:54:14PM -0400, Glenn Maynard wrote:

I’m getting corrupted blits in VC7 with optimizations on in
BlitNtoNKeyCopyAlpha. It turns out that the "assume no aliasing"
optimization is getting turned on somehow. I have no idea how. (If it
was on by default, it’d cause global, catastrophic problems, so
something somewhere has to be turning it on.)

It can be disabled explicitly with:

#pragma optimize(“a”, off)


Glenn Maynard
-------------- next part --------------
— SDL_blit_N.c 2002-08-01 19:06:39.000000000 -0400
+++ /home/glenn/hm/stepmania/src/SDL-1.2.5/src/video/SDL_blit_N.c 2002-10-23 21:43:42.000000000 -0400
@@ -31,6 +31,10 @@
#include “SDL_video.h”
#include “SDL_blit.h”
#include “SDL_byteorder.h”
+
+#if defined(WIN32) && _MSC_VER >= 1300
+#pragma optimize(“g”, off)
+#endif

/* Function to check the CPU flags */
#define MMX_CPU 0x800000

It makes far more sense, though; it’s just a standard optimizer bug, not
turning on the strange “no aliasing” optimization. The attached patch
fixes it, but it turns off “global optimizations” for all of blit_N,
which may be overkill

Ugh. Any way you can isolate the code that tickles the optimizer bug?

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Attached. Results with optimization on:

00ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 00ffffff
00ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 00ffffff
00ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 00ffffff

(the zeroed character is alpha)

Off:

ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff

DUFFS_LOOP4 and optimization on:

00ffffff 00ffffff 00ffffff 00ffffff 00ffffff 00ffffff 00ffffff 00ffffff
00ffffff 00ffffff 00ffffff 00ffffff 00ffffff 00ffffff 00ffffff 00ffffff

No USE_DUFFS_LOOP and optimization on:

ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff

This only seems to happen with VC7, not VC6. Hopefully it can be worked
around; I have a VC6 installation for testing purposes, but I don’t want
to be stuck with it indefinitely for SDL compilation.

For the time being, I’ll just turn off USE_DUFFS_LOOP; it’s much less of a
performance hit than turning off those optimizations. (It might be
worth checking if USE_DUFFS_LOOP is a performance gain in VC; the
optimizer might be able to handle that on its own.)On Fri, Oct 25, 2002 at 01:27:38AM -0700, Sam Lantinga wrote:

Ugh. Any way you can isolate the code that tickles the optimizer bug?


Glenn Maynard
-------------- next part --------------
A non-text attachment was scrubbed…
Name: test.cpp
Type: text/x-c++src
Size: 964 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021104/37fe5472/attachment.cpp