[gs-cvs] rev 8526 - trunk/gs/src

ray at ghostscript.com ray at ghostscript.com
Thu Feb 14 00:34:56 PST 2008


Author: ray
Date: 2008-02-14 00:34:56 -0800 (Thu, 14 Feb 2008)
New Revision: 8526

Modified:
   trunk/gs/src/gdevprna.c
   trunk/gs/src/gsht.c
   trunk/gs/src/gshtscr.c
   trunk/gs/src/gxht.c
   trunk/gs/src/gzht.h
Log:
Improve Halftone tile cache efficiency. Make default cache large enough
on default 32-bit (LARGE) configuration to allow for > 256 cache tiles
when using the 'ht_ccsto.ps' 167x167 Threshold array. Change cache
lookup logic to eliminate collisions when the number of cache slots
exceeds the number of levels (the normal case). Remove duplicated
ht cache default size #defines and normalize the names to end in
_size (to imply size in bytes) and be consistent with other similar
function/macro names.

DETAILS:

When we have more cache slots than the number of levels, we can use
the 'b_level' directly and don't lookup based on the 'number of bits'
(level). This ELIMINATES collisions and on customer 661's benchmarks
resulted in up to 40% performance improvement for some files with
no performance degradation on any when running a large threshold
array based halftone (as the customer does).

The previous -Z. behavior is retained, although small cache sizes
are of questionable value, and this is sort of confusing since a
small memory build will use the same cache size with and without
-Z.

EXPECTED DIFFERENCES:

None.


Modified: trunk/gs/src/gdevprna.c
===================================================================
--- trunk/gs/src/gdevprna.c	2008-02-13 02:36:18 UTC (rev 8525)
+++ trunk/gs/src/gdevprna.c	2008-02-14 08:34:56 UTC (rev 8526)
@@ -28,7 +28,7 @@
 #include "gxcldev.h"
 #include "gxclpath.h"
 #include "gxpageq.h"
-#include "gzht.h"		/* for gx_ht_cache_default_bits */
+#include "gzht.h"		/* for gx_ht_cache_default_bits_size */
 
 /* ----------------- Constants ----------------------- */
 /*
@@ -99,7 +99,7 @@
 	    pwdev->memory->non_gc_memory, RendererAllocationOverheadBytes + max_raster
 				    /* the first * 2 is not a hack */
 		   + (max_raster + sizeof(void *) * 2) * min_band_height
-		   + max_src_image_row + gx_ht_cache_default_bits() * 2)) < 0)
+		   + max_src_image_row + gx_ht_cache_default_bits_size() * 2)) < 0)
 	     goto open_err;
 
     /* Alloc & init bandlist allocators */

Modified: trunk/gs/src/gsht.c
===================================================================
--- trunk/gs/src/gsht.c	2008-02-13 02:36:18 UTC (rev 8525)
+++ trunk/gs/src/gsht.c	2008-02-14 08:34:56 UTC (rev 8526)
@@ -1109,7 +1109,7 @@
 
                 tile_bytes = porder->raster
                               * (porder->num_bits / porder->width);
-                num_tiles = 1 + max_tile_cache_bytes / tile_bytes;
+                num_tiles = 1 + gx_ht_cache_default_bits_size() / tile_bytes;
                 pcache = gx_ht_alloc_cache( pis->memory,
                                             num_tiles,
                                             tile_bytes * num_tiles );

Modified: trunk/gs/src/gshtscr.c
===================================================================
--- trunk/gs/src/gshtscr.c	2008-02-13 02:36:18 UTC (rev 8525)
+++ trunk/gs/src/gshtscr.c	2008-02-14 08:34:56 UTC (rev 8526)
@@ -249,7 +249,7 @@
                             gs_memory_t * mem)
 {
     gs_matrix imat;
-    ulong max_size = max_tile_cache_bytes;
+    ulong max_size = gx_ht_cache_default_bits_size();
     int code;
 
     if (phsp->frequency < 0.1)

Modified: trunk/gs/src/gxht.c
===================================================================
--- trunk/gs/src/gxht.c	2008-02-13 02:36:18 UTC (rev 8525)
+++ trunk/gs/src/gxht.c	2008-02-14 08:34:56 UTC (rev 8526)
@@ -26,14 +26,6 @@
 #include "gzht.h"
 #include "gsserial.h"
 
-/* Define the sizes of the halftone cache. */
-#define max_cached_tiles_HUGE 5000	/* not used */
-#define max_ht_bits_HUGE 1000000	/* not used */
-#define max_cached_tiles_LARGE 577
-#define max_ht_bits_LARGE 100000
-#define max_cached_tiles_SMALL 25
-#define max_ht_bits_SMALL 1000
-
 /* Define the binary halftone device color type. */
 /* The type descriptor must be public for Pattern types. */
 gs_public_st_composite(st_dc_ht_binary, gx_device_color, "dc_ht_binary",
@@ -119,33 +111,25 @@
 uint
 gx_ht_cache_default_tiles(void)
 {
-#if arch_small_memory
-    return max_cached_tiles_SMALL;
-#else
-    return (gs_debug_c('.') ? max_cached_tiles_SMALL :
-	    max_cached_tiles_LARGE);
-#endif
+    return (gs_debug_c('.') ? max_ht_cached_tiles_SMALL :
+	    max_ht_cached_tiles);
 }
 uint
-gx_ht_cache_default_bits(void)
+gx_ht_cache_default_bits_size(void)
 {
-#if arch_small_memory
-    return max_ht_bits_SMALL;
-#else
-    return (gs_debug_c('.') ? max_ht_bits_SMALL :
-	    max_ht_bits_LARGE);
-#endif
+    return (gs_debug_c('.') ? max_ht_cache_bits_size_SMALL :
+	    max_ht_cache_bits_size);
 }
 
-/* Allocate a halftone cache. */
+/* Allocate a halftone cache. max_bits_size is number of bytes */
 gx_ht_cache *
-gx_ht_alloc_cache(gs_memory_t * mem, uint max_tiles, uint max_bits)
+gx_ht_alloc_cache(gs_memory_t * mem, uint max_tiles, uint max_bits_size)
 {
     gx_ht_cache *pcache =
     gs_alloc_struct(mem, gx_ht_cache, &st_ht_cache,
 		    "alloc_ht_cache(struct)");
     byte *tbits =
-	gs_alloc_bytes(mem, max_bits, "alloc_ht_cache(bits)");
+	gs_alloc_bytes(mem, max_bits_size, "alloc_ht_cache(bits)");
     gx_ht_tile *ht_tiles =
 	gs_alloc_struct_array(mem, max_tiles, gx_ht_tile, &st_ht_tiles,
 			      "alloc_ht_cache(ht_tiles)");
@@ -157,7 +141,7 @@
 	return 0;
     }
     pcache->bits = tbits;
-    pcache->bits_size = max_bits;
+    pcache->bits_size = max_bits_size;
     pcache->ht_tiles = ht_tiles;
     pcache->num_tiles = max_tiles;
     pcache->order.cache = pcache;
@@ -216,8 +200,13 @@
 {
     const gx_ht_order *porder = &pcache->order;
     int level = porder->levels[b_level];
-    gx_ht_tile *bt = &pcache->ht_tiles[level / pcache->levels_per_tile];
+    gx_ht_tile *bt;
 
+    if (pcache->num_cached < porder->num_levels )
+	bt = &pcache->ht_tiles[level / pcache->levels_per_tile];
+    else
+	bt =  &pcache->ht_tiles[b_level];	/* one tile per b_level */
+
     if (bt->level != level) {
 	int code = render_ht(bt, level, porder, pcache->base_id + b_level);
 
@@ -317,8 +306,13 @@
     gx_ht_cache *pcache = porder->cache;
     int b_level = pdevc->colors.binary.b_level;
     int level = porder->levels[b_level];
-    gx_ht_tile *bt = &pcache->ht_tiles[level / pcache->levels_per_tile];
+    gx_ht_tile *bt;
 
+    if (pcache->num_cached < porder->num_levels )
+	bt = &pcache->ht_tiles[level / pcache->levels_per_tile];
+    else
+	bt =  &pcache->ht_tiles[b_level];	/* one tile per b_level */
+
     if (bt->level != level) {
 	int code = render_ht(bt, level, porder, pcache->base_id + b_level);
 

Modified: trunk/gs/src/gzht.h
===================================================================
--- trunk/gs/src/gzht.h	2008-02-13 02:36:18 UTC (rev 8525)
+++ trunk/gs/src/gzht.h	2008-02-14 08:34:56 UTC (rev 8526)
@@ -125,21 +125,18 @@
 };
 
 /* Define the sizes of the halftone cache. */
-#define max_cached_tiles_HUGE 5000	/* not used */
-#define max_ht_bits_HUGE 1000000	/* not used */
-#define max_cached_tiles_LARGE 577
-#define max_ht_bits_LARGE 100000
-#define max_cached_tiles_SMALL 25
-#define max_ht_bits_SMALL 1000
+#define max_ht_cached_tiles_LARGE 8192
+#define max_ht_cache_bits_size_LARGE (1024*1024) /* enough for 256 levels 167x167 */
+					   /* see ht_stocht.ps */
+#define max_ht_cached_tiles_SMALL 256
+#define max_ht_cache_bits_size_SMALL 8192	/* enough for 256 levels 8x8 */
 
-/* Define the size of the halftone tile cache. */
-#define max_tile_bytes_LARGE 65536
-#define max_tile_bytes_SMALL 512
 #if arch_small_memory
-#  define max_tile_cache_bytes max_tile_bytes_SMALL
+#  define max_ht_cached_tiles max_ht_cached_tiles_SMALL
+#  define max_ht_cache_bits_size max_ht_cache_bits_size_SMALL
 #else
-#  define max_tile_cache_bytes\
-     (gs_debug_c('.') ? max_tile_bytes_SMALL : max_tile_bytes_LARGE)
+#  define max_ht_cached_tiles max_ht_cached_tiles_LARGE
+#  define max_ht_cache_bits_size max_ht_cache_bits_size_LARGE
 #endif
 
 /* We don't mark from the tiles pointer, and we relocate the tiles en masse. */
@@ -164,7 +161,7 @@
 
 /* Allocate/free a halftone cache. */
 uint gx_ht_cache_default_tiles(void);
-uint gx_ht_cache_default_bits(void);
+uint gx_ht_cache_default_bits_size(void); /* returns size in bytes of 'bits' area */
 gx_ht_cache *gx_ht_alloc_cache(gs_memory_t *, uint, uint);
 void gx_ht_free_cache(gs_memory_t *, gx_ht_cache *);
 



More information about the gs-cvs mailing list