Jens Arnold | eb65f89 | 2006-02-22 01:20:45 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Jens Arnold |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Jens Arnold | eb65f89 | 2006-02-22 01:20:45 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include <string.h> |
| 23 | #define LBLOCKSIZE (sizeof(long)/2) |
Jens Arnold | c7ba2b5 | 2006-02-22 22:33:25 +0000 | [diff] [blame] | 24 | #define UNALIGNED(X) ((long)X & (sizeof(long) - 1)) |
Jens Arnold | eb65f89 | 2006-02-22 01:20:45 +0000 | [diff] [blame] | 25 | #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) |
| 26 | |
Jens Arnold | 9d2f7b5 | 2006-09-07 00:16:04 +0000 | [diff] [blame] | 27 | void memset16(void *dst, int val, size_t len) |
Jens Arnold | eb65f89 | 2006-02-22 01:20:45 +0000 | [diff] [blame] | 28 | { |
| 29 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) |
| 30 | unsigned short *p = (unsigned short *)dst; |
| 31 | |
| 32 | while (len--) |
| 33 | *p++ = val; |
Jens Arnold | eb65f89 | 2006-02-22 01:20:45 +0000 | [diff] [blame] | 34 | #else |
| 35 | unsigned short *p = (unsigned short *)dst; |
| 36 | unsigned int i; |
| 37 | unsigned long buffer; |
| 38 | unsigned long *aligned_addr; |
| 39 | |
| 40 | if (!TOO_SMALL(len) && !UNALIGNED(dst)) |
| 41 | { |
| 42 | aligned_addr = (unsigned long *)dst; |
| 43 | |
| 44 | val &= 0xffff; |
| 45 | if (LBLOCKSIZE == 2) |
| 46 | { |
| 47 | buffer = (val << 16) | val; |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | buffer = 0; |
| 52 | for (i = 0; i < LBLOCKSIZE; i++) |
| 53 | buffer = (buffer << 16) | val; |
| 54 | } |
| 55 | |
| 56 | while (len >= LBLOCKSIZE*4) |
| 57 | { |
| 58 | *aligned_addr++ = buffer; |
| 59 | *aligned_addr++ = buffer; |
| 60 | *aligned_addr++ = buffer; |
| 61 | *aligned_addr++ = buffer; |
| 62 | len -= 4*LBLOCKSIZE; |
| 63 | } |
| 64 | |
| 65 | while (len >= LBLOCKSIZE) |
| 66 | { |
| 67 | *aligned_addr++ = buffer; |
| 68 | len -= LBLOCKSIZE; |
| 69 | } |
| 70 | |
| 71 | p = (unsigned short *)aligned_addr; |
| 72 | } |
| 73 | |
| 74 | while (len--) |
| 75 | *p++ = val; |
Jens Arnold | eb65f89 | 2006-02-22 01:20:45 +0000 | [diff] [blame] | 76 | #endif /* not PREFER_SIZE_OVER_SPEED */ |
| 77 | } |