Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/modules/klibc/memset.c

Source at commit 1406 created 12 years 10 months ago.
By meklort, Revert drivers.c so that kexts are only loaded when OSBundleRequired is set and that value is not safe mode. Added some comments about it too.
1/*
2 * memset.c
3 */
4
5#include <string.h>
6#include <stdint.h>
7
8void *memset(void *dst, int c, size_t n)
9{
10char *q = dst;
11
12#if defined(__i386__)
13size_t nl = n >> 2;
14asm volatile ("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb"
15 : "+c" (nl), "+D" (q)
16 : "a" ((unsigned char)c * 0x01010101U), "r" (n & 3));
17#elif defined(__x86_64__)
18size_t nq = n >> 3;
19asm volatile ("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb"
20 :"+c" (nq), "+D" (q)
21 : "a" ((unsigned char)c * 0x0101010101010101U),
22"r" ((uint32_t) n & 7));
23#else
24while (n--) {
25*q++ = c;
26}
27#endif
28
29return dst;
30}
31

Archive Download this file

Revision: 1406