comparison druntime/src/compiler/ldc/memset.d @ 1458:e0b2d67cfe7c

Added druntime (this should be removed once it works).
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 02 Jun 2009 17:43:06 +0100
parents
children
comparison
equal deleted inserted replaced
1456:7b218ec1044f 1458:e0b2d67cfe7c
1 /**
2 * Contains a memset implementation used by compiler-generated code.
3 *
4 * Copyright: Copyright Digital Mars 2004 - 2009.
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>.
6 * Authors: Walter Bright
7 *
8 * Copyright Digital Mars 2004 - 2009.
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or copy at
11 * http://www.boost.org/LICENSE_1_0.txt)
12 */
13 module rt.memset;
14
15 extern (C)
16 {
17 // Functions from the C library.
18 void *memcpy(void *, void *, size_t);
19 }
20
21 extern (C):
22
23 short *_memset16(short *p, short value, size_t count)
24 {
25 short *pstart = p;
26 short *ptop;
27
28 for (ptop = &p[count]; p < ptop; p++)
29 *p = value;
30 return pstart;
31 }
32
33 int *_memset32(int *p, int value, size_t count)
34 {
35 version (X86)
36 {
37 asm
38 {
39 mov EDI,p ;
40 mov EAX,value ;
41 mov ECX,count ;
42 mov EDX,EDI ;
43 rep ;
44 stosd ;
45 mov EAX,EDX ;
46 }
47 }
48 else
49 {
50 int *pstart = p;
51 int *ptop;
52
53 for (ptop = &p[count]; p < ptop; p++)
54 *p = value;
55 return pstart;
56 }
57 }
58
59 long *_memset64(long *p, long value, size_t count)
60 {
61 long *pstart = p;
62 long *ptop;
63
64 for (ptop = &p[count]; p < ptop; p++)
65 *p = value;
66 return pstart;
67 }
68
69 cdouble *_memset128(cdouble *p, cdouble value, size_t count)
70 {
71 cdouble *pstart = p;
72 cdouble *ptop;
73
74 for (ptop = &p[count]; p < ptop; p++)
75 *p = value;
76 return pstart;
77 }
78
79 real *_memset80(real *p, real value, size_t count)
80 {
81 real *pstart = p;
82 real *ptop;
83
84 for (ptop = &p[count]; p < ptop; p++)
85 *p = value;
86 return pstart;
87 }
88
89 creal *_memset160(creal *p, creal value, size_t count)
90 {
91 creal *pstart = p;
92 creal *ptop;
93
94 for (ptop = &p[count]; p < ptop; p++)
95 *p = value;
96 return pstart;
97 }
98
99 void *_memsetn(void *p, void *value, int count, size_t sizelem)
100 { void *pstart = p;
101 int i;
102
103 for (i = 0; i < count; i++)
104 {
105 memcpy(p, value, sizelem);
106 p = cast(void *)(cast(char *)p + sizelem);
107 }
108 return pstart;
109 }