Chameleon

Chameleon Svn Source Tree

Root/branches/Chimera/i386/modules/klibc/memmove.c

1/*
2 * memmove.c
3 */
4
5#include "libsaio.h"
6
7void *memmove(void *dst, const void *src, size_t n)
8{
9const char *p = src;
10char *q = dst;
11#if defined(__i386__) || defined(__x86_64__)
12if (q < p) {
13asm volatile("cld; rep; movsb"
14 : "+c" (n), "+S"(p), "+D"(q));
15} else {
16p += (n - 1);
17q += (n - 1);
18asm volatile("std; rep; movsb; cld"
19 : "+c" (n), "+S"(p), "+D"(q));
20}
21#else
22if (q < p) {
23while (n--) {
24*q++ = *p++;
25}
26} else {
27p += n;
28q += n;
29while (n--) {
30*--q = *--p;
31}
32}
33#endif
34
35return dst;
36}
37

Archive Download this file

Revision: 850