1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
;
37 unsigned short *p
= (unsigned short *)dst
;
40 unsigned long *aligned_addr
;
42 if (!TOO_SMALL(len
) && !UNALIGNED(dst
))
44 aligned_addr
= (unsigned long *)dst
;
49 buffer
= (val
<< 16) | val
;
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
;
67 while (len
>= LBLOCKSIZE
)
69 *aligned_addr
++ = buffer
;
73 p
= (unsigned short *)aligned_addr
;
78 #endif /* not PREFER_SIZE_OVER_SPEED */