/*1* Copyright (C) 2008-2009 Michal Simek <[email protected]>2* Copyright (C) 2008-2009 PetaLogix3* Copyright (C) 2007 John Williams4*5* Reasonably optimised generic C-code for memset on Microblaze6* This is generic C code to do efficient, alignment-aware memcpy.7*8* It is based on demo code originally Copyright 2001 by Intel Corp, taken from9* http://www.embedded.com/showArticle.jhtml?articleID=1920556710*11* Attempts were made, unsuccessfully, to contact the original12* author of this code (Michael Morrow, Intel). Below is the original13* copyright notice.14*15* This software has been developed by Intel Corporation.16* Intel specifically disclaims all warranties, express or17* implied, and all liability, including consequential and18* other indirect damages, for the use of this program, including19* liability for infringement of any proprietary rights,20* and including the warranties of merchantability and fitness21* for a particular purpose. Intel does not assume any22* responsibility for and errors which may appear in this program23* not any responsibility to update it.24*/2526#include <linux/types.h>27#include <linux/stddef.h>28#include <linux/compiler.h>29#include <linux/module.h>30#include <linux/string.h>3132#ifdef __HAVE_ARCH_MEMSET33#ifndef CONFIG_OPT_LIB_FUNCTION34void *memset(void *v_src, int c, __kernel_size_t n)35{36char *src = v_src;3738/* Truncate c to 8 bits */39c = (c & 0xFF);4041/* Simple, byte oriented memset or the rest of count. */42while (n--)43*src++ = c;4445return v_src;46}47#else /* CONFIG_OPT_LIB_FUNCTION */48void *memset(void *v_src, int c, __kernel_size_t n)49{50char *src = v_src;51uint32_t *i_src;52uint32_t w32 = 0;5354/* Truncate c to 8 bits */55c = (c & 0xFF);5657if (unlikely(c)) {58/* Make a repeating word out of it */59w32 = c;60w32 |= w32 << 8;61w32 |= w32 << 16;62}6364if (likely(n >= 4)) {65/* Align the destination to a word boundary */66/* This is done in an endian independent manner */67switch ((unsigned) src & 3) {68case 1:69*src++ = c;70--n;71case 2:72*src++ = c;73--n;74case 3:75*src++ = c;76--n;77}7879i_src = (void *)src;8081/* Do as many full-word copies as we can */82for (; n >= 4; n -= 4)83*i_src++ = w32;8485src = (void *)i_src;86}8788/* Simple, byte oriented memset or the rest of count. */89while (n--)90*src++ = c;9192return v_src;93}94#endif /* CONFIG_OPT_LIB_FUNCTION */95EXPORT_SYMBOL(memset);96#endif /* __HAVE_ARCH_MEMSET */979899