Merge branch 'for-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
[linux-2.6-microblaze.git] / arch / csky / abiv1 / memset.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4 #include <linux/types.h>
5
6 void *memset(void *dest, int c, size_t l)
7 {
8         char *d = dest;
9         int ch = c & 0xff;
10         int tmp = (ch | ch << 8 | ch << 16 | ch << 24);
11
12         while (((uintptr_t)d & 0x3) && l--)
13                 *d++ = ch;
14
15         while (l >= 16) {
16                 *(((u32 *)d))   = tmp;
17                 *(((u32 *)d)+1) = tmp;
18                 *(((u32 *)d)+2) = tmp;
19                 *(((u32 *)d)+3) = tmp;
20                 l -= 16;
21                 d += 16;
22         }
23
24         while (l > 3) {
25                 *(((u32 *)d)) = tmp;
26                 l -= 4;
27                 d += 4;
28         }
29
30         while (l) {
31                 *d = ch;
32                 l--;
33                 d++;
34         }
35
36         return dest;
37 }