/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314#include <linux/types.h>15#include <linux/string.h>16#include <linux/module.h>1718void *memmove(void *dest, const void *src, size_t n)19{20if ((const char *)src >= (char *)dest + n21|| (char *)dest >= (const char *)src + n) {22/* We found no overlap, so let memcpy do all the heavy23* lifting (prefetching, etc.)24*/25return memcpy(dest, src, n);26}2728if (n != 0) {29const uint8_t *in;30uint8_t x;31uint8_t *out;32int stride;3334if (src < dest) {35/* copy backwards */36in = (const uint8_t *)src + n - 1;37out = (uint8_t *)dest + n - 1;38stride = -1;39} else {40/* copy forwards */41in = (const uint8_t *)src;42out = (uint8_t *)dest;43stride = 1;44}4546/* Manually software-pipeline this loop. */47x = *in;48in += stride;4950while (--n != 0) {51*out = x;52out += stride;53x = *in;54in += stride;55}5657*out = x;58}5960return dest;61}62EXPORT_SYMBOL(memmove);636465