LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Joakim Tjernlund" <Joakim.Tjernlund@lumentis.se>
To: "Paul Mackerras" <paulus@samba.org>,
	"J?rn Engel" <joern@wohnheim.fh-wedel.de>
Cc: "Linuxppc-Dev@Lists. Linuxppc. Org" <linuxppc-dev@lists.linuxppc.org>
Subject: Re: memmove broken
Date: Sat, 5 Jul 2003 16:57:26 +0200	[thread overview]
Message-ID: <005501c34305$f8c4f260$020120b0@jockeXP> (raw)
In-Reply-To: 16134.52251.943207.814024@cargo.ozlabs.ibm.com


> > We should be able to do something like this in the zlib:
> > if (repeat one byte over and over) /* undefined behaviour for memcpy */
> > memset();
> > else {
> > if (copy is wrapped) {
> > memcpy(wrapped part);
> > tweak pointers;
> > }
> > memcpy();
> >
> > With that, source should always be smaller than destination for
> > memcpy, so the implementation details don't matter, as long as memcpy
> > doesn't do a reverse memcpy.
> >
> > Plus, the zlib code is shorter and tells the reader exactly what it
> > does, without the need for extra comments.
>
> Well no, I think it still isn't right.  What if the length is large
> but dst - src == 2 (e.g. if you compress "abababababab") or 3 (e.g. if
> you compress "abcabcabcabcabc")?  Or 4 or 5 or ...?  You will end up
> with an awfully large number of special cases.

Hi,
sorry for being a bit late to reply, but as of now I am on vacation.

This works and does not depend on any arch or memcpy/memmove impl. details:

static inline Byte * memmove_update(Byte *dest, Byte *src, size_t n)
{
/* n is always >= 3 and dest > src */
  Byte *ret = dest + n;

  if (dest - src >= n)
      memmove(dest, src, n); /* no overlapping here */
  else if(dest - src == 1)
      memset(dest, *src, n); /* special case of the pattern copy loop below, can be removed  */
  else {
     /* 1 > dest - src < n */
     /* copy patten at *src to *dest, pattern len is dest - src */
     /* one could use 2 byte chunks here, since dest - src is >= 2 */
    *dest = *src;
    --n;
    do {
      *++dest = *++src;
    } while (--n);
  }
  return ret;
}

simple enough?

 Jocke

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

  reply	other threads:[~2003-07-05 14:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-03 17:20 memmove broken Joakim Tjernlund
2003-07-04  6:17 ` Paul Mackerras
2003-07-04  8:32   ` Joakim Tjernlund
2003-07-04  9:37     ` Paul Mackerras
2003-07-04 11:07       ` Joakim Tjernlund
2003-07-04 23:38         ` Paul Mackerras
2003-07-05  7:21           ` Jörn Engel
2003-07-05  9:55             ` Holger Bettag
2003-07-05 13:01             ` Paul Mackerras
2003-07-05 14:57               ` Joakim Tjernlund [this message]
2003-07-05 17:01               ` Jörn Engel
2003-07-07 10:32                 ` Joakim Tjernlund
2003-07-07 12:06                   ` Jörn Engel
2003-07-07 12:58                     ` Joakim Tjernlund
2003-07-07 13:16                       ` Jörn Engel

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='005501c34305$f8c4f260$020120b0@jockeXP' \
    --to=joakim.tjernlund@lumentis.se \
    --cc=joern@wohnheim.fh-wedel.de \
    --cc=linuxppc-dev@lists.linuxppc.org \
    --cc=paulus@samba.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