|
|
1.1 ! root 1: /* The standard memset function. ! 2: ! 3: Copyright (C) 2011 Richard Henderson ! 4: ! 5: This file is part of QEMU PALcode. ! 6: ! 7: This program is free software; you can redistribute it and/or modify ! 8: it under the terms of the GNU General Public License as published by ! 9: the Free Software Foundation; either version 2 of the License or ! 10: (at your option) any later version. ! 11: ! 12: This program is distributed in the hope that it will be useful, ! 13: but WITHOUT ANY WARRANTY; without even the implied warranty of ! 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the text ! 15: of the GNU General Public License for more details. ! 16: ! 17: You should have received a copy of the GNU General Public License ! 18: along with this program; see the file COPYING. If not see ! 19: <http://www.gnu.org/licenses/>. */ ! 20: ! 21: ! 22: #include <string.h> ! 23: ! 24: void *memset(void *optr, int ival, unsigned long size) ! 25: { ! 26: unsigned long val = ival; ! 27: void *ptr = optr; ! 28: ! 29: if (__builtin_expect (size == 0, 0)) ! 30: return optr; ! 31: ! 32: if (__builtin_expect (val != 0, 0)) ! 33: { ! 34: val = val & 0xff; ! 35: val |= val << 8; ! 36: val |= val << 16; ! 37: val |= val << 32; ! 38: } ! 39: ! 40: if (__builtin_expect ((unsigned long)ptr & 1, 0)) ! 41: { ! 42: *(char *)ptr = val; ! 43: ptr += 1; ! 44: size -= 1; ! 45: } ! 46: ! 47: if (__builtin_expect ((unsigned long)ptr & 2, 0)) ! 48: { ! 49: if (size < 2) ! 50: goto tail_1; ! 51: *(short *)ptr = val; ! 52: ptr += 2; ! 53: size -= 2; ! 54: } ! 55: ! 56: if (__builtin_expect ((unsigned long)ptr & 4, 0)) ! 57: { ! 58: if (size < 4) ! 59: goto tail_3; ! 60: *(int *)ptr = val; ! 61: ptr += 4; ! 62: size -= 4; ! 63: } ! 64: ! 65: while (size >= 8) ! 66: { ! 67: *(long *)ptr = val; ! 68: ptr += 8; ! 69: size -= 8; ! 70: } ! 71: ! 72: if (size >= 4) ! 73: { ! 74: *(int *)ptr = val; ! 75: ptr += 4; ! 76: size -= 4; ! 77: } ! 78: ! 79: tail_3: ! 80: if (size >= 2) ! 81: { ! 82: *(short *)ptr = val; ! 83: ptr += 2; ! 84: size -= 2; ! 85: } ! 86: ! 87: tail_1: ! 88: if (size > 0) ! 89: { ! 90: *(char *)ptr = val; ! 91: ptr += 1; ! 92: size -= 1; ! 93: } ! 94: ! 95: return optr; ! 96: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.