ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / v850 / lib / memset.c
1 /*
2  * arch/v850/lib/memset.c -- Memory initialization
3  *
4  *  Copyright (C) 2001,02  NEC Corporation
5  *  Copyright (C) 2001,02  Miles Bader <miles@gnu.org>
6  *
7  * This file is subject to the terms and conditions of the GNU General
8  * Public License.  See the file COPYING in the main directory of this
9  * archive for more details.
10  *
11  * Written by Miles Bader <miles@gnu.org>
12  */
13
14 #include <linux/types.h>
15
16 void *memset (void *dst, int val, __kernel_size_t count)
17 {
18         if (count) {
19                 register unsigned loop;
20                 register void *ptr asm ("ep") = dst;
21
22                 /* replicate VAL into a long.  */
23                 val &= 0xff;
24                 val |= val << 8;
25                 val |= val << 16;
26
27                 /* copy initial unaligned bytes.  */
28                 if ((long)ptr & 1) {
29                         *((char *)ptr)++ = val;
30                         count--;
31                 }
32                 if (count > 2 && ((long)ptr & 2)) {
33                         *((short *)ptr)++ = val;
34                         count -= 2;
35                 }
36
37                 /* 32-byte copying loop.  */
38                 for (loop = count / 32; loop; loop--) {
39                         asm ("sst.w %0, 0[ep]; sst.w %0, 4[ep];"
40                              "sst.w %0, 8[ep]; sst.w %0, 12[ep];"
41                              "sst.w %0, 16[ep]; sst.w %0, 20[ep];"
42                              "sst.w %0, 24[ep]; sst.w %0, 28[ep]"
43                              :: "r" (val) : "memory");
44                         ptr += 32;
45                 }
46                 count %= 32;
47
48                 /* long copying loop.  */
49                 for (loop = count / 4; loop; loop--)
50                         *((long *)ptr)++ = val;
51                 count %= 4;
52
53                 /* finish up with any trailing bytes.  */
54                 if (count & 2)
55                         *((short *)ptr)++ = val;
56                 if (count & 1)
57                         *(char *)ptr = val;
58         }
59
60         return dst;
61 }