Thread (15 messages) flat view 15 messages, 4 authors, 2003-07-07

RE: memmove broken

From: Joakim Tjernlund <hidden>
Date: 2003-07-04 11:07:53

Joakim Tjernlund writes:
quoted
I just realized that there is something strange going on in zlib.
zlib_inflate_fast() does a standard byte copy:
do{
  *q++ = *r++;
while(--c); /* c >= 3 */

q is always greater than r and this works. This is something else than a
regular mem copy. I havn't figured out yet what is happening here but I don't
think there is a problem with backwards_memcpy()
Ah. Yes.  This is actually quite clever.  If you have for example 256
zero bytes to compress, zlib will output a single literal zero byte
and then a block reference of length 255 and offset -1, saying that
the block from 1..255 is the same as the block from 0..254.  So the
fact that it copies forwards byte by byte is essential.  So you
couldn't use memcpy() either since it copies in larger chunks than 1
byte.
I see, thanks.

Currenly this works, but it is PPC specific:
static inline void memcpy_update(Byte **dest, Byte **src, size_t *n)
{
  if(*dest - *src <= 8){ /* memcpy on PPC will do 8 bytes in a chunk */
    **dest = **src;
    --(*n);
    do {
      *++(*dest) = *++(*src);
    } while (--(*n));
    (*dest)++;  (*src)++;
  } else {
    memcpy(*dest, *src, *n);
    *dest += *n;
    *src += *n;
    *n = 0;
  }

Jocke


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help