[net.sources] Patch for compress 4.0 on machines with an instruction cache

ken@turtlevax.UUCP (05/09/86)

Although I appreciate the work that James Woods (ames!jaw) did on
compress to enhance its efficiency, there was one modification that
made it less efficient for machines like the 68010 and 68020 that have
an instruction cache.  This comtext diff patch undoes an unrolling of
the loop that clears the hash table.

I would be interested in any other machines that have at least a
minimal cache that can keep an instruction sequence like:
 	while (hsize-- != 0)
 	    *htab_p++ = m1;
The code has an #ifdef CACHE that is #defined for the above machines,
and can easily accomodate other such machines.  It also includes mods
from Rick Adams (seismo!rick) from the 2.10.3 release of news for the
Gould as well as a fix from a forgotten USENET contributor for zcat.

Please send me any additions to the list, so that I might be able to
incorporate them and send them to the appropriate person at Berkeley
(please give me an address!) before the official 4.3 BSD release comes
out.

As a bynote, I had somewhat of a problem generating a context diff
on 4.3bsd: the format seems to be different than the one that patch
expects.  In particular, I got the following message from patch:

	Unexpected --- at line 2: --- 44,56 ----

If anyone has a patch for patch, I'd like to get it.

-----------------------------------------------------------------

*** compress.c.old	Fri May  9 01:33:40 1986
--- compress.c	Fri May  9 01:33:37 1986
***************
*** 44,49
  # undef USERMEM
  #endif /* pcxt */
  
  #ifdef USERMEM
  # if USERMEM >= (433484+SACREDMEM)
  #  define PBITS	16

--- 44,56 -----
  # undef USERMEM
  #endif /* pcxt */
  
+ #ifdef mc68010		/* has a tiny, but effective, instruction cache */
+ # define CACHE
+ #endif /* mc68010 */
+ #ifdef mc68020		/* has an instruction cache */
+ # define CACHE
+ #endif /* mc68020 */
+ 
  #ifdef USERMEM
  # if USERMEM >= (433484+SACREDMEM)
  #  define PBITS	16
***************
*** 138,144
   *		James A. Woods		(decvax!ihnp4!ames!jaw)
   *		Joe Orost		(decvax!vax135!petsd!joe)
   *
!  * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $
   * $Log:	compress.c,v $
   * Revision 4.0  85/07/30  12:50:00  joe
   * Removed ferror() calls in output routine on every output except first.

--- 145,151 -----
   *		James A. Woods		(decvax!ihnp4!ames!jaw)
   *		Joe Orost		(decvax!vax135!petsd!joe)
   *
!  * $Header: compress.c,v 4.1 86/05/09 00:46:00 ken Release $
   * $Log:	compress.c,v $
   * Revision 4.1  86/05/09  00:46:00  ken
   * Added CACHE #ifdef's for mc68010 and mc68020
***************
*** 140,145
   *
   * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $
   * $Log:	compress.c,v $
   * Revision 4.0  85/07/30  12:50:00  joe
   * Removed ferror() calls in output routine on every output except first.
   * Prepared for release to the world.

--- 147,155 -----
   *
   * $Header: compress.c,v 4.1 86/05/09 00:46:00 ken Release $
   * $Log:	compress.c,v $
+  * Revision 4.1  86/05/09  00:46:00  ken
+  * Added CACHE #ifdef's for mc68010 and mc68020
+  *
   * Revision 4.0  85/07/30  12:50:00  joe
   * Removed ferror() calls in output routine on every output except first.
   * Prepared for release to the world.
***************
*** 250,256
   * Add variable bit length output.
   *
   */
! static char rcs_ident[] = "$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $";
  
  #include <stdio.h>
  #include <ctype.h>

--- 260,266 -----
   * Add variable bit length output.
   *
   */
! static char rcs_ident[] = "$Header: compress.c,v 4.1 86/05/09 00:46:00 ken Release $";
  
  #include <stdio.h>
  #include <ctype.h>
***************
*** 295,300
  #define codetabof(i)	(codetab[(i) >> 14][(i) & 0x3fff])
  
  #else	/* Normal machine */
  count_int htab [HSIZE];
  unsigned short codetab [HSIZE];
  #define htabof(i)	htab[i]

--- 305,313 -----
  #define codetabof(i)	(codetab[(i) >> 14][(i) & 0x3fff])
  
  #else	/* Normal machine */
+ # ifdef sel
+ /* support gould base register problems */
+ /*NOBASE*/
  count_int htab [HSIZE];
  unsigned short codetab [HSIZE];
  /*NOBASE*/
***************
*** 297,302
  #else	/* Normal machine */
  count_int htab [HSIZE];
  unsigned short codetab [HSIZE];
  #define htabof(i)	htab[i]
  #define codetabof(i)	codetab[i]
  #endif	/* XENIX_16 */

--- 310,320 -----
  /*NOBASE*/
  count_int htab [HSIZE];
  unsigned short codetab [HSIZE];
+ /*NOBASE*/
+ # else /* !gould */
+ count_int htab [HSIZE];
+ unsigned short codetab [HSIZE];
+ # endif /* !gould */
  #define htabof(i)	htab[i]
  #define codetabof(i)	codetab[i]
  #endif	/* !XENIX_16 */
***************
*** 299,305
  unsigned short codetab [HSIZE];
  #define htabof(i)	htab[i]
  #define codetabof(i)	codetab[i]
! #endif	/* XENIX_16 */
  code_int hsize = HSIZE;			/* for dynamic table sizing */
  count_int fsize;
  

--- 317,323 -----
  # endif /* !gould */
  #define htabof(i)	htab[i]
  #define codetabof(i)	codetab[i]
! #endif	/* !XENIX_16 */
  code_int hsize = HSIZE;			/* for dynamic table sizing */
  count_int fsize;
  
***************
*** 392,399
   * 	or stdout   (if stdin used as input)
   *
   * Assumptions:
!      *	When filenames are given, replaces with the compressed version
!      *	(.Z suffix) only if the file decreases in size.
   * Algorithm:
   * 	Modified Lempel-Ziv method (LZW).  Basically finds common
   * substrings and replaces them with a variable size code.  This is

--- 410,417 -----
   * 	or stdout   (if stdin used as input)
   *
   * Assumptions:
!  *	When filenames are given, replaces with the compressed version
!  *	(.Z suffix) only if the file decreases in size.
   * Algorithm:
   * 	Modified Lempel-Ziv method (LZW).  Basically finds common
   * substrings and replaces them with a variable size code.  This is
***************
*** 1391,1397
  cl_hash(hsize)		/* reset code table */
  	register count_int hsize;
  {
! #ifndef XENIX_16	/* Normal machine */
  	register count_int *htab_p = htab+hsize;
  #else
  	register j;

--- 1409,1418 -----
  cl_hash(hsize)		/* reset code table */
  	register count_int hsize;
  {
! #ifdef CACHE		/* Machine with a cache for block initialization */
! 	register count_int *htab_p = htab;
! #else /* no CACHE */
! # ifndef XENIX_16	/* Normal machine */
  	register count_int *htab_p = htab+hsize;
  # else /* XENIX_16 */
  	register j;
***************
*** 1393,1399
  {
  #ifndef XENIX_16	/* Normal machine */
  	register count_int *htab_p = htab+hsize;
! #else
  	register j;
  	register long k = hsize;
  	register count_int *htab_p;

--- 1414,1420 -----
  #else /* no CACHE */
  # ifndef XENIX_16	/* Normal machine */
  	register count_int *htab_p = htab+hsize;
! # else /* XENIX_16 */
  	register j;
  	register long k = hsize;
  	register count_int *htab_p;
***************
*** 1397,1404
  	register j;
  	register long k = hsize;
  	register count_int *htab_p;
! #endif
! 	register long i;
  	register long m1 = -1;
  
  #ifdef XENIX_16

--- 1418,1425 -----
  	register j;
  	register long k = hsize;
  	register count_int *htab_p;
! # endif /* XENIX_16 */
! #endif /* CACHE */
  	register long m1 = -1;
  
  #ifdef CACHE
***************
*** 1401,1407
  	register long i;
  	register long m1 = -1;
  
! #ifdef XENIX_16
      for(j=0; j<=8 && k>=0; j++,k-=8192) {
  	i = 8192;
  	if(k < 8192) {

--- 1422,1435 -----
  #endif /* CACHE */
  	register long m1 = -1;
  
! #ifdef CACHE
! 	while (hsize-- != 0)
! 	    *htab_p++ = m1;
! #else /* no CACHE */
! 
!     register long i;
! 
! # ifdef XENIX_16
      for(j=0; j<=8 && k>=0; j++,k-=8192) {
  	i = 8192;
  	if(k < 8192) {
***************
*** 1410,1416
  	htab_p = &(htab[j][i]);
  	i -= 16;
  	if(i > 0) {
! #else
  	i = hsize - 16;
  #endif
   	do {				/* might use Sys V memset(3) here */

--- 1438,1444 -----
  	htab_p = &(htab[j][i]);
  	i -= 16;
  	if(i > 0) {
! # else
  	i = hsize - 16;
  # endif
   	do {				/* might use Sys V memset(3) here */
***************
*** 1412,1418
  	if(i > 0) {
  #else
  	i = hsize - 16;
! #endif
   	do {				/* might use Sys V memset(3) here */
  		*(htab_p-16) = m1;
  		*(htab_p-15) = m1;

--- 1440,1446 -----
  	if(i > 0) {
  # else
  	i = hsize - 16;
! # endif
   	do {				/* might use Sys V memset(3) here */
  		*(htab_p-16) = m1;
  		*(htab_p-15) = m1;
***************
*** 1432,1438
  		*(htab_p-1) = m1;
  		htab_p -= 16;
  	} while ((i -= 16) >= 0);
! #ifdef XENIX_16
  	}
      }
  #endif

--- 1460,1466 -----
  		*(htab_p-1) = m1;
  		htab_p -= 16;
  	} while ((i -= 16) >= 0);
! # ifdef XENIX_16
  	}
      }
  # endif
***************
*** 1435,1441
  #ifdef XENIX_16
  	}
      }
! #endif
      	for ( i += 16; i > 0; i-- )
  		*--htab_p = m1;
  }

--- 1463,1469 -----
  # ifdef XENIX_16
  	}
      }
! # endif
      	for ( i += 16; i > 0; i-- )
  		*--htab_p = m1;
  #endif /* no CACHE */
***************
*** 1438,1443
  #endif
      	for ( i += 16; i > 0; i-- )
  		*--htab_p = m1;
  }
  
  prratio(stream, num, den)

--- 1466,1472 -----
  # endif
      	for ( i += 16; i > 0; i-- )
  		*--htab_p = m1;
+ #endif /* no CACHE */
  }
  
  prratio(stream, num, den)
-- 
Ken Turkowski @ CIMLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,seismo}!turtlevax!ken
ARPA: turtlevax!ken@DECWRL.DEC.COM