comparison druntime/src/compiler/dmd/memset.d @ 759:d3eb054172f9

Added copy of druntime from DMD 2.020 modified for LDC.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:52:37 +0100
parents
children
comparison
equal deleted inserted replaced
758:f04dde6e882c 759:d3eb054172f9
1 /*
2 * Copyright (C) 2004 by Digital Mars, www.digitalmars.com
3 * Written by Walter Bright
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, in both source and binary form, subject to the following
12 * restrictions:
13 *
14 * o The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software
16 * in a product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
18 * o Altered source versions must be plainly marked as such, and must not
19 * be misrepresented as being the original software.
20 * o This notice may not be removed or altered from any source
21 * distribution.
22 */
23 module rt.memset;
24
25
26 extern (C)
27 {
28 // Functions from the C library.
29 void *memcpy(void *, void *, size_t);
30 }
31
32 extern (C):
33
34 short *_memset16(short *p, short value, size_t count)
35 {
36 short *pstart = p;
37 short *ptop;
38
39 for (ptop = &p[count]; p < ptop; p++)
40 *p = value;
41 return pstart;
42 }
43
44 int *_memset32(int *p, int value, size_t count)
45 {
46 version (X86)
47 {
48 asm
49 {
50 mov EDI,p ;
51 mov EAX,value ;
52 mov ECX,count ;
53 mov EDX,EDI ;
54 rep ;
55 stosd ;
56 mov EAX,EDX ;
57 }
58 }
59 else
60 {
61 int *pstart = p;
62 int *ptop;
63
64 for (ptop = &p[count]; p < ptop; p++)
65 *p = value;
66 return pstart;
67 }
68 }
69
70 long *_memset64(long *p, long value, size_t count)
71 {
72 long *pstart = p;
73 long *ptop;
74
75 for (ptop = &p[count]; p < ptop; p++)
76 *p = value;
77 return pstart;
78 }
79
80 cdouble *_memset128(cdouble *p, cdouble value, size_t count)
81 {
82 cdouble *pstart = p;
83 cdouble *ptop;
84
85 for (ptop = &p[count]; p < ptop; p++)
86 *p = value;
87 return pstart;
88 }
89
90 real *_memset80(real *p, real value, size_t count)
91 {
92 real *pstart = p;
93 real *ptop;
94
95 for (ptop = &p[count]; p < ptop; p++)
96 *p = value;
97 return pstart;
98 }
99
100 creal *_memset160(creal *p, creal value, size_t count)
101 {
102 creal *pstart = p;
103 creal *ptop;
104
105 for (ptop = &p[count]; p < ptop; p++)
106 *p = value;
107 return pstart;
108 }
109
110 void *_memsetn(void *p, void *value, int count, size_t sizelem)
111 { void *pstart = p;
112 int i;
113
114 for (i = 0; i < count; i++)
115 {
116 memcpy(p, value, sizelem);
117 p = cast(void *)(cast(char *)p + sizelem);
118 }
119 return pstart;
120 }