diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-04-28 20:23:29 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2011-04-28 20:39:57 +0100 |
commit | 1553ea878b414b4ac389f7cec4c2076bc52be966 (patch) | |
tree | 1b2235a5a5158d4d73b474bf563f1e85dee0ef60 | |
parent | dd0ead1acfd2cf2fea4e417afdd4b52b06d8c3ad (diff) | |
download | ghostpdl-1553ea878b414b4ac389f7cec4c2076bc52be966.tar.gz |
Stop compiler turning for loop into memset in halftoning code.
The msvc compiler cleverly spots that a for loop can be turned
into a memset. Unfortunately it can't know that the values for
which the loop is called are normally so small that the calling
of the function costs more than simply doing the stores.
The fix is to cast the pointer to which we are storing to be
volatile. This saves a significant chunk of runtime for:
pcl6.exe -sDEVICE=bit -r600 -o null: -dLeadingEdge=3
cicero_call_CRF03-all-in_adobe-8_358p_xNuv288.xl
No cluster differences expected.
-rw-r--r-- | gs/base/gxht_thresh.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/gs/base/gxht_thresh.c b/gs/base/gxht_thresh.c index 3e9c8907b..ac332e507 100644 --- a/gs/base/gxht_thresh.c +++ b/gs/base/gxht_thresh.c @@ -327,10 +327,16 @@ gx_ht_threshold_landscape(byte *contone_align, byte *thresh_align, contone_out_posit = 0; /* Our index out */ for (j = num_contone; j > 0; j--) { byte c = *contone_ptr; - for (w = local_widths[curr_position]; w > 0; w--) { - contone[contone_out_posit] = c; + /* The microsoft compiler, cleverly spots that the following loop + * can be replaced by a memset. Unfortunately, it can't spot that + * the typical length values of the memset are so small that we'd + * be better off doing it the slow way. We therefore introduce a + * sneaky 'volatile' cast below that stops this optimisation. */ + w = local_widths[curr_position]; + do { + ((volatile byte *)contone)[contone_out_posit] = c; contone_out_posit++; - } + } while (--w); #ifdef PACIFY_VALGRIND if (extra) memset(contone+contone_out_posit, 0, extra); |