FS#10406 - split the statusbar setting into one for each display, and allow the bar...
[kugel-rb.git] / firmware / common / memset16.c
blobd73fdd97018f16a8a03e10aff54c45af2c45bb16
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Jens Arnold
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <string.h>
23 #include "memory.h"
25 #define LBLOCKSIZE (sizeof(long)/2)
26 #define UNALIGNED(X) ((long)X & (sizeof(long) - 1))
27 #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
29 void memset16(void *dst, int val, size_t len)
31 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
32 unsigned short *p = (unsigned short *)dst;
34 while (len--)
35 *p++ = val;
36 #else
37 unsigned short *p = (unsigned short *)dst;
38 unsigned int i;
39 unsigned long buffer;
40 unsigned long *aligned_addr;
42 if (!TOO_SMALL(len) && !UNALIGNED(dst))
44 aligned_addr = (unsigned long *)dst;
46 val &= 0xffff;
47 if (LBLOCKSIZE == 2)
49 buffer = (val << 16) | val;
51 else
53 buffer = 0;
54 for (i = 0; i < LBLOCKSIZE; i++)
55 buffer = (buffer << 16) | val;
58 while (len >= LBLOCKSIZE*4)
60 *aligned_addr++ = buffer;
61 *aligned_addr++ = buffer;
62 *aligned_addr++ = buffer;
63 *aligned_addr++ = buffer;
64 len -= 4*LBLOCKSIZE;
67 while (len >= LBLOCKSIZE)
69 *aligned_addr++ = buffer;
70 len -= LBLOCKSIZE;
73 p = (unsigned short *)aligned_addr;
76 while (len--)
77 *p++ = val;
78 #endif /* not PREFER_SIZE_OVER_SPEED */