AMSv2 SD: use a sleep instead of a udelay for 100 ms delay
[maemo-rb.git] / firmware / common / memset16.c
blob7e31df0cddee8946915339380dd32642ac660263
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-extra.h" /* memset16() */
24 #define LBLOCKSIZE (sizeof(long)/2)
25 #define UNALIGNED(X) ((long)X & (sizeof(long) - 1))
26 #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
28 void memset16(void *dst, int val, size_t len)
30 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
31 unsigned short *p = (unsigned short *)dst;
33 while (len--)
34 *p++ = val;
35 #else
36 unsigned short *p = (unsigned short *)dst;
37 unsigned int i;
38 unsigned long buffer;
39 unsigned long *aligned_addr;
41 if (!TOO_SMALL(len) && !UNALIGNED(dst))
43 aligned_addr = (unsigned long *)dst;
45 val &= 0xffff;
46 if (LBLOCKSIZE == 2)
48 buffer = (val << 16) | val;
50 else
52 buffer = 0;
53 for (i = 0; i < LBLOCKSIZE; i++)
54 buffer = (buffer << 16) | val;
57 while (len >= LBLOCKSIZE*4)
59 *aligned_addr++ = buffer;
60 *aligned_addr++ = buffer;
61 *aligned_addr++ = buffer;
62 *aligned_addr++ = buffer;
63 len -= 4*LBLOCKSIZE;
66 while (len >= LBLOCKSIZE)
68 *aligned_addr++ = buffer;
69 len -= LBLOCKSIZE;
72 p = (unsigned short *)aligned_addr;
75 while (len--)
76 *p++ = val;
77 #endif /* not PREFER_SIZE_OVER_SPEED */