summaryrefslogtreecommitdiffstats
path: root/arch/csky/abiv1/memset.c
blob: b4aa75b99c5d1008bacc5fa19cc299f7954b6cbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.

#include <linux/types.h>

void *memset(void *dest, int c, size_t l)
{
	char *d = dest;
	int ch = c & 0xff;
	int tmp = (ch | ch << 8 | ch << 16 | ch << 24);

	while (((uintptr_t)d & 0x3) && l--)
		*d++ = ch;

	while (l >= 16) {
		*(((u32 *)d))   = tmp;
		*(((u32 *)d)+1) = tmp;
		*(((u32 *)d)+2) = tmp;
		*(((u32 *)d)+3) = tmp;
		l -= 16;
		d += 16;
	}

	while (l > 3) {
		*(((u32 *)d)) = tmp;
		l -= 4;
		d += 4;
	}

	while (l) {
		*d = ch;
		l--;
		d++;
	}

	return dest;
}