mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: Joakim Tjernlund <Joakim.Tjernlund@lumentis.se>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH RFC] 2.5.73 zlib #1 memmove
Date: Tue, 1 Jul 2003 17:45:22 +0200	[thread overview]
Message-ID: <20030701154522.GB25363@wohnheim.fh-wedel.de> (raw)

[ I currently have some mail problems that might take a while to
  resolve.  wohnheim.fh-wedel.de has a new dns-entry and the old one
  has a max lifetime on one week. :(

  I'm trying to resolve that problem but please keep linux-kernel on
  CC:. That way I can at least read the archives until the problems
  are history. ]

Joakim found a performance issue in the zlib and after some back and
forth, it appears that memmove() should be the correct solution.

The code in question copies a string from the LZ77 sliding window into
the output buffer.  The string is 3-258 bytes long with a tendency
towards small strings.  The zlib uses this code to do the copy:

*q++ = *r++;  c--;
*q++ = *r++;  c--;
do {
	*q++ = *r++;
} while (--c);

The first two lines are loop unrolling.  Apart from being ugly, this
should also be slower than memmove(), so I propose this patch.

Jörn

-- 
Fantasy is more important than knowlegde. Knowlegde is limited,
while fantasy embraces the whole world.
-- Albert Einstein

--- linux-2.5.73/lib/zlib_inflate/inffast.c~zlib_memcpy	2003-06-30 03:51:54.000000000 +0200
+++ linux-2.5.73/lib/zlib_inflate/inffast.c	2003-06-30 04:22:32.000000000 +0200
@@ -20,6 +20,14 @@
 #define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
 #define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
 
+static inline void memmove_update(Byte **dest, Byte **src, size_t *n)
+{
+	memmove(*dest, *src, *n);
+	*dest += *n;
+	*src += *n;
+	*n = 0;
+}
+
 /* Called with number of bytes left to write in window at least 258
    (the maximum string length) and number of input bytes available
    at least ten.  The ten bytes are six bytes for the longest length/
@@ -100,30 +108,18 @@
               if (c > e)
               {
                 c -= e;                         /* wrapped copy */
-                do {
-                    *q++ = *r++;
-                } while (--e);
+		memmove_update(&q, &r, &e);
                 r = s->window;
-                do {
-                    *q++ = *r++;
-                } while (--c);
+		memmove_update(&q, &r, &c);
               }
               else                              /* normal copy */
               {
-                *q++ = *r++;  c--;
-                *q++ = *r++;  c--;
-                do {
-                    *q++ = *r++;
-                } while (--c);
+		memmove_update(&q, &r, &c);
               }
             }
             else                                /* normal copy */
             {
-              *q++ = *r++;  c--;
-              *q++ = *r++;  c--;
-              do {
-                *q++ = *r++;
-              } while (--c);
+              memmove_update(&q, &r, &c);
             }
             break;
           }

             reply	other threads:[~2003-07-01 15:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-01 15:45 Jörn Engel [this message]
2003-07-01 16:16 ` [PATCH RFC] 2.5.73 zlib #2 codefold Jörn Engel
2003-07-02  8:46   ` Joakim Tjernlund
2003-07-02 16:59     ` Jörn Engel
2003-07-02  9:27 [PATCH RFC] 2.5.73 zlib #1 memmove Etienne Lorrain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030701154522.GB25363@wohnheim.fh-wedel.de \
    --to=joern@wohnheim.fh-wedel.de \
    --cc=Joakim.Tjernlund@lumentis.se \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®