| // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| /* |
| * Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| */ |
| |
| #include <config.h> |
| #include <linux/types.h> |
| #include <linux/string.h> |
| #include <linux/ctype.h> |
| #include <malloc.h> |
| |
| /* version for uasan without check */ |
| |
| void *__memset(void *s, int c, size_t count) |
| { |
| unsigned long *sl = (unsigned long *)s; |
| char *s8; |
| |
| #if 1 |
| unsigned long cl = 0; |
| int i; |
| |
| /* do it one word at a time (32 bits or 64 bits) while possible */ |
| if (((ulong)s & (sizeof(*sl) - 1)) == 0) { |
| for (i = 0; i < sizeof(*sl); i++) { |
| cl <<= 8; |
| cl |= c & 0xff; |
| } |
| while (count >= sizeof(*sl)) { |
| *sl++ = cl; |
| count -= sizeof(*sl); |
| } |
| } |
| #endif /* fill 8 bits at a time */ |
| s8 = (char *)sl; |
| while (count--) |
| *s8++ = c; |
| |
| return s; |
| } |
| |
| void *__memcpy(void *dest, const void *src, size_t count) |
| { |
| unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; |
| char *d8, *s8; |
| |
| if (src == dest) |
| return dest; |
| |
| /* while all data is aligned (common case), copy a word at a time */ |
| if ((((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { |
| while (count >= sizeof(*dl)) { |
| *dl++ = *sl++; |
| count -= sizeof(*dl); |
| } |
| } |
| /* copy the reset one byte at a time */ |
| d8 = (char *)dl; |
| s8 = (char *)sl; |
| while (count--) |
| *d8++ = *s8++; |
| |
| return dest; |
| } |
| |
| void *__memmove(void *dest, const void *src, size_t count) |
| { |
| char *tmp, *s; |
| |
| if (dest <= src) { |
| memcpy(dest, src, count); |
| } else { |
| tmp = (char *)dest + count; |
| s = (char *)src + count; |
| while (count--) |
| *--tmp = *--s; |
| } |
| |
| return dest; |
| } |