Add Cserve_Get_VM_Time
[qemu-palcode.git] / memset.c
blobe8481dc9c652ec9d74200678137413698388f876
1 /* The standard memset function.
3 Copyright (C) 2011 Richard Henderson
5 This file is part of QEMU PALcode.
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.
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.
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/>. */
22 #include <string.h>
24 void *memset(void *optr, int ival, unsigned long size)
26 unsigned long val = ival;
27 void *ptr = optr;
29 if (__builtin_expect (size == 0, 0))
30 return optr;
32 if (__builtin_expect (val != 0, 0))
34 val = val & 0xff;
35 val |= val << 8;
36 val |= val << 16;
37 val |= val << 32;
40 if (__builtin_expect ((unsigned long)ptr & 1, 0))
42 *(char *)ptr = val;
43 ptr += 1;
44 size -= 1;
47 if (__builtin_expect ((unsigned long)ptr & 2, 0))
49 if (size < 2)
50 goto tail_1;
51 *(short *)ptr = val;
52 ptr += 2;
53 size -= 2;
56 if (__builtin_expect ((unsigned long)ptr & 4, 0))
58 if (size < 4)
59 goto tail_3;
60 *(int *)ptr = val;
61 ptr += 4;
62 size -= 4;
65 while (size >= 8)
67 *(long *)ptr = val;
68 ptr += 8;
69 size -= 8;
72 if (size >= 4)
74 *(int *)ptr = val;
75 ptr += 4;
76 size -= 4;
79 tail_3:
80 if (size >= 2)
82 *(short *)ptr = val;
83 ptr += 2;
84 size -= 2;
87 tail_1:
88 if (size > 0)
90 *(char *)ptr = val;
91 ptr += 1;
92 size -= 1;
95 return optr;