Get a good start on cleaning up powermgmt.c
[kugel-rb.git] / firmware / common / memset16.c
blob5f0fc3fe089ff70f16ac6833747959622632af54
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Jens Arnold
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <string.h>
21 #define LBLOCKSIZE (sizeof(long)/2)
22 #define UNALIGNED(X) ((long)X & (sizeof(long) - 1))
23 #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
25 void memset16(void *dst, int val, size_t len)
27 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
28 unsigned short *p = (unsigned short *)dst;
30 while (len--)
31 *p++ = val;
32 #else
33 unsigned short *p = (unsigned short *)dst;
34 unsigned int i;
35 unsigned long buffer;
36 unsigned long *aligned_addr;
38 if (!TOO_SMALL(len) && !UNALIGNED(dst))
40 aligned_addr = (unsigned long *)dst;
42 val &= 0xffff;
43 if (LBLOCKSIZE == 2)
45 buffer = (val << 16) | val;
47 else
49 buffer = 0;
50 for (i = 0; i < LBLOCKSIZE; i++)
51 buffer = (buffer << 16) | val;
54 while (len >= LBLOCKSIZE*4)
56 *aligned_addr++ = buffer;
57 *aligned_addr++ = buffer;
58 *aligned_addr++ = buffer;
59 *aligned_addr++ = buffer;
60 len -= 4*LBLOCKSIZE;
63 while (len >= LBLOCKSIZE)
65 *aligned_addr++ = buffer;
66 len -= LBLOCKSIZE;
69 p = (unsigned short *)aligned_addr;
72 while (len--)
73 *p++ = val;
74 #endif /* not PREFER_SIZE_OVER_SPEED */