^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2008-2009 PetaLogix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2007 John Williams
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Reasonably optimised generic C-code for memset on Microblaze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This is generic C code to do efficient, alignment-aware memcpy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * http://www.embedded.com/showArticle.jhtml?articleID=19205567
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Attempts were made, unsuccessfully, to contact the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * author of this code (Michael Morrow, Intel). Below is the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * copyright notice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * This software has been developed by Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Intel specifically disclaims all warranties, express or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * implied, and all liability, including consequential and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * other indirect damages, for the use of this program, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * liability for infringement of any proprietary rights,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * and including the warranties of merchantability and fitness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * for a particular purpose. Intel does not assume any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * responsibility for and errors which may appear in this program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * not any responsibility to update it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #ifdef __HAVE_ARCH_MEMSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #ifndef CONFIG_OPT_LIB_FUNCTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) void *memset(void *v_src, int c, __kernel_size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) char *src = v_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Truncate c to 8 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) c = (c & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Simple, byte oriented memset or the rest of count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) while (n--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *src++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return v_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #else /* CONFIG_OPT_LIB_FUNCTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void *memset(void *v_src, int c, __kernel_size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) char *src = v_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) uint32_t *i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) uint32_t w32 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Truncate c to 8 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) c = (c & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (unlikely(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* Make a repeating word out of it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) w32 = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) w32 |= w32 << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) w32 |= w32 << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (likely(n >= 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Align the destination to a word boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* This is done in an endian independent manner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) switch ((unsigned) src & 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *src++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) --n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *src++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) --n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *src++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) --n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) i_src = (void *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* Do as many full-word copies as we can */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) for (; n >= 4; n -= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *i_src++ = w32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) src = (void *)i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* Simple, byte oriented memset or the rest of count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) while (n--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *src++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return v_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #endif /* CONFIG_OPT_LIB_FUNCTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) EXPORT_SYMBOL(memset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #endif /* __HAVE_ARCH_MEMSET */