/*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/export.h>27#include <linux/types.h>28#include <linux/stddef.h>29#include <linux/compiler.h>30#include <linux/string.h>3132#ifdef CONFIG_OPT_LIB_FUNCTION33void *memset(void *v_src, int c, __kernel_size_t n)34{35char *src = v_src;36uint32_t *i_src;37uint32_t w32 = 0;3839/* Truncate c to 8 bits */40c = (c & 0xFF);4142if (unlikely(c)) {43/* Make a repeating word out of it */44w32 = c;45w32 |= w32 << 8;46w32 |= w32 << 16;47}4849if (likely(n >= 4)) {50/* Align the destination to a word boundary */51/* This is done in an endian independent manner */52switch ((unsigned) src & 3) {53case 1:54*src++ = c;55--n;56fallthrough;57case 2:58*src++ = c;59--n;60fallthrough;61case 3:62*src++ = c;63--n;64}6566i_src = (void *)src;6768/* Do as many full-word copies as we can */69for (; n >= 4; n -= 4)70*i_src++ = w32;7172src = (void *)i_src;73}7475/* Simple, byte oriented memset or the rest of count. */76switch (n) {77case 3:78*src++ = c;79fallthrough;80case 2:81*src++ = c;82fallthrough;83case 1:84*src++ = c;85break;86default:87break;88}8990return v_src;91}92EXPORT_SYMBOL(memset);93#endif /* CONFIG_OPT_LIB_FUNCTION */949596