[Zlib-devel] infnew-5b available for testing

Glenn Randers-Pehrson glennrp at comcast.net
Fri Jan 3 07:37:01 EST 2003


At 08:31 PM 1/2/03 -0800, Mark Adler wrote:
>zlib speed demons,
>I think this code is ready for a wider beta audience.

There are still a huge number of compiler warnings on the SGI,
that the controlling expression is constant.

The MIPS compiler doesn't care much for the "do { } while(0|1)"
blocks, which look to me like some kind of optimization trick
aimed at a particular compiler.

Also there are warnings when an assignment narrows the variable
being assigned, such as in CRC2, which exhibits both problems:

do {
   hbuf[0]=(word);
   hbuf[1]=(word) >> 8;
   } while (0)

The warnings can be silenced with

   {
   hbuf[0]=(Byte)(word);
   hbuf[1]=(Byte)((word) >> 8);
   }

Loops of the form
   do
   {
     some stuff;
   } while (1);

can be rewritten

   for (;;)
   {
     some stuff;
   }

which doesn't generate any compiler complaints but should have
the same effect.

On the SGI MIPS compiler, making these changes does not seem
to have any impact on speed.

If you want to make this configurable for easy experimentation,
you could define macros:

#ifdef USE_DO_WHILE
#  define DO_ONCE_START do
#  define DO_ONCE_END while (0);
#  define DO_FOREVER_START do
#  define DO_FOREVER_END while (1);
#else
#  define DO_ONCE_START
#  define DO_ONCE_END
#  define DO_FOREVER_START for (;;)
#  define DO_FOREVER_END
#endif

and change
do {
  some stuff;
  } while 0;

to 
  DO_ONCE_START {
  some stuff;
  } DO_ONCE_END

and
do {
  some stuff;
  } while (1);

to

DO_FOREVER_START {
  some stuff;
  } DO_FOREVER_END

Glenn




More information about the Zlib-devel mailing list