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 ****************************************************************************/
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
;
36 unsigned short *p
= (unsigned short *)dst
;
39 unsigned long *aligned_addr
;
41 if (!TOO_SMALL(len
) && !UNALIGNED(dst
))
43 aligned_addr
= (unsigned long *)dst
;
48 buffer
= (val
<< 16) | val
;
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
;
66 while (len
>= LBLOCKSIZE
)
68 *aligned_addr
++ = buffer
;
72 p
= (unsigned short *)aligned_addr
;
77 #endif /* not PREFER_SIZE_OVER_SPEED */